Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/singleton.h" | |
| 15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/threading/thread_checker.h" | |
| 16 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" | 18 #include "chrome/browser/media/router/discovery/mdns/dns_sd_delegate.h" |
| 17 | 19 |
| 18 namespace local_discovery { | 20 namespace local_discovery { |
| 19 class ServiceDiscoverySharedClient; | 21 class ServiceDiscoverySharedClient; |
| 20 } | 22 } |
| 21 | 23 |
| 24 namespace extensions { | |
| 25 namespace { | |
| 26 class MockDnsSdRegistry; | |
|
mark a. foltz
2017/05/11 23:22:24
This is a sign this mock should live in c/b/media/
zhaobin
2017/05/12 17:35:00
Done.
| |
| 27 } | |
| 28 } // namespace extensions | |
| 29 | |
| 22 namespace media_router { | 30 namespace media_router { |
| 23 | 31 |
| 24 class DnsSdDeviceLister; | 32 class DnsSdDeviceLister; |
| 25 class ServiceTypeData; | 33 class ServiceTypeData; |
| 26 | 34 |
| 27 // Registry class for keeping track of discovered network services over DNS-SD. | 35 // Registry class for keeping track of discovered network services over DNS-SD. |
| 28 class DnsSdRegistry : public DnsSdDelegate { | 36 class DnsSdRegistry : public DnsSdDelegate { |
| 29 public: | 37 public: |
| 30 typedef std::vector<DnsSdService> DnsSdServiceList; | 38 typedef std::vector<DnsSdService> DnsSdServiceList; |
| 31 | 39 |
| 32 class DnsSdObserver { | 40 class DnsSdObserver { |
| 33 public: | 41 public: |
| 34 virtual void OnDnsSdEvent(const std::string& service_type, | 42 virtual void OnDnsSdEvent(const std::string& service_type, |
| 35 const DnsSdServiceList& services) = 0; | 43 const DnsSdServiceList& services) = 0; |
| 36 | 44 |
| 37 protected: | 45 protected: |
| 38 virtual ~DnsSdObserver() {} | 46 virtual ~DnsSdObserver() {} |
| 39 }; | 47 }; |
| 40 | 48 |
| 41 DnsSdRegistry(); | 49 static DnsSdRegistry* GetInstance(); |
| 42 explicit DnsSdRegistry(local_discovery::ServiceDiscoverySharedClient* client); | |
| 43 virtual ~DnsSdRegistry(); | |
| 44 | 50 |
| 45 // Publishes the current device list for |service_type| to event listeners | 51 // Publishes the current device list for |service_type| to event listeners |
| 46 // whose event filter matches the service type. | 52 // whose event filter matches the service type. |
| 47 virtual void Publish(const std::string& service_type); | 53 virtual void Publish(const std::string& service_type); |
| 48 | 54 |
| 49 // Immediately issues a multicast DNS query for all service types of the | 55 // Immediately issues a multicast DNS query for all service types of the |
| 50 // calling extension. | 56 // calling extension. |
| 51 virtual void ForceDiscovery(); | 57 virtual void ForceDiscovery(); |
| 52 | 58 |
| 53 // Observer registration for parties interested in discovery events. | 59 // Observer registration for parties interested in discovery events. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 void ServiceChanged(const std::string& service_type, | 107 void ServiceChanged(const std::string& service_type, |
| 102 bool added, | 108 bool added, |
| 103 const DnsSdService& service) override; | 109 const DnsSdService& service) override; |
| 104 void ServiceRemoved(const std::string& service_type, | 110 void ServiceRemoved(const std::string& service_type, |
| 105 const std::string& service_name) override; | 111 const std::string& service_name) override; |
| 106 void ServicesFlushed(const std::string& service_type) override; | 112 void ServicesFlushed(const std::string& service_type) override; |
| 107 | 113 |
| 108 std::map<std::string, std::unique_ptr<ServiceTypeData>> service_data_map_; | 114 std::map<std::string, std::unique_ptr<ServiceTypeData>> service_data_map_; |
| 109 | 115 |
| 110 private: | 116 private: |
| 117 friend struct base::DefaultSingletonTraits<DnsSdRegistry>; | |
| 118 friend class extensions::MockDnsSdRegistry; | |
| 119 friend class TestDnsSdRegistry; | |
| 120 | |
| 121 DnsSdRegistry(); | |
| 122 explicit DnsSdRegistry(local_discovery::ServiceDiscoverySharedClient* client); | |
| 123 virtual ~DnsSdRegistry(); | |
| 124 | |
| 111 void DispatchApiEvent(const std::string& service_type); | 125 void DispatchApiEvent(const std::string& service_type); |
| 112 bool IsRegistered(const std::string& service_type); | 126 bool IsRegistered(const std::string& service_type); |
| 113 | 127 |
| 114 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> | 128 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> |
| 115 service_discovery_client_; | 129 service_discovery_client_; |
| 116 base::ObserverList<DnsSdObserver> observers_; | 130 base::ObserverList<DnsSdObserver> observers_; |
| 131 base::ThreadChecker thread_checker_; | |
| 117 | 132 |
| 118 DISALLOW_COPY_AND_ASSIGN(DnsSdRegistry); | 133 DISALLOW_COPY_AND_ASSIGN(DnsSdRegistry); |
| 119 }; | 134 }; |
| 120 | 135 |
| 121 } // namespace media_router | 136 } // namespace media_router |
| 122 | 137 |
| 123 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ | 138 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ |
| OLD | NEW |