OLD | NEW |
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 import logging as real_logging | 4 import logging as real_logging |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 from telemetry.core import local_server | 8 from telemetry.core import local_server |
9 from telemetry.core import memory_cache_http_server | 9 from telemetry.core import memory_cache_http_server |
10 from telemetry.core import network_controller | 10 from telemetry.core import network_controller |
11 from telemetry.core import tracing_controller | 11 from telemetry.core import tracing_controller |
12 from telemetry.core import util | 12 from telemetry.core import util |
| 13 from telemetry.internal import forwarders |
13 from telemetry.internal.platform import (platform_backend as | 14 from telemetry.internal.platform import (platform_backend as |
14 platform_backend_module) | 15 platform_backend_module) |
15 | 16 |
16 from py_utils import discover | 17 from py_utils import discover |
17 | 18 |
18 _host_platform = None | 19 _host_platform = None |
19 # Remote platform is a dictionary from device ids to remote platform instances. | 20 # Remote platform is a dictionary from device ids to remote platform instances. |
20 _remote_platforms = {} | 21 _remote_platforms = {} |
21 | 22 |
22 | 23 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 self._platform_backend = platform_backend | 82 self._platform_backend = platform_backend |
82 self._platform_backend.InitPlatformBackend() | 83 self._platform_backend.InitPlatformBackend() |
83 self._platform_backend.SetPlatform(self) | 84 self._platform_backend.SetPlatform(self) |
84 self._network_controller = network_controller.NetworkController( | 85 self._network_controller = network_controller.NetworkController( |
85 self._platform_backend.network_controller_backend) | 86 self._platform_backend.network_controller_backend) |
86 self._tracing_controller = tracing_controller.TracingController( | 87 self._tracing_controller = tracing_controller.TracingController( |
87 self._platform_backend.tracing_controller_backend) | 88 self._platform_backend.tracing_controller_backend) |
88 self._local_server_controller = local_server.LocalServerController( | 89 self._local_server_controller = local_server.LocalServerController( |
89 self._platform_backend) | 90 self._platform_backend) |
90 self._is_monitoring_power = False | 91 self._is_monitoring_power = False |
| 92 self._forwarder = None |
91 | 93 |
92 @property | 94 @property |
93 def is_host_platform(self): | 95 def is_host_platform(self): |
94 return self == GetHostPlatform() | 96 return self == GetHostPlatform() |
95 | 97 |
96 @property | 98 @property |
97 def network_controller(self): | 99 def network_controller(self): |
98 """Control network settings and servers to simulate the Web.""" | 100 """Control network settings and servers to simulate the Web.""" |
99 return self._network_controller | 101 return self._network_controller |
100 | 102 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if paths and self.http_server.paths == paths: | 405 if paths and self.http_server.paths == paths: |
404 return False | 406 return False |
405 | 407 |
406 self.http_server.Close() | 408 self.http_server.Close() |
407 | 409 |
408 if not paths: | 410 if not paths: |
409 return False | 411 return False |
410 | 412 |
411 server = memory_cache_http_server.MemoryCacheHTTPServer(paths) | 413 server = memory_cache_http_server.MemoryCacheHTTPServer(paths) |
412 self.StartLocalServer(server) | 414 self.StartLocalServer(server) |
| 415 |
| 416 # Requires port forwarding if browser is on remote device, and |
| 417 # replaces the http_server port number with the one resolved by |
| 418 # remote machine with ssh/adb remote port forwarding. |
| 419 if self._platform_backend.IsDeviceRemote(): |
| 420 # TODO(crbug.com/747293): |
| 421 # Originally the proxy_server is enabled for forwarding traffic |
| 422 # if the device is on remote. However, if the tracing is enabled, |
| 423 # the browser startup args will be reset which disables traffic |
| 424 # reroute through proxy_server. Here we have to create extra |
| 425 # port_forwarding. |
| 426 if self.tracing_controller.is_tracing_running: |
| 427 self._forwarder = self._platform_backend.CreatePortForwarder( |
| 428 forwarders.PortPair(self.http_server.port, 0), |
| 429 use_remote_port_forwarding=True) |
| 430 self.http_server.port = self._forwarder.host_port |
413 return True | 431 return True |
414 | 432 |
415 def StopAllLocalServers(self): | 433 def StopAllLocalServers(self): |
416 self._local_server_controller.Close() | 434 self._local_server_controller.Close() |
| 435 if self._forwarder: |
| 436 self._forwarder.Close() |
417 | 437 |
418 @property | 438 @property |
419 def local_servers(self): | 439 def local_servers(self): |
420 """Returns the currently running local servers.""" | 440 """Returns the currently running local servers.""" |
421 return self._local_server_controller.local_servers | 441 return self._local_server_controller.local_servers |
422 | 442 |
423 def HasBattOrConnected(self): | 443 def HasBattOrConnected(self): |
424 return self._platform_backend.HasBattOrConnected() | 444 return self._platform_backend.HasBattOrConnected() |
425 | 445 |
426 def WaitForBatteryTemperature(self, temp): | 446 def WaitForBatteryTemperature(self, temp): |
427 """Waits for the battery on the device under test to cool down to temp. | 447 """Waits for the battery on the device under test to cool down to temp. |
428 | 448 |
429 Args: | 449 Args: |
430 temp: temperature target in degrees C. | 450 temp: temperature target in degrees C. |
431 """ | 451 """ |
432 return self._platform_backend.WaitForBatteryTemperature(temp) | 452 return self._platform_backend.WaitForBatteryTemperature(temp) |
OLD | NEW |