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_PORT_FORWARDING_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
11 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 11 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
12 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 12 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
14 | 14 |
15 class PrefService; | 15 class PrefService; |
16 class Profile; | 16 class Profile; |
17 | 17 |
18 class PortForwardingController | 18 class PortForwardingController { |
19 : private KeyedService, | |
20 private DevToolsAndroidBridge::DeviceListListener { | |
21 public: | 19 public: |
| 20 typedef DevToolsAndroidBridge::PortStatus PortStatus; |
| 21 typedef DevToolsAndroidBridge::PortStatusMap PortStatusMap; |
| 22 typedef DevToolsAndroidBridge::DevicesStatus DevicesStatus; |
| 23 |
22 explicit PortForwardingController(Profile* profile); | 24 explicit PortForwardingController(Profile* profile); |
23 | 25 |
24 virtual ~PortForwardingController(); | 26 virtual ~PortForwardingController(); |
25 | 27 |
26 // KeyedService implementation. | 28 DevicesStatus DeviceListChanged( |
27 virtual void Shutdown() OVERRIDE; | 29 const DevToolsAndroidBridge::RemoteDevices& devices); |
28 | |
29 class Factory : public BrowserContextKeyedServiceFactory { | |
30 public: | |
31 // Returns singleton instance of Factory. | |
32 static Factory* GetInstance(); | |
33 | |
34 // Returns PortForwardingController associated with |profile|. | |
35 static PortForwardingController* GetForProfile(Profile* profile); | |
36 | |
37 private: | |
38 friend struct DefaultSingletonTraits<Factory>; | |
39 | |
40 Factory(); | |
41 virtual ~Factory(); | |
42 | |
43 // BrowserContextKeyedServiceFactory overrides: | |
44 virtual KeyedService* BuildServiceInstanceFor( | |
45 content::BrowserContext* context) const OVERRIDE; | |
46 DISALLOW_COPY_AND_ASSIGN(Factory); | |
47 }; | |
48 | |
49 typedef int PortStatus; | |
50 typedef std::map<int, PortStatus> PortStatusMap; | |
51 typedef std::map<std::string, PortStatusMap> DevicesStatus; | |
52 | |
53 class Listener { | |
54 public: | |
55 typedef PortForwardingController::PortStatusMap PortStatusMap; | |
56 typedef PortForwardingController::DevicesStatus DevicesStatus; | |
57 | |
58 virtual void PortStatusChanged(const DevicesStatus&) = 0; | |
59 protected: | |
60 virtual ~Listener() {} | |
61 }; | |
62 | |
63 void AddListener(Listener* listener); | |
64 void RemoveListener(Listener* listener); | |
65 | 30 |
66 private: | 31 private: |
67 class Connection; | 32 class Connection; |
68 typedef std::map<std::string, Connection*> Registry; | 33 typedef std::map<std::string, Connection*> Registry; |
69 | 34 |
70 // DevToolsAndroidBridge::Listener implementation. | |
71 virtual void DeviceListChanged( | |
72 const DevToolsAndroidBridge::RemoteDevices& devices) OVERRIDE; | |
73 | |
74 void OnPrefsChange(); | 35 void OnPrefsChange(); |
75 | 36 |
76 void StartListening(); | |
77 void StopListening(); | |
78 | |
79 void UpdateConnections(); | 37 void UpdateConnections(); |
80 void ShutdownConnections(); | 38 void ShutdownConnections(); |
81 | 39 |
82 void NotifyListeners(const DevicesStatus& status) const; | |
83 | |
84 Profile* profile_; | 40 Profile* profile_; |
85 PrefService* pref_service_; | 41 PrefService* pref_service_; |
86 PrefChangeRegistrar pref_change_registrar_; | 42 PrefChangeRegistrar pref_change_registrar_; |
87 Registry registry_; | 43 Registry registry_; |
88 | 44 |
89 typedef std::vector<Listener*> Listeners; | |
90 Listeners listeners_; | |
91 bool listening_; | |
92 | |
93 typedef std::map<int, std::string> ForwardingMap; | 45 typedef std::map<int, std::string> ForwardingMap; |
94 ForwardingMap forwarding_map_; | 46 ForwardingMap forwarding_map_; |
95 | 47 |
96 DISALLOW_COPY_AND_ASSIGN(PortForwardingController); | 48 DISALLOW_COPY_AND_ASSIGN(PortForwardingController); |
97 }; | 49 }; |
98 | 50 |
99 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_ | 51 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_PORT_FORWARDING_CONTROLLER_H_ |
OLD | NEW |