Chromium Code Reviews| Index: chrome/browser/media/router/discovery/dial/dial_registry.h |
| diff --git a/chrome/browser/media/router/discovery/dial/dial_registry.h b/chrome/browser/media/router/discovery/dial/dial_registry.h |
| index 12250ff40a657b40705dbfbf4a0aaa3614210aac..f0b72ed028e588d64b03507a28e1f68ddeca01c4 100644 |
| --- a/chrome/browser/media/router/discovery/dial/dial_registry.h |
| +++ b/chrome/browser/media/router/discovery/dial/dial_registry.h |
| @@ -15,7 +15,6 @@ |
| #include "base/containers/hash_tables.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| -#include "base/memory/ref_counted.h" |
| #include "base/observer_list.h" |
| #include "base/time/time.h" |
| #include "base/timer/timer.h" |
| @@ -54,13 +53,7 @@ class DialRegistry : public DialService::Observer, |
| virtual ~Observer() {} |
| }; |
| - // Create the DIAL registry and pass a reference to allow it to notify on |
| - // DIAL device events. |
| - DialRegistry(base::TimeDelta refresh_interval, |
| - base::TimeDelta expiration, |
| - const size_t max_devices); |
| - |
| - ~DialRegistry() override; |
| + static DialRegistry* GetInstance(); |
| // Called by the DIAL API when event listeners are added or removed. The dial |
| // service is started after the first listener is added and stopped after the |
| @@ -76,6 +69,11 @@ class DialRegistry : public DialService::Observer, |
| // already active. |
| bool DiscoverNow(); |
| + // Starts and stops periodic discovery. Periodic discovery is done when there |
| + // are registered event listeners. |
| + void StartPeriodicDiscovery(); |
| + void StopPeriodicDiscovery(); |
| + |
| // Returns the URL of the device description for the device identified by |
| // |label|, or an empty GURL if no such device exists. |
| GURL GetDeviceDescriptionURL(const std::string& label) const; |
| @@ -101,6 +99,14 @@ class DialRegistry : public DialService::Observer, |
| base::hash_map<std::string, std::unique_ptr<DialDeviceData>>; |
| using DeviceByLabelMap = std::map<std::string, DialDeviceData*>; |
| + friend class MockDialRegistry; |
| + friend struct base::DefaultSingletonTraits<DialRegistry>; |
| + |
| + // Create the DIAL registry and pass a reference to allow it to notify on |
|
imcheng
2017/03/23 23:06:00
nit: Remove this comment as it's not very useful.
zhaobin
2017/03/24 00:42:35
Done.
|
| + // DIAL device events. |
| + DialRegistry(); |
| + ~DialRegistry() override; |
| + |
| // DialService::Observer: |
| void OnDiscoveryRequest(DialService* service) override; |
| void OnDeviceDiscovered(DialService* service, |
| @@ -117,10 +123,6 @@ class DialRegistry : public DialService::Observer, |
| void OnDialDeviceEvent(const DeviceList& devices); |
| void OnDialError(DialErrorCode type); |
| - // Starts and stops periodic discovery. Periodic discovery is done when there |
| - // are registered event listeners. |
| - void StartPeriodicDiscovery(); |
| - void StopPeriodicDiscovery(); |
| // Check whether we are in a state ready to discover and dispatch error |
| // notifications if not. |
| @@ -179,8 +181,9 @@ class DialRegistry : public DialService::Observer, |
| // construct the device list sent to API clients. |
| DeviceByLabelMap device_by_label_map_; |
| - // Timer used to manage periodic discovery requests. |
| - base::RepeatingTimer repeating_timer_; |
| + // Timer used to manage periodic discovery requests. Timer is created and |
| + // destroyed on IO thread. |
| + std::unique_ptr<base::RepeatingTimer> repeating_timer_; |
| // Interface from which the DIAL API is notified of DIAL device events. the |
| // DIAL API owns this DIAL registry. |