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

Side by Side Diff: chrome/browser/extensions/api/mdns/mdns_api.h

Issue 2874243003: [mDns] Make DnsSdRegistry a leaky singleton (Closed)
Patch Set: 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_EXTENSIONS_API_MDNS_MDNS_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 27 matching lines...) Expand all
38 public media_router::DnsSdRegistry::DnsSdObserver { 38 public media_router::DnsSdRegistry::DnsSdObserver {
39 public: 39 public:
40 explicit MDnsAPI(content::BrowserContext* context); 40 explicit MDnsAPI(content::BrowserContext* context);
41 ~MDnsAPI() override; 41 ~MDnsAPI() override;
42 42
43 static MDnsAPI* Get(content::BrowserContext* context); 43 static MDnsAPI* Get(content::BrowserContext* context);
44 44
45 // BrowserContextKeyedAPI implementation. 45 // BrowserContextKeyedAPI implementation.
46 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance(); 46 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance();
47 47
48 // Used to mock out the DnsSdRegistry for testing. 48 // Used to mock out the DnsSdRegistry for testing. Does not take ownership of
49 void SetDnsSdRegistryForTesting( 49 // |registry|.
50 std::unique_ptr<media_router::DnsSdRegistry> registry); 50 void SetDnsSdRegistryForTesting(media_router::DnsSdRegistry* registry);
51 51
52 // Immediately issues a multicast DNS query for all service types. 52 // Immediately issues a multicast DNS query for all service types.
53 // NOTE: Discovery queries are sent to all event handlers associated with 53 // NOTE: Discovery queries are sent to all event handlers associated with
54 // |this| service's BrowserContext. 54 // |this| service's BrowserContext.
55 void ForceDiscovery(); 55 void ForceDiscovery();
56 56
57 protected: 57 protected:
58 // Retrieve an instance of the registry. Lazily created when needed. 58 // Retrieve an instance of the registry. Lazily created when needed.
59 virtual media_router::DnsSdRegistry* dns_sd_registry(); 59 virtual media_router::DnsSdRegistry* dns_sd_registry();
60 60
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // if non-null. 105 // if non-null.
106 // The counts for each service type are output to |service_type_counts|, if 106 // The counts for each service type are output to |service_type_counts|, if
107 // non-null. 107 // non-null.
108 void GetValidOnServiceListListeners(const std::string& service_type_filter, 108 void GetValidOnServiceListListeners(const std::string& service_type_filter,
109 std::set<std::string>* extension_ids, 109 std::set<std::string>* extension_ids,
110 ServiceTypeCounts* service_type_counts); 110 ServiceTypeCounts* service_type_counts);
111 111
112 // Ensure methods are only called on UI thread. 112 // Ensure methods are only called on UI thread.
113 base::ThreadChecker thread_checker_; 113 base::ThreadChecker thread_checker_;
114 content::BrowserContext* const browser_context_; 114 content::BrowserContext* const browser_context_;
115 // Lazily created on first access and destroyed with this API class. 115 // Raw pointer to a leaky singleton. Lazily created on first access. Must
116 std::unique_ptr<media_router::DnsSdRegistry> dns_sd_registry_; 116 // outlive this object.
117 media_router::DnsSdRegistry* dns_sd_registry_;
117 // Count of active listeners per service type, saved from the previous 118 // Count of active listeners per service type, saved from the previous
118 // invocation of UpdateMDnsListeners(). 119 // invocation of UpdateMDnsListeners().
119 ServiceTypeCounts prev_service_counts_; 120 ServiceTypeCounts prev_service_counts_;
120 121
121 DISALLOW_COPY_AND_ASSIGN(MDnsAPI); 122 DISALLOW_COPY_AND_ASSIGN(MDnsAPI);
122 }; 123 };
123 124
124 class MdnsForceDiscoveryFunction : public UIThreadExtensionFunction { 125 class MdnsForceDiscoveryFunction : public UIThreadExtensionFunction {
125 public: 126 public:
126 MdnsForceDiscoveryFunction(); 127 MdnsForceDiscoveryFunction();
127 128
128 protected: 129 protected:
129 ~MdnsForceDiscoveryFunction() override; 130 ~MdnsForceDiscoveryFunction() override;
130 131
131 private: 132 private:
132 // UIThreadExtensionFunction override. 133 // UIThreadExtensionFunction override.
133 ResponseAction Run() override; 134 ResponseAction Run() override;
134 135
135 DECLARE_EXTENSION_FUNCTION("mdns.forceDiscovery", MDNS_FORCEDISCOVERY); 136 DECLARE_EXTENSION_FUNCTION("mdns.forceDiscovery", MDNS_FORCEDISCOVERY);
136 DISALLOW_COPY_AND_ASSIGN(MdnsForceDiscoveryFunction); 137 DISALLOW_COPY_AND_ASSIGN(MdnsForceDiscoveryFunction);
137 }; 138 };
138 139
139 } // namespace extensions 140 } // namespace extensions
140 141
141 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ 142 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/mdns/mdns_api.cc » ('j') | chrome/browser/extensions/api/mdns/mdns_api_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698