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