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

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

Issue 23437015: Initial chrome.mdns API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use new event filter Created 7 years, 3 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "chrome/browser/extensions/api/mdns/nsd_registry.h"
14 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
15 #include "chrome/browser/extensions/event_router.h"
16
17 namespace extensions {
18
19 class NsdRegistry;
20
21 // MDnsAPI is instantiated with the profile and will listen for extensions that
22 // register listeners for the chrome.mdns extension API. It will use an Network
23 // Service Discovery type registry class to start the mDNS listener process (if
24 // necessary) and observe new service events to dispatch them to registered
25 // extensions. The Network Service Discovery registry is a location for
26 // managing discovery protocols.
27 class MDnsAPI : public ProfileKeyedAPI,
28 public EventRouter::Observer,
29 public NsdRegistry::NsdObserver {
30 public:
31 explicit MDnsAPI(Profile* profile);
32 virtual ~MDnsAPI();
33
34 static MDnsAPI* Get(Profile* profile);
35
36 // ProfileKeyedAPI implementation.
37 static ProfileKeyedAPIFactory<MDnsAPI>* GetFactoryInstance();
38
39 // Used to mock out the NsdRegistry for testing.
40 void SetNsdRegistryForTesting(scoped_ptr<NsdRegistry> registry);
41
42 protected:
43 // Retrieve an instance of the registry. Lazily created when needed.
44 virtual NsdRegistry* nsd_registry();
45
46 private:
47 friend class ProfileKeyedAPIFactory<MDnsAPI>;
48
49 // EventRouter::Observer:
50 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
51 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
52
53 // NsdRegistry::Observer
54 virtual void OnMDnsEvent(
55 const std::string& service_type,
56 const NsdRegistry::NsdServiceList& services) OVERRIDE;
57
58 // ProfileKeyedAPI implementation.
59 static const char* service_name() {
60 return "MDnsAPI";
61 }
62
63 static const bool kServiceIsCreatedWithBrowserContext = true;
64 static const bool kServiceIsNULLWhileTesting = true;
65
66 // Update the current list of service types and update the NSD registry.
67 void UpdateMDnsListeners(const EventListenerInfo& details);
68
69 // Ensure methods are only called on UI thread.
70 base::ThreadChecker thread_checker_;
71 Profile* const profile_;
72 // Lazily created on first access and destroyed with this API class.
73 scoped_ptr<NsdRegistry> nsd_registry_;
74 // Current set of service types registered with the NSD registry.
75 std::set<std::string> service_types_;
76
77 DISALLOW_COPY_AND_ASSIGN(MDnsAPI);
78 };
79
80 } // namespace extensions
81
82 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698