Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/perf/profile_creators/profile_extender.py

Issue 1822043004: Do not close network controller in ProfileExtender if it was not opened there. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import copy 5 import copy
6 6
7 from telemetry.core import platform 7 from telemetry.core import platform
8 from telemetry.util import wpr_modes 8 from telemetry.util import wpr_modes
9 from telemetry.internal.browser import browser_finder 9 from telemetry.internal.browser import browser_finder
10 from telemetry.internal.browser import browser_finder_exceptions 10 from telemetry.internal.browser import browser_finder_exceptions
(...skipping 20 matching lines...) Expand all
31 self._finder_options = copy.deepcopy(finder_options) 31 self._finder_options = copy.deepcopy(finder_options)
32 # Since profile extenders are not supported on remote platforms, 32 # Since profile extenders are not supported on remote platforms,
33 # this should be the same as target platform. 33 # this should be the same as target platform.
34 self._os_name = platform.GetHostPlatform().GetOSName() 34 self._os_name = platform.GetHostPlatform().GetOSName()
35 35
36 # A reference to the browser that will be performing all of the tab 36 # A reference to the browser that will be performing all of the tab
37 # navigations. 37 # navigations.
38 # This member is initialized during SetUpBrowser(). 38 # This member is initialized during SetUpBrowser().
39 self._browser = None 39 self._browser = None
40 40
41 # We only need to close network controller if we opened it before.
42 # If it was already open, we should not close it.
43 self._should_close_network_controller = False
44
41 def Run(self): 45 def Run(self):
42 """Creates or extends the profile.""" 46 """Creates or extends the profile."""
43 raise NotImplementedError() 47 raise NotImplementedError()
44 48
45 def WebPageReplayArchivePath(self): 49 def WebPageReplayArchivePath(self):
46 """Returns the path to the WPR archive. 50 """Returns the path to the WPR archive.
47 51
48 Can be overridden by subclasses. 52 Can be overridden by subclasses.
49 """ 53 """
50 return None 54 return None
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 self._SetUpWebPageReplay(self.finder_options, possible_browser) 106 self._SetUpWebPageReplay(self.finder_options, possible_browser)
103 self._browser = possible_browser.Create(self.finder_options) 107 self._browser = possible_browser.Create(self.finder_options)
104 108
105 def TearDownBrowser(self): 109 def TearDownBrowser(self):
106 """Tears down the browser. 110 """Tears down the browser.
107 111
108 Can be overridden by subclasses. The subclass implementation must call the 112 Can be overridden by subclasses. The subclass implementation must call the
109 super class implementation. 113 super class implementation.
110 """ 114 """
111 if self._browser: 115 if self._browser:
112 self._browser.platform.network_controller.Close() 116 if self._should_close_network_controller:
117 self._browser.platform.network_controller.Close()
113 self._browser.Close() 118 self._browser.Close()
114 self._browser = None 119 self._browser = None
115 120
116 def FetchWebPageReplayArchives(self): 121 def FetchWebPageReplayArchives(self):
117 """Fetches the web page replay archives. 122 """Fetches the web page replay archives.
118 123
119 Can be overridden by subclasses. 124 Can be overridden by subclasses.
120 """ 125 """
121 pass 126 pass
122 127
123 def _SetUpWebPageReplay(self, finder_options, possible_browser): 128 def _SetUpWebPageReplay(self, finder_options, possible_browser):
124 """Sets up Web Page Replay, if necessary.""" 129 """Sets up Web Page Replay, if necessary."""
125 130
126 wpr_archive_path = self.WebPageReplayArchivePath() 131 wpr_archive_path = self.WebPageReplayArchivePath()
127 if not wpr_archive_path: 132 if not wpr_archive_path:
128 return 133 return
129 134
130 self.FetchWebPageReplayArchives() 135 self.FetchWebPageReplayArchives()
131 136
132 if finder_options.use_live_sites: 137 if finder_options.use_live_sites:
133 wpr_mode = wpr_modes.WPR_OFF 138 wpr_mode = wpr_modes.WPR_OFF
134 else: 139 else:
135 wpr_mode = wpr_modes.WPR_REPLAY 140 wpr_mode = wpr_modes.WPR_REPLAY
136 141
137 network_controller = possible_browser.platform.network_controller 142 network_controller = possible_browser.platform.network_controller
138 network_controller.Open(wpr_mode, finder_options.browser_options.netsim, 143 if not network_controller.is_open:
139 finder_options.browser_options.extra_wpr_args) 144 self._should_close_network_controller = True
145 network_controller.Open(wpr_mode, finder_options.browser_options.netsim,
146 finder_options.browser_options.extra_wpr_args)
140 network_controller.StartReplay( 147 network_controller.StartReplay(
141 wpr_archive_path, make_javascript_deterministic=True) 148 wpr_archive_path, make_javascript_deterministic=True)
142 149
143 def _GetPossibleBrowser(self, finder_options): 150 def _GetPossibleBrowser(self, finder_options):
144 """Return a possible_browser with the given options.""" 151 """Return a possible_browser with the given options."""
145 possible_browser = browser_finder.FindBrowser(finder_options) 152 possible_browser = browser_finder.FindBrowser(finder_options)
146 if not possible_browser: 153 if not possible_browser:
147 raise browser_finder_exceptions.BrowserFinderException( 154 raise browser_finder_exceptions.BrowserFinderException(
148 'No browser found.\n\nAvailable browsers:\n%s\n' % 155 'No browser found.\n\nAvailable browsers:\n%s\n' %
149 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) 156 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options)))
150 finder_options.browser_options.browser_type = ( 157 finder_options.browser_options.browser_type = (
151 possible_browser.browser_type) 158 possible_browser.browser_type)
152 159
153 return possible_browser 160 return possible_browser
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698