| 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 os |
| 8 import sys |
| 9 |
| 10 _SRC_PATH = os.path.abspath(os.path.join( |
| 11 os.path.dirname(__file__), os.pardir, os.pardir)) |
| 12 |
| 13 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil')) |
| 14 from devil.android import device_utils |
| 15 |
| 16 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading')) |
| 17 import controller |
| 18 import device_setup |
| 19 from options import OPTIONS |
| 20 |
| 21 |
| 22 def FindDevice(device_id): |
| 23 """Returns a device matching |device_id| or the first one if None, or None.""" |
| 24 devices = device_utils.DeviceUtils.HealthyDevices() |
| 25 if device_id is None: |
| 26 return devices[0] |
| 27 return device_setup.GetDeviceFromSerial(device_id) |
| 28 |
| 29 |
| 30 def Setup(device, additional_flags=None): |
| 31 """Sets up a |device| and returns an instance of RemoteChromeController. |
| 32 |
| 33 Args: |
| 34 device: (Device) As returned by FindDevice(). |
| 35 additional_flags: ([str] or None) Chrome flags to add. |
| 36 """ |
| 37 if not device.HasRoot(): |
| 38 device.EnableRoot() |
| 39 chrome_controller = controller.RemoteChromeController(device) |
| 40 device.ForceStop(OPTIONS.ChromePackage().package) |
| 41 if additional_flags is not None: |
| 42 chrome_controller.AddChromeArguments(additional_flags) |
| 43 chrome_controller.ResetBrowserState() |
| 44 return chrome_controller |
| 45 |
| 46 |
| 47 def DatabaseDevicePath(): |
| 48 return ('/data/user/0/%s/app_chrome/Default/Network Action Predictor' % |
| 49 OPTIONS.ChromePackage().package) |
| OLD | NEW |