Add a retry for logging into chrome.

BUG=chromium:304442
TEST=trybot

Change-Id: Icd672a7afb82cab92ac651af3f1e7234556dd2d7
Reviewed-on: https://chromium-review.googlesource.com/177249
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Achuith Bhandarkar <achuith@chromium.org>
Tested-by: Achuith Bhandarkar <achuith@chromium.org>
diff --git a/client/common_lib/cros/chrome.py b/client/common_lib/cros/chrome.py
index 6280e2d..35c642f 100644
--- a/client/common_lib/cros/chrome.py
+++ b/client/common_lib/cros/chrome.py
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import os
+import logging, os
 
 from telemetry.core import browser_finder, browser_options, exceptions
 from telemetry.core import extension_to_load, util
@@ -20,7 +20,8 @@
     BROWSER_TYPE_GUEST = 'system-guest'
 
 
-    def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False):
+    def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False,
+                 num_tries=1):
         self._autotest_ext_path = None
         if autotest_ext:
             self._autotest_ext_path = os.path.join(os.path.dirname(__file__),
@@ -48,9 +49,16 @@
         b_options.disable_component_extensions_with_background_pages = False
         b_options.create_browser_with_oobe = True
 
-        browser_to_create = browser_finder.FindBrowser(finder_options)
-        self._browser = browser_to_create.Create()
-        self._browser.Start()
+        for i in range(num_tries):
+            try:
+                browser_to_create = browser_finder.FindBrowser(finder_options)
+                self._browser = browser_to_create.Create()
+                self._browser.Start()
+                break
+            except util.TimeoutException:
+                logging.error('Timed out logging in, tries=%d', i)
+                if i == num_tries-1:
+                    raise
 
 
     def __enter__(self):