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

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

Issue 22870011: chrome.mdns API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: can listen 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 | Annotate | Revision Log
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_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_SERVICE_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h"
13
14 #include "chrome/browser/local_discovery/service_discovery_host_client.h"
15
16 // namespace local_discovery {
17 // class ServiceWatcher {
18 // enum UpdateType;
19 // }
20 // class ServiceDiscoveryClient;
21 // }
22
23 namespace extensions {
24
25 namespace api {
26 namespace mdns {
27 struct MDnsService;
28 }
29 }
30
31 // Manages a watcher for a specific MDNS/DNS-SD service type and notifies
32 // a delegate of changes to watched services.
33 class MDnsService {
34 public:
35 // Delegate that is notified when a watched service is added, updated or
36 // removed.
37 class Delegate {
38 public:
39 virtual void ServiceAdded(const std::string& service_name,
40 const api::mdns::MDnsService& service) = 0;
41 virtual void ServiceUpdated(const std::string& service_name,
42 const api::mdns::MDnsService& service) = 0;
43 virtual void ServiceRemoved(const std::string& service_name) = 0;
44 };
45
46 explicit MDnsService(const std::string& service_type,
47 MDnsService::Delegate *delegate);
48 ~MDnsService();
49
50 // Starts the service watcher.
51 bool Start();
52
53 // Stops the service watcher.
54 void Stop();
55
56 // Requests that the service watcher issue an immediate query for services.
57 // force_update will first clear the service cache.
58 void Discover(bool force_update);
59
60 const std::string& service_type();
61
62 private:
63 typedef std::map<std::string, linked_ptr<local_discovery::ServiceResolver> >
64 ServiceResolverMap;
65
66 // Invoked when the watcher notifies us of a service change.
67 void OnServiceUpdated(
68 local_discovery::ServiceWatcher::UpdateType update,
69 const std::string& service_name);
70
71 void OnResolveComplete(
72 bool added,
73 local_discovery::ServiceResolver::RequestStatus status,
74 const local_discovery::ServiceDescription& description);
75
76 // The service type that we are watching.
77 const std::string service_type_;
78
79 // The delegate to notify of changes to services.
80 // TODO: I think this should be a reference.
mark a. foltz 2013/08/23 23:27:23 SGTM if the delegate will always outlive this obje
81 MDnsService::Delegate * delegate_;
82
83 // The instance of the service discovery client.
84 local_discovery::ServiceDiscoveryClient* service_discovery_client_;
85
86 // The instance of the service watcher.
87 scoped_ptr<local_discovery::ServiceWatcher> service_watcher_;
88
89 // True when the watcher is running.
90 bool running_;
91
92 ServiceResolverMap resolvers_;
93
94 DISALLOW_COPY_AND_ASSIGN(MDnsService);
95 };
96
97 } // namespace extensions
98
99 #endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698