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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_client.h

Issue 16272006: In-browser DNS-based service discovery system (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mdns_implementation
Patch Set: Created 7 years, 6 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_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
14 #include "net/base/host_port_pair.h"
15 #include "net/base/net_util.h"
16
17 namespace local_discovery {
18
19 struct Service {
Vitaly Buka (NO REVIEWS) 2013/06/18 23:01:46 Service -> ServiceDescription ?
Noam Samuel 2013/06/19 18:46:22 Done.
20 public:
21 Service();
22 ~Service();
23
24 // The address (in host/port format) for the service (from SRV record).
gene 2013/06/18 23:46:53 Do you need service name as a part of this class?
Noam Samuel 2013/06/19 18:46:22 Done.
25 net::HostPortPair address;
26 // The metadata (from TXT record) of the service.
27 std::vector<std::string> metadata;
28 // IP address of the service, if available from cache. May be empty.
29 net::IPAddressNumber ip_address;
30 // Last time the service was seen.
31 base::Time last_seen;
32 };
33
34 // Lets users browse the network for services of interest or listen for changes
35 // in the services they are interested in. See
36 // |ServiceDiscoveryClient::CreateServiceWatcher|.
37 class ServiceWatcher {
38 public:
39 class Delegate {
40 public:
41 virtual ~Delegate() {}
42
43 // A service has been added or removed for a certain service name.
44 virtual void OnServiceStatusChanged(bool available,
45 const std::string& service_name) = 0;
46
47 virtual void OnServiceChanged(const std::string& service_name) = 0;
gene 2013/06/18 23:46:53 Do you need to pass Service/ServiceDescription obj
Noam Samuel 2013/06/19 18:46:22 Users will need to resolve the service separately
48 };
49
50 // Listening will automatically stop when the destructor is called.
51 virtual ~ServiceWatcher() {}
52
53 // Start the service type watcher.
54 virtual bool Start() = 0;
55
56 // Get all known services names of this watcher's type. Return them in
57 // |services|.
58 virtual void GetAvailableServices(
59 std::vector<std::string>* services) const = 0;
60
61 // Read services from the cache, alerting the delegate to any service that
62 // is not yet known.
63 virtual void ReadCachedServices() = 0;
64
65 // Probe for services of this type.
66 virtual void DiscoverNewServices(bool force_update) = 0;
67
68 virtual std::string GetServiceType() const = 0;
69 };
70
71 // Represents a service on the network and allows users to access the service's
72 // address and metadata. See |ServiceDiscoveryClient::CreateServiceResolver|.
73 class ServiceResolver {
74 public:
75 enum RequestStatus {
76 STATUS_SUCCESS = 0,
77 STATUS_TIMEOUT = 1,
78 STATUS_KNOWN_NONEXISTENT = 2
79 };
80
81 // A callback for recieving the last time the PTR record has been seen.
gene 2013/06/18 23:46:53 Do you mean SRV record here?
Noam Samuel 2013/06/19 18:46:22 Whoops. This is completely the wrong comment. That
82 typedef base::Callback<void(RequestStatus)> ResolveCompleteCallback;
gene 2013/06/18 23:46:53 Do you need to pass Service/ServiceDescription her
Noam Samuel 2013/06/19 18:46:22 Done.
83
84 // Listening will automatically stop when the destructor is called.
85 virtual ~ServiceResolver() {}
86
87 // Start the service reader.
88 virtual bool StartResolving() = 0;
89
90 // Check whether the resolver is currently resolving. Can be called multiple
91 // times.
92 virtual bool IsResolving() const = 0;
93
94 // Check wheteher the resolver has resolved the service already.
95 virtual bool HasResolved() const = 0;
96
97 virtual std::string GetHumanReadableName() const = 0;
98 virtual std::string GetType() const = 0;
99 virtual std::string GetName() const = 0;
100
101 virtual const Service& GetService() const = 0;
102 };
103
104 class ServiceDiscoveryClient {
105 public:
106 virtual ~ServiceDiscoveryClient() {}
107
108 // Create a service object listening for DNS-SD service announcements on
109 // service type |service_type|. If a service type watcher is |active|,
gene 2013/06/18 23:46:53 you can remove part about active listener here
Noam Samuel 2013/06/19 18:46:22 Done.
110 // it will query the network for new services. If |alert_existing_services| is
111 // true, the delegate will be alerted for services already in the cache.
112 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher(
113 const std::string& service_type,
114 ServiceWatcher::Delegate* delegate) = 0;
115
116 // Create a service object listening for DNS-SD service announcements on
117 // service |service_name|. |delegate| may be null in which case the
118 // object will not recieve continuous announcements but may still query
119 // about the relevant service.
120 virtual scoped_ptr<ServiceResolver> CreateServiceResolver(
121 const std::string& service_name,
122 const ServiceResolver::ResolveCompleteCallback& callback) = 0;
123
124 // Lazily create and return static instance for ServiceDiscoveryClient.
125 static ServiceDiscoveryClient* GetInstance();
126
127 // Set the global instance (for testing). MUST be called before the first call
128 // to GetInstance.
129 static void SetInstance(ServiceDiscoveryClient* instance);
130 };
131
132 } // namespace local_discovery
133
134 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698