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_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 <set> | 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "chrome/browser/extensions/api/mdns/dns_sd_registry.h" | 16 #include "chrome/browser/extensions/api/mdns/dns_sd_registry.h" |
17 #include "chrome/common/extensions/api/mdns.h" | 17 #include "chrome/common/extensions/api/mdns.h" |
18 #include "extensions/browser/api/async_api_function.h" | 18 #include "extensions/browser/api/async_api_function.h" |
19 #include "extensions/browser/browser_context_keyed_api_factory.h" | 19 #include "extensions/browser/browser_context_keyed_api_factory.h" |
20 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
21 #include "extensions/browser/extension_function.h" | 21 #include "extensions/browser/extension_function.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 class BrowserContext; | 24 class BrowserContext; |
(...skipping 13 matching lines...) Expand all Loading... |
38 public: | 38 public: |
39 explicit MDnsAPI(content::BrowserContext* context); | 39 explicit MDnsAPI(content::BrowserContext* context); |
40 ~MDnsAPI() override; | 40 ~MDnsAPI() override; |
41 | 41 |
42 static MDnsAPI* Get(content::BrowserContext* context); | 42 static MDnsAPI* Get(content::BrowserContext* context); |
43 | 43 |
44 // BrowserContextKeyedAPI implementation. | 44 // BrowserContextKeyedAPI implementation. |
45 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance(); | 45 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance(); |
46 | 46 |
47 // Used to mock out the DnsSdRegistry for testing. | 47 // Used to mock out the DnsSdRegistry for testing. |
48 void SetDnsSdRegistryForTesting(scoped_ptr<DnsSdRegistry> registry); | 48 void SetDnsSdRegistryForTesting(std::unique_ptr<DnsSdRegistry> registry); |
49 | 49 |
50 // Immediately issues a multicast DNS query for all service types. | 50 // Immediately issues a multicast DNS query for all service types. |
51 // NOTE: Discovery queries are sent to all event handlers associated with | 51 // NOTE: Discovery queries are sent to all event handlers associated with |
52 // |this| service's BrowserContext. | 52 // |this| service's BrowserContext. |
53 void ForceDiscovery(); | 53 void ForceDiscovery(); |
54 | 54 |
55 protected: | 55 protected: |
56 // Retrieve an instance of the registry. Lazily created when needed. | 56 // Retrieve an instance of the registry. Lazily created when needed. |
57 virtual DnsSdRegistry* dns_sd_registry(); | 57 virtual DnsSdRegistry* dns_sd_registry(); |
58 | 58 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // The counts for each service type are output to |service_type_counts|, if | 103 // The counts for each service type are output to |service_type_counts|, if |
104 // non-null. | 104 // non-null. |
105 void GetValidOnServiceListListeners(const std::string& service_type_filter, | 105 void GetValidOnServiceListListeners(const std::string& service_type_filter, |
106 std::set<std::string>* extension_ids, | 106 std::set<std::string>* extension_ids, |
107 ServiceTypeCounts* service_type_counts); | 107 ServiceTypeCounts* service_type_counts); |
108 | 108 |
109 // Ensure methods are only called on UI thread. | 109 // Ensure methods are only called on UI thread. |
110 base::ThreadChecker thread_checker_; | 110 base::ThreadChecker thread_checker_; |
111 content::BrowserContext* const browser_context_; | 111 content::BrowserContext* const browser_context_; |
112 // Lazily created on first access and destroyed with this API class. | 112 // Lazily created on first access and destroyed with this API class. |
113 scoped_ptr<DnsSdRegistry> dns_sd_registry_; | 113 std::unique_ptr<DnsSdRegistry> dns_sd_registry_; |
114 // Count of active listeners per service type, saved from the previous | 114 // Count of active listeners per service type, saved from the previous |
115 // invocation of UpdateMDnsListeners(). | 115 // invocation of UpdateMDnsListeners(). |
116 ServiceTypeCounts prev_service_counts_; | 116 ServiceTypeCounts prev_service_counts_; |
117 | 117 |
118 DISALLOW_COPY_AND_ASSIGN(MDnsAPI); | 118 DISALLOW_COPY_AND_ASSIGN(MDnsAPI); |
119 }; | 119 }; |
120 | 120 |
121 class MdnsForceDiscoveryFunction : public UIThreadExtensionFunction { | 121 class MdnsForceDiscoveryFunction : public UIThreadExtensionFunction { |
122 public: | 122 public: |
123 MdnsForceDiscoveryFunction(); | 123 MdnsForceDiscoveryFunction(); |
124 | 124 |
125 protected: | 125 protected: |
126 ~MdnsForceDiscoveryFunction() override; | 126 ~MdnsForceDiscoveryFunction() override; |
127 | 127 |
128 private: | 128 private: |
129 // UIThreadExtensionFunction override. | 129 // UIThreadExtensionFunction override. |
130 ResponseAction Run() override; | 130 ResponseAction Run() override; |
131 | 131 |
132 DECLARE_EXTENSION_FUNCTION("mdns.forceDiscovery", MDNS_FORCEDISCOVERY); | 132 DECLARE_EXTENSION_FUNCTION("mdns.forceDiscovery", MDNS_FORCEDISCOVERY); |
133 DISALLOW_COPY_AND_ASSIGN(MdnsForceDiscoveryFunction); | 133 DISALLOW_COPY_AND_ASSIGN(MdnsForceDiscoveryFunction); |
134 }; | 134 }; |
135 | 135 |
136 } // namespace extensions | 136 } // namespace extensions |
137 | 137 |
138 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ | 138 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ |
OLD | NEW |