Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(996)

Side by Side Diff: chrome/browser/extensions/api/dial/dial_registry.h

Issue 2702503003: [Dial] Refactor DialRegistry and DeviceDescriptionFetcher so they can be used by MediaSinkService (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // update is triggered by dial.discoverNow or an error occured. 50 // update is triggered by dial.discoverNow or an error occured.
51 virtual void OnDialDeviceEvent(const DeviceList& devices) = 0; 51 virtual void OnDialDeviceEvent(const DeviceList& devices) = 0;
52 virtual void OnDialError(DialErrorCode type) = 0; 52 virtual void OnDialError(DialErrorCode type) = 0;
53 53
54 protected: 54 protected:
55 virtual ~Observer() {} 55 virtual ~Observer() {}
56 }; 56 };
57 57
58 // Create the DIAL registry and pass a reference to allow it to notify on 58 // Create the DIAL registry and pass a reference to allow it to notify on
59 // DIAL device events. 59 // DIAL device events.
60 DialRegistry(Observer* dial_api, 60 DialRegistry(Observer* dial_api,
mark a. foltz 2017/03/01 21:44:00 Can we use the Register API below instead of also
zhaobin 2017/03/02 07:04:35 Done.
61 const base::TimeDelta& refresh_interval, 61 const base::TimeDelta& refresh_interval,
62 const base::TimeDelta& expiration, 62 const base::TimeDelta& expiration,
63 const size_t max_devices); 63 const size_t max_devices);
64 64
65 ~DialRegistry() override; 65 ~DialRegistry() override;
66 66
67 // Called by the DIAL API when event listeners are added or removed. The dial 67 // Called by the DIAL API when event listeners are added or removed. The dial
68 // service is started after the first listener is added and stopped after the 68 // service is started after the first listener is added and stopped after the
69 // last listener is removed. 69 // last listener is removed.
70 void OnListenerAdded(); 70 void OnListenerAdded();
71 void OnListenerRemoved(); 71 void OnListenerRemoved();
72 72
73 // This class does not take ownership of observer.
74 void RegisterObserver(Observer* observer);
75 void UnregisterObserver(Observer* observer);
76
73 // Called by the DIAL API to try to kickoff a discovery if there is not one 77 // Called by the DIAL API to try to kickoff a discovery if there is not one
74 // already active. 78 // already active.
75 bool DiscoverNow(); 79 bool DiscoverNow();
76 80
77 // Returns the URL of the device description for the device identified by 81 // Returns the URL of the device description for the device identified by
78 // |label|, or an empty GURL if no such device exists. 82 // |label|, or an empty GURL if no such device exists.
79 GURL GetDeviceDescriptionURL(const std::string& label) const; 83 GURL GetDeviceDescriptionURL(const std::string& label) const;
80 84
81 // Adds a device directly to the registry as if it was discovered. For tests 85 // Adds a device directly to the registry as if it was discovered. For tests
82 // only. Note that if discovery is actually started, this device will be 86 // only. Note that if discovery is actually started, this device will be
(...skipping 21 matching lines...) Expand all
104 void OnDeviceDiscovered(DialService* service, 108 void OnDeviceDiscovered(DialService* service,
105 const DialDeviceData& device) override; 109 const DialDeviceData& device) override;
106 void OnDiscoveryFinished(DialService* service) override; 110 void OnDiscoveryFinished(DialService* service) override;
107 void OnError(DialService* service, 111 void OnError(DialService* service,
108 const DialService::DialServiceErrorCode& code) override; 112 const DialService::DialServiceErrorCode& code) override;
109 113
110 // net::NetworkChangeObserver: 114 // net::NetworkChangeObserver:
111 void OnNetworkChanged( 115 void OnNetworkChanged(
112 net::NetworkChangeNotifier::ConnectionType type) override; 116 net::NetworkChangeNotifier::ConnectionType type) override;
113 117
118 // Notify all observers about DialDeviceEvent or DialError.
119 void OnDialDeviceEvent(const DeviceList& devices);
120 void OnDialError(DialErrorCode type);
121
114 // Starts and stops periodic discovery. Periodic discovery is done when there 122 // Starts and stops periodic discovery. Periodic discovery is done when there
115 // are registered event listeners. 123 // are registered event listeners.
116 void StartPeriodicDiscovery(); 124 void StartPeriodicDiscovery();
117 void StopPeriodicDiscovery(); 125 void StopPeriodicDiscovery();
118 126
119 // Check whether we are in a state ready to discover and dispatch error 127 // Check whether we are in a state ready to discover and dispatch error
120 // notifications if not. 128 // notifications if not.
121 bool ReadyToDiscover(); 129 bool ReadyToDiscover();
122 130
123 // Purge our whole registry. We may need to do this occasionally, e.g. when 131 // Purge our whole registry. We may need to do this occasionally, e.g. when
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 179
172 // A map used to track known devices sorted by label. We iterate over this to 180 // A map used to track known devices sorted by label. We iterate over this to
173 // construct the device list sent to API clients. 181 // construct the device list sent to API clients.
174 DeviceByLabelMap device_by_label_map_; 182 DeviceByLabelMap device_by_label_map_;
175 183
176 // Timer used to manage periodic discovery requests. 184 // Timer used to manage periodic discovery requests.
177 base::RepeatingTimer repeating_timer_; 185 base::RepeatingTimer repeating_timer_;
178 186
179 // Interface from which the DIAL API is notified of DIAL device events. the 187 // Interface from which the DIAL API is notified of DIAL device events. the
180 // DIAL API owns this DIAL registry. 188 // DIAL API owns this DIAL registry.
181 Observer* const dial_api_; 189 std::set<Observer*> observers_;
mark a. foltz 2017/03/01 21:44:00 Can you use base::ObserverList?
zhaobin 2017/03/02 07:04:35 Done.
182 190
183 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestAddRemoveListeners); 191 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestAddRemoveListeners);
184 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNoDevicesDiscovered); 192 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNoDevicesDiscovered);
185 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestDevicesDiscovered); 193 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestDevicesDiscovered);
186 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, 194 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest,
187 TestDevicesDiscoveredWithTwoListeners); 195 TestDevicesDiscoveredWithTwoListeners);
188 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestDeviceExpires); 196 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestDeviceExpires);
189 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestExpiredDeviceIsRediscovered); 197 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestExpiredDeviceIsRediscovered);
190 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, 198 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest,
191 TestRemovingListenerDoesNotClearList); 199 TestRemovingListenerDoesNotClearList);
192 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNetworkEventConnectionLost); 200 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, TestNetworkEventConnectionLost);
193 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest, 201 FRIEND_TEST_ALL_PREFIXES(DialRegistryTest,
194 TestNetworkEventConnectionRestored); 202 TestNetworkEventConnectionRestored);
195 DISALLOW_COPY_AND_ASSIGN(DialRegistry); 203 DISALLOW_COPY_AND_ASSIGN(DialRegistry);
196 }; 204 };
197 205
198 } // namespace dial 206 } // namespace dial
199 } // namespace api 207 } // namespace api
200 } // namespace extensions 208 } // namespace extensions
201 209
202 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_ 210 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DIAL_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698