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

Side by Side Diff: tools/android/loading/device_setup.py

Issue 2733233002: [tools/android] Replace FlagReplacer with flag_changer equivalent (Closed)
Patch Set: Created 3 years, 9 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 | « tools/android/loading/controller.py ('k') | tools/android/loading/wpr_helper.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 collections 5 import collections
6 import contextlib 6 import contextlib
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import tempfile 12 import tempfile
13 import time 13 import time
14 14
15 _SRC_DIR = os.path.abspath(os.path.join( 15 _SRC_DIR = os.path.abspath(os.path.join(
16 os.path.dirname(__file__), '..', '..', '..')) 16 os.path.dirname(__file__), '..', '..', '..'))
17 17
18 _CATAPULT_DIR = os.path.join(_SRC_DIR, 'third_party', 'catapult') 18 _CATAPULT_DIR = os.path.join(_SRC_DIR, 'third_party', 'catapult')
19 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil')) 19 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil'))
20 from devil.android import device_utils 20 from devil.android import device_utils
21 from devil.android import flag_changer
22 from devil.android import forwarder 21 from devil.android import forwarder
23 from devil.android.sdk import adb_wrapper 22 from devil.android.sdk import adb_wrapper
24 from devil.android.sdk import intent 23 from devil.android.sdk import intent
25 24
26 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) 25 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android'))
27 from pylib import constants 26 from pylib import constants
28 from video_recorder import video_recorder 27 from video_recorder import video_recorder
29 28
30 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf')) 29 sys.path.append(os.path.join(_SRC_DIR, 'tools', 'perf'))
31 from chrome_telemetry_build import chromium_config 30 from chrome_telemetry_build import chromium_config
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 for command in command_queue: 113 for command in command_queue:
115 command_file.write(subprocess.list2cmdline(command) + ' ;\n') 114 command_file.write(subprocess.list2cmdline(command) + ' ;\n')
116 command_file.write('exit 0;\n'.format( 115 command_file.write('exit 0;\n'.format(
117 REMOTE_COMMAND_FILE_PATH)) 116 REMOTE_COMMAND_FILE_PATH))
118 command_file.flush() 117 command_file.flush()
119 device.adb.Push(command_file.name, REMOTE_COMMAND_FILE_PATH) 118 device.adb.Push(command_file.name, REMOTE_COMMAND_FILE_PATH)
120 device.adb.Shell('sh {p} && rm {p}'.format(p=REMOTE_COMMAND_FILE_PATH)) 119 device.adb.Shell('sh {p} && rm {p}'.format(p=REMOTE_COMMAND_FILE_PATH))
121 120
122 121
123 @contextlib.contextmanager 122 @contextlib.contextmanager
124 def FlagReplacer(device, command_line_path, new_flags):
125 """Replaces chrome flags in a context, restores them afterwards.
126
127 Args:
128 device: Device to target, from DeviceUtils. Can be None, in which case this
129 context manager is a no-op.
130 command_line_path: Full path to the command-line file.
131 new_flags: Flags to replace.
132 """
133 # If we're logging requests from a local desktop chrome instance there is no
134 # device.
135 if not device:
136 yield
137 return
138 changer = flag_changer.FlagChanger(device, command_line_path)
139 changer.ReplaceFlags(new_flags)
140 try:
141 yield
142 finally:
143 changer.Restore()
144
145
146 @contextlib.contextmanager
147 def ForwardPort(device, local, remote): 123 def ForwardPort(device, local, remote):
148 """Forwards a local port to a remote one on a device in a context.""" 124 """Forwards a local port to a remote one on a device in a context."""
149 # If we're logging requests from a local desktop chrome instance there is no 125 # If we're logging requests from a local desktop chrome instance there is no
150 # device. 126 # device.
151 if not device: 127 if not device:
152 yield 128 yield
153 return 129 return
154 device.adb.Forward(local, remote) 130 device.adb.Forward(local, remote)
155 try: 131 try:
156 yield 132 yield
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 # speed index measurement. 401 # speed index measurement.
426 connection.ExecuteJavaScript(""" 402 connection.ExecuteJavaScript("""
427 (function() { 403 (function() {
428 requestAnimationFrame(function() { 404 requestAnimationFrame(function() {
429 var screen = window.__speedindex_screen; 405 var screen = window.__speedindex_screen;
430 screen.style.background = 'rgb(255, 255, 255)'; 406 screen.style.background = 'rgb(255, 255, 255)';
431 }); 407 });
432 })(); 408 })();
433 """) 409 """)
434 yield 410 yield
OLDNEW
« no previous file with comments | « tools/android/loading/controller.py ('k') | tools/android/loading/wpr_helper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698