Call platform.StopAllLocalServers() in close()

This is to make sure the telemetry local servers, e.g. the one started by
platform.SetHTTPServerDirectories(), are closed properly.

BUG=chromium:663387
TEST=Manually run several tests which use platform.SetHTTPServerDirectories()
     and make sure there's no process leak.

Change-Id: I63630b9df6898e34ee1114f66f22201d129498e5
Reviewed-on: https://chromium-review.googlesource.com/408835
Commit-Ready: Ilja H. Friedel <ihf@chromium.org>
Tested-by: Ricky Liang <jcliang@chromium.org>
Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
diff --git a/client/common_lib/cros/chrome.py b/client/common_lib/cros/chrome.py
index e74ced8..be190e2 100644
--- a/client/common_lib/cros/chrome.py
+++ b/client/common_lib/cros/chrome.py
@@ -54,7 +54,19 @@
 
 
 class Chrome(object):
-    """Wrapper for creating a telemetry browser instance with extensions."""
+    """Wrapper for creating a telemetry browser instance with extensions.
+
+    The recommended way to use this class is to create the instance using the
+    with statement:
+
+    >>> with chrome.Chrome(...) as cr:
+    >>>     # Do whatever you need with cr.
+    >>>     pass
+
+    This will make sure all the clean-up functions are called.  If you really
+    need to use this class without the with statement, make sure to call the
+    close() method once you're done with the Chrome instance.
+    """
 
 
     BROWSER_TYPE_LOGIN = 'system'
@@ -301,4 +313,10 @@
             if is_arc_available():
                 arc_util.pre_processing_before_close(self)
         finally:
+            # Calling platform.StopAllLocalServers() to tear down the telemetry
+            # server processes such as the one started by
+            # platform.SetHTTPServerDirectories().  Not calling this function
+            # will leak the process and may affect test results.
+            # (crbug.com/663387)
+            self._browser.platform.StopAllLocalServers()
             self._browser.Close()