Don't add extra app list launcher page webviews.
[chromium-blink-merge.git] / tools / perf / profile_creators / profile_extender.py
blobf69957a4d279c3d2fde4cd6369066714a6a21232
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry.core import platform
6 from telemetry.core import wpr_modes
9 class ProfileExtender(object):
10 """Abstract base class for an object that constructs a Chrome profile."""
12 def __init__(self):
13 # The path of the profile that the browser will use while it's running.
14 # This member is initialized during SetUp().
15 self._profile_path = None
17 # A reference to the browser that will be performing all of the tab
18 # navigations.
19 # This member is initialized during SetUp().
20 self._browser = None
22 def Run(self, options):
23 """Creates or extends the profile.
25 |options| is an instance of BrowserFinderOptions. When subclass
26 implementations of this method inevitably attempt to find and launch a
27 browser, they should pass |options| to the relevant methods.
29 Several properties of |options| might require direct manipulation by
30 subclasses. These are:
31 |options.output_profile_path|: The path at which the profile should be
32 created.
33 |options.browser_options.profile_dir|: If this property is None, then a
34 new profile is created. Otherwise, the existing profile is appended on
35 to.
36 """
37 raise NotImplementedError()
39 def WebPageReplayArchivePath(self):
40 """Returns the path to the WPR archive.
42 Can be overridden by subclasses.
43 """
44 return None
46 @property
47 def profile_path(self):
48 return self._profile_path
50 @property
51 def browser(self):
52 return self._browser
54 def SetUp(self, finder_options):
55 """Finds and starts the browser.
57 Can be overridden by subclasses. Subclasses must call the super class
58 implementation.
59 """
60 self._profile_path = finder_options.output_profile_path
61 possible_browser = self._GetPossibleBrowser(finder_options)
63 assert possible_browser.supports_tab_control
64 assert (platform.GetHostPlatform().GetOSName() in
65 ["win", "mac", "linux"])
67 self._SetUpWebPageReplay(finder_options, possible_browser)
68 self._browser = possible_browser.Create(finder_options)
70 def TearDown(self):
71 """Teardown that is guaranteed to be executed before the instance is
72 destroyed.
74 Can be overridden by subclasses. Subclasses must call the super class
75 implementation.
76 """
77 if self._browser:
78 self._browser.Close()
79 self._browser = None
81 def FetchWebPageReplayArchives(self):
82 """Fetches the web page replay archives.
84 Can be overridden by subclasses.
85 """
86 pass
88 def _SetUpWebPageReplay(self, finder_options, possible_browser):
89 """Sets up Web Page Replay, if necessary."""
91 wpr_archive_path = self.WebPageReplayArchivePath()
92 if not wpr_archive_path:
93 return
95 self.FetchWebPageReplayArchives()
97 # The browser options needs to be passed to both the network controller
98 # as well as the browser backend.
99 browser_options = finder_options.browser_options
100 if finder_options.use_live_sites:
101 browser_options.wpr_mode = wpr_modes.WPR_OFF
102 else:
103 browser_options.wpr_mode = wpr_modes.WPR_REPLAY
105 network_controller = possible_browser.platform.network_controller
106 make_javascript_deterministic = True
108 network_controller.SetReplayArgs(
109 wpr_archive_path, browser_options.wpr_mode, browser_options.netsim,
110 browser_options.extra_wpr_args, make_javascript_deterministic)