| 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 platform is on ChromeOS, 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.GetOSName() == 'chromeos' and |
| 420 self._platform_backend.IsRemoteDevice()): |
| 421 self._forwarder = self._platform_backend.CreatePortForwarder( |
| 422 forwarders.PortPair(self.http_server.port, 0), |
| 423 use_remote_port_forwarding=True) |
| 424 self.http_server.port = self._forwarder.host_port |
| 413 return True | 425 return True |
| 414 | 426 |
| 415 def StopAllLocalServers(self): | 427 def StopAllLocalServers(self): |
| 416 self._local_server_controller.Close() | 428 self._local_server_controller.Close() |
| 429 if self._forwarder: |
| 430 self._forwarder.Close() |
| 417 | 431 |
| 418 @property | 432 @property |
| 419 def local_servers(self): | 433 def local_servers(self): |
| 420 """Returns the currently running local servers.""" | 434 """Returns the currently running local servers.""" |
| 421 return self._local_server_controller.local_servers | 435 return self._local_server_controller.local_servers |
| 422 | 436 |
| 423 def HasBattOrConnected(self): | 437 def HasBattOrConnected(self): |
| 424 return self._platform_backend.HasBattOrConnected() | 438 return self._platform_backend.HasBattOrConnected() |
| 425 | 439 |
| 426 def WaitForBatteryTemperature(self, temp): | 440 def WaitForBatteryTemperature(self, temp): |
| 427 """Waits for the battery on the device under test to cool down to temp. | 441 """Waits for the battery on the device under test to cool down to temp. |
| 428 | 442 |
| 429 Args: | 443 Args: |
| 430 temp: temperature target in degrees C. | 444 temp: temperature target in degrees C. |
| 431 """ | 445 """ |
| 432 return self._platform_backend.WaitForBatteryTemperature(temp) | 446 return self._platform_backend.WaitForBatteryTemperature(temp) |
| OLD | NEW |