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 <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" | 16 #include "chrome/browser/media/router/discovery/mdns/dns_sd_registry.h" |
mark a. foltz
2017/05/12 18:51:18
Can this #include be moved to the .cc? You have a
zhaobin
2017/05/12 21:15:59
Remove forward declaration. This #include is neede
| |
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; |
25 } | 25 } |
26 | 26 |
(...skipping 11 matching lines...) Expand all Loading... | |
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 Loading... | |
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_ |
OLD | NEW |