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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // MDnsAPI is instantiated with the profile and will listen for extensions that | 25 // MDnsAPI is instantiated with the profile and will listen for extensions that |
26 // register listeners for the chrome.mdns extension API. It will use a registry | 26 // register listeners for the chrome.mdns extension API. It will use a registry |
27 // class to start the mDNS listener process (if necessary) and observe new | 27 // class to start the mDNS listener process (if necessary) and observe new |
28 // service events to dispatch them to registered extensions. | 28 // service events to dispatch them to registered extensions. |
29 class MDnsAPI : public BrowserContextKeyedAPI, | 29 class MDnsAPI : public BrowserContextKeyedAPI, |
30 public EventRouter::Observer, | 30 public EventRouter::Observer, |
31 public DnsSdRegistry::DnsSdObserver { | 31 public DnsSdRegistry::DnsSdObserver { |
32 public: | 32 public: |
33 explicit MDnsAPI(content::BrowserContext* context); | 33 explicit MDnsAPI(content::BrowserContext* context); |
34 virtual ~MDnsAPI(); | 34 ~MDnsAPI() override; |
35 | 35 |
36 static MDnsAPI* Get(content::BrowserContext* context); | 36 static MDnsAPI* Get(content::BrowserContext* context); |
37 | 37 |
38 // BrowserContextKeyedAPI implementation. | 38 // BrowserContextKeyedAPI implementation. |
39 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance(); | 39 static BrowserContextKeyedAPIFactory<MDnsAPI>* GetFactoryInstance(); |
40 | 40 |
41 // Used to mock out the DnsSdRegistry for testing. | 41 // Used to mock out the DnsSdRegistry for testing. |
42 void SetDnsSdRegistryForTesting(scoped_ptr<DnsSdRegistry> registry); | 42 void SetDnsSdRegistryForTesting(scoped_ptr<DnsSdRegistry> registry); |
43 | 43 |
44 protected: | 44 protected: |
45 // Retrieve an instance of the registry. Lazily created when needed. | 45 // Retrieve an instance of the registry. Lazily created when needed. |
46 virtual DnsSdRegistry* dns_sd_registry(); | 46 virtual DnsSdRegistry* dns_sd_registry(); |
47 | 47 |
48 private: | 48 private: |
49 friend class BrowserContextKeyedAPIFactory<MDnsAPI>; | 49 friend class BrowserContextKeyedAPIFactory<MDnsAPI>; |
50 | 50 |
51 // EventRouter::Observer: | 51 // EventRouter::Observer: |
52 virtual void OnListenerAdded(const EventListenerInfo& details) override; | 52 void OnListenerAdded(const EventListenerInfo& details) override; |
53 virtual void OnListenerRemoved(const EventListenerInfo& details) override; | 53 void OnListenerRemoved(const EventListenerInfo& details) override; |
54 | 54 |
55 // DnsSdRegistry::Observer | 55 // DnsSdRegistry::Observer |
56 virtual void OnDnsSdEvent( | 56 void OnDnsSdEvent(const std::string& service_type, |
57 const std::string& service_type, | 57 const DnsSdRegistry::DnsSdServiceList& services) override; |
58 const DnsSdRegistry::DnsSdServiceList& services) override; | |
59 | 58 |
60 // BrowserContextKeyedAPI implementation. | 59 // BrowserContextKeyedAPI implementation. |
61 static const char* service_name() { | 60 static const char* service_name() { |
62 return "MDnsAPI"; | 61 return "MDnsAPI"; |
63 } | 62 } |
64 | 63 |
65 static const bool kServiceIsCreatedWithBrowserContext = true; | 64 static const bool kServiceIsCreatedWithBrowserContext = true; |
66 static const bool kServiceIsNULLWhileTesting = true; | 65 static const bool kServiceIsNULLWhileTesting = true; |
67 | 66 |
68 // Update the current list of service types and update the registry. | 67 // Update the current list of service types and update the registry. |
69 void UpdateMDnsListeners(const EventListenerInfo& details); | 68 void UpdateMDnsListeners(const EventListenerInfo& details); |
70 | 69 |
71 // Ensure methods are only called on UI thread. | 70 // Ensure methods are only called on UI thread. |
72 base::ThreadChecker thread_checker_; | 71 base::ThreadChecker thread_checker_; |
73 content::BrowserContext* const browser_context_; | 72 content::BrowserContext* const browser_context_; |
74 // Lazily created on first access and destroyed with this API class. | 73 // Lazily created on first access and destroyed with this API class. |
75 scoped_ptr<DnsSdRegistry> dns_sd_registry_; | 74 scoped_ptr<DnsSdRegistry> dns_sd_registry_; |
76 // Current set of service types registered with the registry. | 75 // Current set of service types registered with the registry. |
77 std::set<std::string> service_types_; | 76 std::set<std::string> service_types_; |
78 | 77 |
79 DISALLOW_COPY_AND_ASSIGN(MDnsAPI); | 78 DISALLOW_COPY_AND_ASSIGN(MDnsAPI); |
80 }; | 79 }; |
81 | 80 |
82 } // namespace extensions | 81 } // namespace extensions |
83 | 82 |
84 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ | 83 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_ |
OLD | NEW |