| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ |
| 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/devtools/device/android_device_manager.h" | 8 #include "chrome/browser/devtools/device/android_device_manager.h" |
| 9 #include "chrome/browser/devtools/device/webrtc/devtools_bridge_instances_reques
t.h" | 9 #include "chrome/browser/devtools/device/webrtc/devtools_bridge_instances_reques
t.h" |
| 10 #include "chrome/browser/devtools/device/webrtc/send_command_request.h" | 10 #include "chrome/browser/devtools/device/webrtc/send_command_request.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class WebUI; | 23 class WebUI; |
| 24 } // namespace content | 24 } // namespace content |
| 25 | 25 |
| 26 namespace local_discovery { | 26 namespace local_discovery { |
| 27 class GCDApiFlow; | 27 class GCDApiFlow; |
| 28 } // local_discovery | 28 } // local_discovery |
| 29 | 29 |
| 30 // Lives on the UI thread. | 30 // Lives on the UI thread. |
| 31 class DevToolsBridgeClient final | 31 class DevToolsBridgeClient : protected content::WebContentsObserver, |
| 32 : private content::NotificationObserver, | 32 private content::NotificationObserver, |
| 33 private IdentityProvider::Observer, | 33 private IdentityProvider::Observer, |
| 34 private content::WebContentsObserver, | 34 private SendCommandRequest::Delegate, |
| 35 private SendCommandRequest::Delegate, | 35 private DevToolsBridgeInstancesRequest::Delegate { |
| 36 private DevToolsBridgeInstancesRequest::Delegate { | |
| 37 public: | 36 public: |
| 38 using BrowserInfo = AndroidDeviceManager::BrowserInfo; | 37 using BrowserInfo = AndroidDeviceManager::BrowserInfo; |
| 39 using DeviceInfo = AndroidDeviceManager::DeviceInfo; | 38 using DeviceInfo = AndroidDeviceManager::DeviceInfo; |
| 40 using SerialList = std::vector<std::string>; | 39 using SerialList = std::vector<std::string>; |
| 41 using BrowserInfoList = std::vector<BrowserInfo>; | 40 using BrowserInfoList = std::vector<BrowserInfo>; |
| 42 | 41 |
| 43 static base::WeakPtr<DevToolsBridgeClient> Create( | 42 static base::WeakPtr<DevToolsBridgeClient> Create( |
| 44 Profile* profile, | 43 Profile* profile, |
| 45 SigninManagerBase* signin_manager, | 44 SigninManagerBase* signin_manager, |
| 46 ProfileOAuth2TokenService* token_service); | 45 ProfileOAuth2TokenService* token_service); |
| 47 | 46 |
| 48 void DeleteSelf(); | 47 void DeleteSelf(); |
| 49 | 48 |
| 50 static SerialList GetDevices(base::WeakPtr<DevToolsBridgeClient> weak_ptr); | 49 static SerialList GetDevices(base::WeakPtr<DevToolsBridgeClient> weak_ptr); |
| 51 static DeviceInfo GetDeviceInfo(base::WeakPtr<DevToolsBridgeClient> weak_ptr, | 50 static DeviceInfo GetDeviceInfo(base::WeakPtr<DevToolsBridgeClient> weak_ptr, |
| 52 const std::string& serial); | 51 const std::string& serial); |
| 53 void StartSessionIfNeeded(const std::string& socket_name); | 52 void StartSessionIfNeeded(const std::string& socket_name); |
| 54 | 53 |
| 55 static DevToolsBridgeClient* FromWebContents( | 54 static DevToolsBridgeClient* FromWebContents( |
| 56 content::WebContents* web_contents); | 55 content::WebContents* web_contents); |
| 57 void RegisterMessageHandlers(content::WebUI* web_ui); | 56 void RegisterMessageHandlers(content::WebUI* web_ui); |
| 58 | 57 |
| 59 private: | 58 protected: |
| 60 DevToolsBridgeClient(Profile* profile, | 59 DevToolsBridgeClient(Profile* profile, |
| 61 SigninManagerBase* signin_manager, | 60 SigninManagerBase* signin_manager, |
| 62 ProfileOAuth2TokenService* token_service); | 61 ProfileOAuth2TokenService* token_service); |
| 63 | 62 |
| 64 ~DevToolsBridgeClient(); | 63 // Implementation of content::WebContentsObserver. |
| 64 void DocumentOnLoadCompletedInMainFrame() override; |
| 65 |
| 66 ~DevToolsBridgeClient() override; |
| 65 | 67 |
| 66 bool IsAuthenticated(); | 68 bool IsAuthenticated(); |
| 67 | 69 |
| 70 // Overridden in tests. |
| 71 virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow(); |
| 72 virtual void OnBrowserListUpdatedForTests() {} |
| 73 |
| 74 const BrowserInfoList& browsers() const { return browsers_; } |
| 75 ProfileIdentityProvider& identity_provider() { return identity_provider_; } |
| 76 |
| 77 private: |
| 68 void CreateBackgroundWorker(); | 78 void CreateBackgroundWorker(); |
| 69 scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow(); | |
| 70 void UpdateBrowserList(); | 79 void UpdateBrowserList(); |
| 71 | 80 |
| 72 void HandleSendCommand(const base::ListValue* args); | 81 void HandleSendCommand(const base::ListValue* args); |
| 73 | 82 |
| 74 // Implementation of IdentityProvider::Observer. | 83 // Implementation of IdentityProvider::Observer. |
| 75 void OnActiveAccountLogin() override; | 84 void OnActiveAccountLogin() override; |
| 76 void OnActiveAccountLogout() override; | 85 void OnActiveAccountLogout() override; |
| 77 | 86 |
| 78 // Implementation of WebContentsObserver. | |
| 79 void DocumentOnLoadCompletedInMainFrame() override; | |
| 80 | |
| 81 // Implementation of NotificationObserver. | 87 // Implementation of NotificationObserver. |
| 82 void Observe(int type, | 88 void Observe(int type, |
| 83 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
| 84 const content::NotificationDetails& details) override; | 90 const content::NotificationDetails& details) override; |
| 85 | 91 |
| 86 // Implementation of SendCommandRequest::Delegate. | 92 // Implementation of SendCommandRequest::Delegate. |
| 87 void OnCommandSucceeded(const base::DictionaryValue& response) override; | 93 void OnCommandSucceeded(const base::DictionaryValue& response) override; |
| 88 void OnCommandFailed() override; | 94 void OnCommandFailed() override; |
| 89 | 95 |
| 90 // Implementation of DevToolsBridgeInstancesRequest::Delegate. | 96 // Implementation of DevToolsBridgeInstancesRequest::Delegate. |
| 91 void OnDevToolsBridgeInstancesRequestSucceeded( | 97 void OnDevToolsBridgeInstancesRequestSucceeded( |
| 92 const DevToolsBridgeInstancesRequest::InstanceList& instances) override; | 98 const DevToolsBridgeInstancesRequest::InstanceList& instances) override; |
| 93 void OnDevToolsBridgeInstancesRequestFailed() override; | 99 void OnDevToolsBridgeInstancesRequestFailed() override; |
| 94 | 100 |
| 95 Profile* const profile_; | 101 Profile* const profile_; |
| 96 ProfileIdentityProvider identity_provider_; | 102 ProfileIdentityProvider identity_provider_; |
| 97 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
| 98 scoped_ptr<content::WebContents> background_worker_; | 104 scoped_ptr<content::WebContents> background_worker_; |
| 99 scoped_ptr<local_discovery::GCDApiFlow> browser_list_request_; | 105 scoped_ptr<local_discovery::GCDApiFlow> browser_list_request_; |
| 100 scoped_ptr<local_discovery::GCDApiFlow> send_command_request_; | 106 scoped_ptr<local_discovery::GCDApiFlow> send_command_request_; |
| 101 BrowserInfoList browsers_; | 107 BrowserInfoList browsers_; |
| 102 bool worker_is_loaded_; | 108 bool worker_is_loaded_; |
| 103 base::WeakPtrFactory<DevToolsBridgeClient> weak_factory_; | 109 base::WeakPtrFactory<DevToolsBridgeClient> weak_factory_; |
| 104 | 110 |
| 105 DISALLOW_COPY_AND_ASSIGN(DevToolsBridgeClient); | 111 DISALLOW_COPY_AND_ASSIGN(DevToolsBridgeClient); |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ | 114 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_WEBRTC_DEVTOOLS_BRIDGE_CLIENT_H_ |
| OLD | NEW |