OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """Start and stop Web Page Replay.""" | 5 """Start and stop Web Page Replay.""" |
6 | 6 |
7 from py_utils import atexit_with_log | 7 from py_utils import atexit_with_log |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 self.replay_process = None | 92 self.replay_process = None |
93 | 93 |
94 | 94 |
95 @classmethod | 95 @classmethod |
96 def _GetGoBinaryPath(cls): | 96 def _GetGoBinaryPath(cls): |
97 if not cls._go_binary_path: | 97 if not cls._go_binary_path: |
98 cls._go_binary_path = binary_manager.FetchPath( | 98 cls._go_binary_path = binary_manager.FetchPath( |
99 'wpr_go', py_utils.GetHostArchName(), py_utils.GetHostOsName()) | 99 'wpr_go', py_utils.GetHostArchName(), py_utils.GetHostOsName()) |
100 return cls._go_binary_path | 100 return cls._go_binary_path |
101 | 101 |
102 @classmethod | |
103 def InstallRootCertificate(cls, android_device_id=None, adb_path=None): | |
104 """Install root certificate on the host machine or on remote Android device. | |
105 | |
106 Args: | |
107 android_device_id: a string id of the Android device. | |
108 adb_path: path to adb binary to use for issuing commands to the device. | |
109 This is specified iff android_device_id is specified. | |
110 """ | |
111 assert ((android_device_id is None and adb_path is None) or | |
112 (android_device_id is not None and adb_path is not None)), ( | |
113 'android_device_id and adb_path must be both specified or ' | |
114 'not specified') | |
115 go_binary_path = cls._GetGoBinaryPath() | |
116 if android_device_id is None: | |
117 subprocess.check_call([go_binary_path, 'installroot']) | |
118 else: | |
119 subprocess.check_call( | |
120 [go_binary_path, 'installroot', | |
121 '--android_device_id=%s' % android_device_id, | |
122 '--adb_binary_path=%s' % adb_path]) | |
123 | |
124 @classmethod | |
125 def RemoveRootCertificate(cls, android_device_id=None, adb_path=None): | |
126 """Remove installed root certificate on the host machine or on remote | |
127 Android device. | |
128 | |
129 Args: | |
130 android_device_id: a string id of the Android device. | |
131 adb_path: path to adb binary to use for issuing commands to the device. | |
132 This is specified iff android_device_id is specified. | |
133 """ | |
134 assert ((android_device_id is None and adb_path is None) or | |
135 (android_device_id is not None and adb_path is not None)), ( | |
136 'android_device_id and adb_path must be both specified or ' | |
137 'not specified') | |
138 go_binary_path = cls._GetGoBinaryPath() | |
139 if android_device_id is None: | |
140 subprocess.check_call([go_binary_path, 'removeroot']) | |
141 else: | |
142 subprocess.check_call( | |
143 [go_binary_path, 'removeroot', | |
144 '--android_device_id=%s' % android_device_id, | |
145 '--adb_binary_path=%s' % adb_path]) | |
146 | |
147 @property | 102 @property |
148 def http_port(self): | 103 def http_port(self): |
149 if not self._IsStarted(): | 104 if not self._IsStarted(): |
150 return None | 105 return None |
151 return self._started_ports['http'] | 106 return self._started_ports['http'] |
152 | 107 |
153 @property | 108 @property |
154 def https_port(self): | 109 def https_port(self): |
155 if not self._IsStarted(): | 110 if not self._IsStarted(): |
156 return None | 111 return None |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 On posix system, running this function before starting replay fixes a | 337 On posix system, running this function before starting replay fixes a |
383 bug that shows up when Telemetry is run as a background command from a | 338 bug that shows up when Telemetry is run as a background command from a |
384 script. https://crbug.com/254572. | 339 script. https://crbug.com/254572. |
385 | 340 |
386 Background: Signal masks on Linux are inherited from parent | 341 Background: Signal masks on Linux are inherited from parent |
387 processes. If anything invoking us accidentally masks SIGINT | 342 processes. If anything invoking us accidentally masks SIGINT |
388 (e.g. by putting a process in the background from a shell script), | 343 (e.g. by putting a process in the background from a shell script), |
389 sending a SIGINT to the child will fail to terminate it. | 344 sending a SIGINT to the child will fail to terminate it. |
390 """ | 345 """ |
391 signal.signal(signal.SIGINT, signal.SIG_DFL) | 346 signal.signal(signal.SIGINT, signal.SIG_DFL) |
OLD | NEW |