OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 virtual ~Observer() {} | 51 virtual ~Observer() {} |
52 }; | 52 }; |
53 | 53 |
54 // Create the DIAL registry and pass a reference to allow it to notify on | 54 // Create the DIAL registry and pass a reference to allow it to notify on |
55 // DIAL device events. | 55 // DIAL device events. |
56 DialRegistry(Observer* dial_api, | 56 DialRegistry(Observer* dial_api, |
57 const base::TimeDelta& refresh_interval, | 57 const base::TimeDelta& refresh_interval, |
58 const base::TimeDelta& expiration, | 58 const base::TimeDelta& expiration, |
59 const size_t max_devices); | 59 const size_t max_devices); |
60 | 60 |
61 virtual ~DialRegistry(); | 61 ~DialRegistry() override; |
62 | 62 |
63 // Called by the DIAL API when event listeners are added or removed. The dial | 63 // Called by the DIAL API when event listeners are added or removed. The dial |
64 // service is started after the first listener is added and stopped after the | 64 // service is started after the first listener is added and stopped after the |
65 // last listener is removed. | 65 // last listener is removed. |
66 void OnListenerAdded(); | 66 void OnListenerAdded(); |
67 void OnListenerRemoved(); | 67 void OnListenerRemoved(); |
68 | 68 |
69 // Called by the DIAL API to try to kickoff a discovery if there is not one | 69 // Called by the DIAL API to try to kickoff a discovery if there is not one |
70 // already active. | 70 // already active. |
71 bool DiscoverNow(); | 71 bool DiscoverNow(); |
72 | 72 |
73 protected: | 73 protected: |
74 // Returns a new instance of the DIAL service. Overridden by tests. | 74 // Returns a new instance of the DIAL service. Overridden by tests. |
75 virtual DialService* CreateDialService(); | 75 virtual DialService* CreateDialService(); |
76 virtual void ClearDialService(); | 76 virtual void ClearDialService(); |
77 | 77 |
78 // Returns the current time. Overridden by tests. | 78 // Returns the current time. Overridden by tests. |
79 virtual base::Time Now() const; | 79 virtual base::Time Now() const; |
80 | 80 |
81 protected: | 81 protected: |
82 // The DIAL service. Periodic discovery is active when this is not NULL. | 82 // The DIAL service. Periodic discovery is active when this is not NULL. |
83 scoped_ptr<DialService> dial_; | 83 scoped_ptr<DialService> dial_; |
84 | 84 |
85 private: | 85 private: |
86 typedef base::hash_map<std::string, linked_ptr<DialDeviceData> > | 86 typedef base::hash_map<std::string, linked_ptr<DialDeviceData> > |
87 DeviceByIdMap; | 87 DeviceByIdMap; |
88 typedef std::map<std::string, linked_ptr<DialDeviceData> > DeviceByLabelMap; | 88 typedef std::map<std::string, linked_ptr<DialDeviceData> > DeviceByLabelMap; |
89 | 89 |
90 // DialService::Observer: | 90 // DialService::Observer: |
91 virtual void OnDiscoveryRequest(DialService* service) override; | 91 void OnDiscoveryRequest(DialService* service) override; |
92 virtual void OnDeviceDiscovered(DialService* service, | 92 void OnDeviceDiscovered(DialService* service, |
93 const DialDeviceData& device) override; | 93 const DialDeviceData& device) override; |
94 virtual void OnDiscoveryFinished(DialService* service) override; | 94 void OnDiscoveryFinished(DialService* service) override; |
95 virtual void OnError(DialService* service, | 95 void OnError(DialService* service, |
96 const DialService::DialServiceErrorCode& code) override; | 96 const DialService::DialServiceErrorCode& code) override; |
97 | 97 |
98 // net::NetworkChangeObserver: | 98 // net::NetworkChangeObserver: |
99 virtual void OnNetworkChanged( | 99 void OnNetworkChanged( |
100 net::NetworkChangeNotifier::ConnectionType type) override; | 100 net::NetworkChangeNotifier::ConnectionType type) override; |
101 | 101 |
102 // Starts and stops periodic discovery. Periodic discovery is done when there | 102 // Starts and stops periodic discovery. Periodic discovery is done when there |
103 // are registered event listeners. | 103 // are registered event listeners. |
104 void StartPeriodicDiscovery(); | 104 void StartPeriodicDiscovery(); |
105 void StopPeriodicDiscovery(); | 105 void StopPeriodicDiscovery(); |
106 | 106 |
107 // Check whether we are in a state ready to discover and dispatch error | 107 // Check whether we are in a state ready to discover and dispatch error |
108 // notifications if not. | 108 // notifications if not. |
109 bool ReadyToDiscover(); | 109 bool ReadyToDiscover(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 TestRemovingListenerDoesNotClearList); | 184 TestRemovingListenerDoesNotClearList); |
185 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNetworkEventConnectionLost); | 185 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNetworkEventConnectionLost); |
186 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, | 186 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, |
187 TestNetworkEventConnectionRestored); | 187 TestNetworkEventConnectionRestored); |
188 DISALLOW_COPY_AND_ASSIGN(DialRegistry); | 188 DISALLOW_COPY_AND_ASSIGN(DialRegistry); |
189 }; | 189 }; |
190 | 190 |
191 } // namespace extensions | 191 } // namespace extensions |
192 | 192 |
193 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ | 193 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ |
OLD | NEW |