Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Common utils for the speculative resource prefetch evaluation.""" | |
| 6 | |
| 7 import argparse | |
| 8 import logging | |
| 9 import os | |
| 10 import sys | |
| 11 | |
| 12 _SRC_PATH = os.path.abspath(os.path.join( | |
| 13 os.path.dirname(__file__), os.pardir, os.pardir)) | |
| 14 | |
| 15 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) | |
| 16 from devil.android import device_utils | |
| 17 | |
| 18 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) | |
| 19 import controller | |
| 20 from options import OPTIONS | |
| 21 | |
| 22 | |
| 23 def CreateBaseArgumentParser(description): | |
|
pasko
2016/11/17 15:59:04
inlining this function on every use will increase
Benoit L
2016/11/21 13:40:32
Done.
| |
| 24 """Returns a new ArgumentParser instance with a |description|.""" | |
| 25 return argparse.ArgumentParser(description=description, | |
| 26 parents=[OPTIONS.GetParentParser()]) | |
| 27 | |
| 28 | |
| 29 def ParseAndReturnArgs(parser): | |
|
pasko
2016/11/17 15:59:04
as the above, this utility is quite small and does
Benoit L
2016/11/21 13:40:32
Done.
| |
| 30 args = parser.parse_args() | |
| 31 OPTIONS.SetParsedArgs(args) | |
| 32 return args | |
| 33 | |
| 34 | |
| 35 def FindDevice(device_id): | |
| 36 """Returns a device matching |device_id| or the first one if None, or None.""" | |
| 37 devices = device_utils.DeviceUtils.HealthyDevices() | |
| 38 if device_id is None: | |
| 39 return devices[0] | |
| 40 matching_devices = [d for d in devices if str(d) == device_id] | |
| 41 if not matching_devices: | |
| 42 return None | |
| 43 return matching_devices[0] | |
| 44 | |
| 45 | |
| 46 def Setup(device, additional_flags=None): | |
| 47 """Sets up a device and returns an instance of RemoteChromeController.""" | |
| 48 if not device.HasRoot(): | |
| 49 device.EnableRoot() | |
| 50 chrome_controller = controller.RemoteChromeController(device) | |
| 51 device.ForceStop(OPTIONS.ChromePackage().package) | |
| 52 if additional_flags is not None: | |
| 53 chrome_controller.AddChromeArguments(additional_flags) | |
| 54 chrome_controller.ResetBrowserState() | |
| 55 return chrome_controller | |
| 56 | |
| 57 | |
| 58 def DatabaseDevicePath(): | |
| 59 return ('/data/user/0/%s/app_chrome/Default/Network Action Predictor' % | |
| 60 OPTIONS.ChromePackage().package) | |
| OLD | NEW |