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

Side by Side Diff: chrome/browser/media/router/discovery/mdns/dns_sd_registry.h

Issue 2874243003: [mDns] Make DnsSdRegistry a leaky singleton (Closed)
Patch Set: resolve code review comments from Mark Created 3 years, 7 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 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
22 namespace media_router { 24 namespace media_router {
23 25
24 class DnsSdDeviceLister; 26 class DnsSdDeviceLister;
25 class ServiceTypeData; 27 class ServiceTypeData;
26 28
27 // Registry class for keeping track of discovered network services over DNS-SD. 29 // Registry class for keeping track of discovered network services over DNS-SD.
28 class DnsSdRegistry : public DnsSdDelegate { 30 class DnsSdRegistry : public DnsSdDelegate {
29 public: 31 public:
30 typedef std::vector<DnsSdService> DnsSdServiceList; 32 typedef std::vector<DnsSdService> DnsSdServiceList;
31 33
32 class DnsSdObserver { 34 class DnsSdObserver {
33 public: 35 public:
34 virtual void OnDnsSdEvent(const std::string& service_type, 36 virtual void OnDnsSdEvent(const std::string& service_type,
35 const DnsSdServiceList& services) = 0; 37 const DnsSdServiceList& services) = 0;
36 38
37 protected: 39 protected:
38 virtual ~DnsSdObserver() {} 40 virtual ~DnsSdObserver() {}
39 }; 41 };
40 42
41 DnsSdRegistry(); 43 static DnsSdRegistry* GetInstance();
42 explicit DnsSdRegistry(local_discovery::ServiceDiscoverySharedClient* client);
43 virtual ~DnsSdRegistry();
44 44
45 // Publishes the current device list for |service_type| to event listeners 45 // Publishes the current device list for |service_type| to event listeners
46 // whose event filter matches the service type. 46 // whose event filter matches the service type.
47 virtual void Publish(const std::string& service_type); 47 virtual void Publish(const std::string& service_type);
48 48
49 // Immediately issues a multicast DNS query for all service types of the 49 // Immediately issues a multicast DNS query for all service types of the
50 // calling extension. 50 // calling extension.
51 virtual void ForceDiscovery(); 51 virtual void ForceDiscovery();
52 52
53 // Observer registration for parties interested in discovery events. 53 // Observer registration for parties interested in discovery events.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void ServiceChanged(const std::string& service_type, 101 void ServiceChanged(const std::string& service_type,
102 bool added, 102 bool added,
103 const DnsSdService& service) override; 103 const DnsSdService& service) override;
104 void ServiceRemoved(const std::string& service_type, 104 void ServiceRemoved(const std::string& service_type,
105 const std::string& service_name) override; 105 const std::string& service_name) override;
106 void ServicesFlushed(const std::string& service_type) override; 106 void ServicesFlushed(const std::string& service_type) override;
107 107
108 std::map<std::string, std::unique_ptr<ServiceTypeData>> service_data_map_; 108 std::map<std::string, std::unique_ptr<ServiceTypeData>> service_data_map_;
109 109
110 private: 110 private:
111 friend struct base::DefaultSingletonTraits<DnsSdRegistry>;
112 friend class MockDnsSdRegistry;
113 friend class TestDnsSdRegistry;
114
115 DnsSdRegistry();
116 explicit DnsSdRegistry(local_discovery::ServiceDiscoverySharedClient* client);
117 virtual ~DnsSdRegistry();
118
111 void DispatchApiEvent(const std::string& service_type); 119 void DispatchApiEvent(const std::string& service_type);
112 bool IsRegistered(const std::string& service_type); 120 bool IsRegistered(const std::string& service_type);
113 121
114 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> 122 scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
115 service_discovery_client_; 123 service_discovery_client_;
116 base::ObserverList<DnsSdObserver> observers_; 124 base::ObserverList<DnsSdObserver> observers_;
125 base::ThreadChecker thread_checker_;
117 126
118 DISALLOW_COPY_AND_ASSIGN(DnsSdRegistry); 127 DISALLOW_COPY_AND_ASSIGN(DnsSdRegistry);
119 }; 128 };
120 129
121 } // namespace media_router 130 } // namespace media_router
122 131
123 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_ 132 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MDNS_DNS_SD_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/router/BUILD.gn ('k') | chrome/browser/media/router/discovery/mdns/dns_sd_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698