1# Copyright 2013 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. 4import uuid 5import sys 6 7from catapult_base import cloud_storage # pylint: disable=import-error 8 9from telemetry import decorators 10from telemetry.internal.backends import app_backend 11from telemetry.internal.browser import web_contents 12from telemetry.internal.platform import profiling_controller_backend 13 14 15class ExtensionsNotSupportedException(Exception): 16 pass 17 18 19class BrowserBackend(app_backend.AppBackend): 20 """A base class for browser backends.""" 21 22 def __init__(self, platform_backend, supports_extensions, browser_options, 23 tab_list_backend): 24 assert browser_options.browser_type 25 super(BrowserBackend, self).__init__( 26 browser_options.browser_type, platform_backend) 27 self._supports_extensions = supports_extensions 28 self.browser_options = browser_options 29 self._tab_list_backend_class = tab_list_backend 30 self._profiling_controller_backend = ( 31 profiling_controller_backend.ProfilingControllerBackend( 32 platform_backend, self)) 33 34 def SetBrowser(self, browser): 35 super(BrowserBackend, self).SetApp(app=browser) 36 37 @property 38 def log_file_path(self): 39 # Specific browser backend is responsible for overriding this properly. 40 raise NotImplementedError 41 42 def UploadLogsToCloudStorage(self): 43 """ Uploading log files produce by this browser instance to cloud storage. 44 45 Check supports_uploading_logs before calling this method. 46 """ 47 assert self.supports_uploading_logs 48 remote_path = (self.browser_options.logs_cloud_remote_path or 49 'log_%s' % uuid.uuid4()) 50 cloud_url = cloud_storage.Insert( 51 bucket=self.browser_options.logs_cloud_bucket, 52 remote_path=remote_path, 53 local_path=self.log_file_path) 54 sys.stderr.write('Uploading browser log to %s\n' % cloud_url) 55 56 @property 57 def browser(self): 58 return self.app 59 60 @property 61 def profiling_controller_backend(self): 62 return self._profiling_controller_backend 63 64 @property 65 def browser_type(self): 66 return self.app_type 67 68 @property 69 def supports_uploading_logs(self): 70 # Specific browser backend is responsible for overriding this properly. 71 return False 72 73 @property 74 def supports_extensions(self): 75 """True if this browser backend supports extensions.""" 76 return self._supports_extensions 77 78 @property 79 def supports_tab_control(self): 80 raise NotImplementedError() 81 82 @property 83 @decorators.Cache 84 def tab_list_backend(self): 85 return self._tab_list_backend_class(self) 86 87 @property 88 def supports_tracing(self): 89 raise NotImplementedError() 90 91 @property 92 def supports_system_info(self): 93 return False 94 95 def StartTracing(self, trace_options, custom_categories=None, 96 timeout=web_contents.DEFAULT_WEB_CONTENTS_TIMEOUT): 97 raise NotImplementedError() 98 99 def StopTracing(self, trace_data_builder): 100 raise NotImplementedError() 101 102 def Start(self): 103 raise NotImplementedError() 104 105 def IsBrowserRunning(self): 106 raise NotImplementedError() 107 108 def IsAppRunning(self): 109 return self.IsBrowserRunning() 110 111 def GetStandardOutput(self): 112 raise NotImplementedError() 113 114 def GetStackTrace(self): 115 raise NotImplementedError() 116 117 def GetSystemInfo(self): 118 raise NotImplementedError() 119 120 @property 121 def supports_memory_dumping(self): 122 return False 123 124 def DumpMemory(self, timeout=web_contents.DEFAULT_WEB_CONTENTS_TIMEOUT): 125 raise NotImplementedError() 126 127 @property 128 def supports_overriding_memory_pressure_notifications(self): 129 return False 130 131 def SetMemoryPressureNotificationsSuppressed( 132 self, suppressed, timeout=web_contents.DEFAULT_WEB_CONTENTS_TIMEOUT): 133 raise NotImplementedError() 134 135 def SimulateMemoryPressureNotification( 136 self, pressure_level, timeout=web_contents.DEFAULT_WEB_CONTENTS_TIMEOUT): 137 raise NotImplementedError() 138 139 @property 140 def supports_cpu_metrics(self): 141 raise NotImplementedError() 142 143 @property 144 def supports_memory_metrics(self): 145 raise NotImplementedError() 146 147 @property 148 def supports_power_metrics(self): 149 raise NotImplementedError() 150