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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_host_client.cc

Issue 23851008: Added cache flush on network change to ServiceDiscoveryHostClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 #include "chrome/browser/local_discovery/service_discovery_host_client.h" 5 #include "chrome/browser/local_discovery/service_discovery_host_client.h"
6 6
7 #include "chrome/common/local_discovery/local_discovery_messages.h" 7 #include "chrome/common/local_discovery/local_discovery_messages.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/utility_process_host.h" 9 #include "content/public/browser/utility_process_host.h"
10 10
11 namespace local_discovery { 11 namespace local_discovery {
12 12
13 using content::BrowserThread; 13 using content::BrowserThread;
14 using content::UtilityProcessHost; 14 using content::UtilityProcessHost;
15 15
16 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher { 16 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher {
17 public: 17 public:
18 ServiceWatcherProxy(ServiceDiscoveryHostClient* host, 18 ServiceWatcherProxy(ServiceDiscoveryHostClient* host,
19 const std::string& service_type, 19 const std::string& service_type,
20 const ServiceWatcher::UpdatedCallback& callback) 20 const ServiceWatcher::UpdatedCallback& callback)
21 : host_(host), 21 : host_(host),
22 service_type_(service_type), 22 service_type_(service_type),
23 id_(host_->RegisterWatcherCallback(callback)), 23 id_(host_->RegisterWatcherProxy(this)),
24 started_(false) { 24 started_(false),
25 callback_(callback) {
25 } 26 }
26 27
27 virtual ~ServiceWatcherProxy() { 28 virtual ~ServiceWatcherProxy() {
28 host_->UnregisterWatcherCallback(id_); 29 host_->UnregisterWatcherProxy(id_);
29 if (started_) 30 if (started_)
30 host_->Send(new LocalDiscoveryMsg_DestroyWatcher(id_)); 31 host_->Send(new LocalDiscoveryMsg_DestroyWatcher(id_));
31 } 32 }
32 33
33 virtual void Start() OVERRIDE { 34 virtual void Start() OVERRIDE {
34 DCHECK(!started_); 35 DCHECK(!started_);
35 host_->Send(new LocalDiscoveryMsg_StartWatcher(id_, service_type_)); 36 SendStartMessage();
36 started_ = true; 37 started_ = true;
37 } 38 }
38 39
39 virtual void DiscoverNewServices(bool force_update) OVERRIDE { 40 virtual void DiscoverNewServices(bool force_update) OVERRIDE {
40 DCHECK(started_); 41 DCHECK(started_);
41 host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update)); 42 host_->Send(new LocalDiscoveryMsg_DiscoverServices(id_, force_update));
42 } 43 }
43 44
44 virtual std::string GetServiceType() const OVERRIDE { 45 virtual std::string GetServiceType() const OVERRIDE {
45 return service_type_; 46 return service_type_;
46 } 47 }
47 48
49 void RestartIfNecessary() {
50 if (started_) {
51 SendStartMessage();
52 callback_.Run(ServiceWatcher::UPDATE_CACHE_FLUSHED, "");
53 }
54 }
55
56 ServiceWatcher::UpdatedCallback callback() { return callback_; }
57
48 private: 58 private:
59 void SendStartMessage() {
60 host_->Send(new LocalDiscoveryMsg_StartWatcher(id_, service_type_));
61 }
62
49 scoped_refptr<ServiceDiscoveryHostClient> host_; 63 scoped_refptr<ServiceDiscoveryHostClient> host_;
50 const std::string service_type_; 64 const std::string service_type_;
51 const uint64 id_; 65 const uint64 id_;
52 bool started_; 66 bool started_;
67 ServiceWatcher::UpdatedCallback callback_;
53 }; 68 };
54 69
55 class ServiceDiscoveryHostClient::ServiceResolverProxy 70 class ServiceDiscoveryHostClient::ServiceResolverProxy
56 : public ServiceResolver { 71 : public ServiceResolver {
57 public: 72 public:
58 ServiceResolverProxy(ServiceDiscoveryHostClient* host, 73 ServiceResolverProxy(ServiceDiscoveryHostClient* host,
59 const std::string& service_name, 74 const std::string& service_name,
60 const ServiceResolver::ResolveCompleteCallback& callback) 75 const ServiceResolver::ResolveCompleteCallback& callback)
61 : host_(host), 76 : host_(host),
62 service_name_(service_name), 77 service_name_(service_name),
63 id_(host->RegisterResolverCallback(callback)), 78 id_(host->RegisterResolverProxy(this)),
64 started_(false) { 79 started_(false),
80 finished_(false),
81 callback_(callback) {
65 } 82 }
66 83
67 virtual ~ServiceResolverProxy() { 84 virtual ~ServiceResolverProxy() {
68 host_->UnregisterResolverCallback(id_); 85 host_->UnregisterResolverProxy(id_);
69 if (started_) 86 if (started_)
70 host_->Send(new LocalDiscoveryMsg_DestroyResolver(id_)); 87 host_->Send(new LocalDiscoveryMsg_DestroyResolver(id_));
71 } 88 }
72 89
73 virtual void StartResolving() OVERRIDE { 90 virtual void StartResolving() OVERRIDE {
74 DCHECK(!started_); 91 DCHECK(!started_);
75 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_)); 92 SendStartMessage();
76 started_ = true; 93 started_ = true;
77 } 94 }
78 95
79 virtual std::string GetName() const OVERRIDE { 96 virtual std::string GetName() const OVERRIDE {
80 return service_name_; 97 return service_name_;
81 } 98 }
82 99
100 void Finish() {
101 finished_ = true;
102 }
103
104 void RestartIfNecessary() {
105 if (started_) {
106 if (finished_) {
107 started_ = false;
108 } else {
109 SendStartMessage();
110 }
111 }
112 }
113
114 ServiceResolver::ResolveCompleteCallback callback() { return callback_; }
115
83 private: 116 private:
117 void SendStartMessage() {
118 host_->Send(new LocalDiscoveryMsg_ResolveService(id_, service_name_));
119 }
120
84 scoped_refptr<ServiceDiscoveryHostClient> host_; 121 scoped_refptr<ServiceDiscoveryHostClient> host_;
85 const std::string service_name_; 122 const std::string service_name_;
86 const uint64 id_; 123 const uint64 id_;
87 bool started_; 124 bool started_;
125 bool finished_;
126 ServiceResolver::ResolveCompleteCallback callback_;
88 }; 127 };
89 128
90 class ServiceDiscoveryHostClient::LocalDomainResolverProxy 129 class ServiceDiscoveryHostClient::LocalDomainResolverProxy
91 : public LocalDomainResolver { 130 : public LocalDomainResolver {
92 public: 131 public:
93 LocalDomainResolverProxy(ServiceDiscoveryHostClient* host, 132 LocalDomainResolverProxy(ServiceDiscoveryHostClient* host,
94 const std::string& domain, 133 const std::string& domain,
95 net::AddressFamily address_family, 134 net::AddressFamily address_family,
96 const LocalDomainResolver::IPAddressCallback& callback) 135 const LocalDomainResolver::IPAddressCallback& callback)
97 : host_(host), 136 : host_(host),
98 domain_(domain), 137 domain_(domain),
99 address_family_(address_family), 138 address_family_(address_family),
100 id_(host->RegisterLocalDomainResolverCallback(callback)), 139 id_(host->RegisterLocalDomainResolverProxy(this)),
101 started_(false) { 140 started_(false),
141 callback_(callback) {
102 } 142 }
103 143
104 virtual ~LocalDomainResolverProxy() { 144 virtual ~LocalDomainResolverProxy() {
105 host_->UnregisterLocalDomainResolverCallback(id_); 145 host_->UnregisterLocalDomainResolverProxy(id_);
106 if (started_) 146 if (started_)
107 host_->Send(new LocalDiscoveryMsg_DestroyLocalDomainResolver(id_)); 147 host_->Send(new LocalDiscoveryMsg_DestroyLocalDomainResolver(id_));
108 } 148 }
109 149
110 virtual void Start() OVERRIDE { 150 virtual void Start() OVERRIDE {
111 DCHECK(!started_); 151 DCHECK(!started_);
112 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_, 152 SendStartMessage();
113 address_family_));
114 started_ = true; 153 started_ = true;
115 } 154 }
116 155
156 void Finish() {
157 finished_ = true;
158 }
159
160 void RestartIfNecessary() {
161 if (started_) {
162 if (finished_) {
163 started_ = false;
164 } else {
165 SendStartMessage();
166 }
167 }
168 }
169
170 LocalDomainResolver::IPAddressCallback callback() { return callback_; }
171
117 private: 172 private:
173 void SendStartMessage() {
174 host_->Send(new LocalDiscoveryMsg_ResolveLocalDomain(id_, domain_,
175 address_family_));
176 }
177
118 scoped_refptr<ServiceDiscoveryHostClient> host_; 178 scoped_refptr<ServiceDiscoveryHostClient> host_;
119 std::string domain_; 179 std::string domain_;
120 net::AddressFamily address_family_; 180 net::AddressFamily address_family_;
121 const uint64 id_; 181 const uint64 id_;
122 bool started_; 182 bool started_;
183 bool finished_;
184 LocalDomainResolver::IPAddressCallback callback_;
123 }; 185 };
124 186
125 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) { 187 ServiceDiscoveryHostClient::ServiceDiscoveryHostClient() : current_id_(0) {
126 callback_runner_ = base::MessageLoop::current()->message_loop_proxy(); 188 callback_runner_ = base::MessageLoop::current()->message_loop_proxy();
127 } 189 }
128 190
129 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() { 191 ServiceDiscoveryHostClient::~ServiceDiscoveryHostClient() {
130 // The ServiceDiscoveryHostClient may be destroyed from the IO thread or the 192 // The ServiceDiscoveryHostClient may be destroyed from the IO thread or the
131 // owning thread. 193 // owning thread.
132 DetachFromThread(); 194 DetachFromThread();
133 DCHECK(service_watcher_callbacks_.empty()); 195 DCHECK(service_watcher_proxies_.empty());
134 DCHECK(service_resolver_callbacks_.empty()); 196 DCHECK(service_resolver_proxies_.empty());
135 DCHECK(domain_resolver_callbacks_.empty()); 197 DCHECK(domain_resolver_proxies_.empty());
136 } 198 }
137 199
138 scoped_ptr<ServiceWatcher> ServiceDiscoveryHostClient::CreateServiceWatcher( 200 scoped_ptr<ServiceWatcher> ServiceDiscoveryHostClient::CreateServiceWatcher(
139 const std::string& service_type, 201 const std::string& service_type,
140 const ServiceWatcher::UpdatedCallback& callback) { 202 const ServiceWatcher::UpdatedCallback& callback) {
141 DCHECK(CalledOnValidThread()); 203 DCHECK(CalledOnValidThread());
142 return scoped_ptr<ServiceWatcher>( 204 return scoped_ptr<ServiceWatcher>(
143 new ServiceWatcherProxy(this, service_type, callback)); 205 new ServiceWatcherProxy(this, service_type, callback));
144 } 206 }
145 207
146 scoped_ptr<ServiceResolver> ServiceDiscoveryHostClient::CreateServiceResolver( 208 scoped_ptr<ServiceResolver> ServiceDiscoveryHostClient::CreateServiceResolver(
147 const std::string& service_name, 209 const std::string& service_name,
148 const ServiceResolver::ResolveCompleteCallback& callback) { 210 const ServiceResolver::ResolveCompleteCallback& callback) {
149 DCHECK(CalledOnValidThread()); 211 DCHECK(CalledOnValidThread());
150 return scoped_ptr<ServiceResolver>( 212 return scoped_ptr<ServiceResolver>(
151 new ServiceResolverProxy(this, service_name, callback)); 213 new ServiceResolverProxy(this, service_name, callback));
152 } 214 }
153 215
154 scoped_ptr<LocalDomainResolver> 216 scoped_ptr<LocalDomainResolver>
155 ServiceDiscoveryHostClient::CreateLocalDomainResolver( 217 ServiceDiscoveryHostClient::CreateLocalDomainResolver(
156 const std::string& domain, 218 const std::string& domain,
157 net::AddressFamily address_family, 219 net::AddressFamily address_family,
158 const LocalDomainResolver::IPAddressCallback& callback) { 220 const LocalDomainResolver::IPAddressCallback& callback) {
159 DCHECK(CalledOnValidThread()); 221 DCHECK(CalledOnValidThread());
160 return scoped_ptr<LocalDomainResolver>(new LocalDomainResolverProxy( 222 return scoped_ptr<LocalDomainResolver>(new LocalDomainResolverProxy(
161 this, domain, address_family, callback)); 223 this, domain, address_family, callback));
162 } 224 }
163 225
164 uint64 ServiceDiscoveryHostClient::RegisterWatcherCallback( 226 uint64 ServiceDiscoveryHostClient::RegisterWatcherProxy(
165 const ServiceWatcher::UpdatedCallback& callback) { 227 ServiceWatcherProxy* proxy) {
166 DCHECK(CalledOnValidThread()); 228 DCHECK(CalledOnValidThread());
167 DCHECK(!ContainsKey(service_watcher_callbacks_, current_id_ + 1)); 229 DCHECK(!ContainsKey(service_watcher_proxies_, current_id_ + 1));
168 service_watcher_callbacks_[++current_id_] = callback; 230 service_watcher_proxies_[++current_id_] = proxy;
169 return current_id_; 231 return current_id_;
170 } 232 }
171 233
172 uint64 ServiceDiscoveryHostClient::RegisterResolverCallback( 234 uint64 ServiceDiscoveryHostClient::RegisterResolverProxy(
173 const ServiceResolver::ResolveCompleteCallback& callback) { 235 ServiceResolverProxy* proxy) {
174 DCHECK(CalledOnValidThread()); 236 DCHECK(CalledOnValidThread());
175 DCHECK(!ContainsKey(service_resolver_callbacks_, current_id_ + 1)); 237 DCHECK(!ContainsKey(service_resolver_proxies_, current_id_ + 1));
176 service_resolver_callbacks_[++current_id_] = callback; 238 service_resolver_proxies_[++current_id_] = proxy;
177 return current_id_; 239 return current_id_;
178 } 240 }
179 241
180 uint64 ServiceDiscoveryHostClient::RegisterLocalDomainResolverCallback( 242 uint64 ServiceDiscoveryHostClient::RegisterLocalDomainResolverProxy(
181 const LocalDomainResolver::IPAddressCallback& callback) { 243 LocalDomainResolverProxy* proxy) {
182 DCHECK(CalledOnValidThread()); 244 DCHECK(CalledOnValidThread());
183 DCHECK(!ContainsKey(domain_resolver_callbacks_, current_id_ + 1)); 245 DCHECK(!ContainsKey(domain_resolver_proxies_, current_id_ + 1));
184 domain_resolver_callbacks_[++current_id_] = callback; 246 domain_resolver_proxies_[++current_id_] = proxy;
185 return current_id_; 247 return current_id_;
186 } 248 }
187 249
188 void ServiceDiscoveryHostClient::UnregisterWatcherCallback(uint64 id) { 250 void ServiceDiscoveryHostClient::UnregisterWatcherProxy(uint64 id) {
189 DCHECK(CalledOnValidThread()); 251 DCHECK(CalledOnValidThread());
190 DCHECK(ContainsKey(service_watcher_callbacks_, id)); 252 DCHECK(ContainsKey(service_watcher_proxies_, id));
191 service_watcher_callbacks_.erase(id); 253 service_watcher_proxies_.erase(id);
192 } 254 }
193 255
194 void ServiceDiscoveryHostClient::UnregisterResolverCallback(uint64 id) { 256 void ServiceDiscoveryHostClient::UnregisterResolverProxy(uint64 id) {
195 DCHECK(CalledOnValidThread()); 257 DCHECK(CalledOnValidThread());
196 DCHECK(ContainsKey(service_resolver_callbacks_, id)); 258 DCHECK(ContainsKey(service_resolver_proxies_, id));
197 service_resolver_callbacks_.erase(id); 259 service_resolver_proxies_.erase(id);
198 } 260 }
199 261
200 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback( 262 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverProxy(
201 uint64 id) { 263 uint64 id) {
202 DCHECK(CalledOnValidThread()); 264 DCHECK(CalledOnValidThread());
203 DCHECK(ContainsKey(domain_resolver_callbacks_, id)); 265 DCHECK(ContainsKey(domain_resolver_proxies_, id));
204 domain_resolver_callbacks_.erase(id); 266 domain_resolver_proxies_.erase(id);
205 } 267 }
206 268
207 void ServiceDiscoveryHostClient::Start() { 269 void ServiceDiscoveryHostClient::Start() {
208 DCHECK(CalledOnValidThread()); 270 DCHECK(CalledOnValidThread());
271 net::NetworkChangeNotifier::AddIPAddressObserver(this);
209 BrowserThread::PostTask( 272 BrowserThread::PostTask(
210 BrowserThread::IO, 273 BrowserThread::IO,
211 FROM_HERE, 274 FROM_HERE,
212 base::Bind(&ServiceDiscoveryHostClient::StartOnIOThread, this)); 275 base::Bind(&ServiceDiscoveryHostClient::StartOnIOThread, this));
213 } 276 }
214 277
215 void ServiceDiscoveryHostClient::Shutdown() { 278 void ServiceDiscoveryHostClient::Shutdown() {
216 DCHECK(CalledOnValidThread()); 279 DCHECK(CalledOnValidThread());
280 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
217 BrowserThread::PostTask( 281 BrowserThread::PostTask(
218 BrowserThread::IO, 282 BrowserThread::IO,
219 FROM_HERE, 283 FROM_HERE,
220 base::Bind(&ServiceDiscoveryHostClient::ShutdownOnIOThread, this)); 284 base::Bind(&ServiceDiscoveryHostClient::ShutdownOnIOThread, this));
221 } 285 }
222 286
223 void ServiceDiscoveryHostClient::StartOnIOThread() { 287 void ServiceDiscoveryHostClient::StartOnIOThread() {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
225 utility_host_ = UtilityProcessHost::Create( 289 utility_host_ = UtilityProcessHost::Create(
226 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 290 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
227 if (utility_host_) { 291 if (utility_host_) {
228 utility_host_->EnableZygote(); 292 utility_host_->EnableZygote();
229 utility_host_->EnableMDns(); 293 utility_host_->EnableMDns();
230 utility_host_->StartBatchMode(); 294 utility_host_->StartBatchMode();
231 } 295 }
232 } 296 }
233 297
234 void ServiceDiscoveryHostClient::ShutdownOnIOThread() { 298 void ServiceDiscoveryHostClient::ShutdownOnIOThread() {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
236 if (utility_host_) { 300 if (utility_host_) {
237 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery); 301 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery);
238 utility_host_->EndBatchMode(); 302 utility_host_->EndBatchMode();
239 } 303 }
240 } 304 }
241 305
306 void ServiceDiscoveryHostClient::RestartOnIOThread() {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
308
309 ShutdownOnIOThread();
310 StartOnIOThread();
311 }
312
242 void ServiceDiscoveryHostClient::Send(IPC::Message* msg) { 313 void ServiceDiscoveryHostClient::Send(IPC::Message* msg) {
243 DCHECK(CalledOnValidThread()); 314 DCHECK(CalledOnValidThread());
244 BrowserThread::PostTask( 315 BrowserThread::PostTask(
245 BrowserThread::IO, 316 BrowserThread::IO,
246 FROM_HERE, 317 FROM_HERE,
247 base::Bind(&ServiceDiscoveryHostClient::SendOnIOThread, this, msg)); 318 base::Bind(&ServiceDiscoveryHostClient::SendOnIOThread, this, msg));
248 } 319 }
249 320
250 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) { 321 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
252 if (utility_host_) 323 if (utility_host_)
253 utility_host_->Send(msg); 324 utility_host_->Send(msg);
254 } 325 }
255 326
327 void ServiceDiscoveryHostClient::OnIPAddressChanged() {
328 BrowserThread::PostTask(
329 BrowserThread::IO,
330 FROM_HERE,
331 base::Bind(&ServiceDiscoveryHostClient::RestartOnIOThread, this));
332
333 for (WatcherProxies::iterator i = service_watcher_proxies_.begin();
334 i != service_watcher_proxies_.end();
335 i++) {
336 i->second->RestartIfNecessary();
337 }
338
339 for (ResolverProxies::iterator i = service_resolver_proxies_.begin();
340 i != service_resolver_proxies_.end();
341 i++) {
342 i->second->RestartIfNecessary();
343 }
344
345 for (ResolverProxies::iterator i = service_resolver_proxies_.begin();
346 i != service_resolver_proxies_.end();
347 i++) {
348 i->second->RestartIfNecessary();
349 }
350 }
351
256 bool ServiceDiscoveryHostClient::OnMessageReceived( 352 bool ServiceDiscoveryHostClient::OnMessageReceived(
257 const IPC::Message& message) { 353 const IPC::Message& message) {
258 bool handled = true; 354 bool handled = true;
259 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message) 355 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message)
260 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_WatcherCallback, 356 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_WatcherCallback,
261 OnWatcherCallback) 357 OnWatcherCallback)
262 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_ResolverCallback, 358 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_ResolverCallback,
263 OnResolverCallback) 359 OnResolverCallback)
264 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_LocalDomainResolverCallback, 360 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_LocalDomainResolverCallback,
265 OnLocalDomainResolverCallback) 361 OnLocalDomainResolverCallback)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 FROM_HERE, 396 FROM_HERE,
301 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback, 397 base::Bind(&ServiceDiscoveryHostClient::RunLocalDomainResolverCallback,
302 this, id, success, ip_address_ipv4, ip_address_ipv6)); 398 this, id, success, ip_address_ipv4, ip_address_ipv6));
303 } 399 }
304 400
305 void ServiceDiscoveryHostClient::RunWatcherCallback( 401 void ServiceDiscoveryHostClient::RunWatcherCallback(
306 uint64 id, 402 uint64 id,
307 ServiceWatcher::UpdateType update, 403 ServiceWatcher::UpdateType update,
308 const std::string& service_name) { 404 const std::string& service_name) {
309 DCHECK(CalledOnValidThread()); 405 DCHECK(CalledOnValidThread());
310 WatcherCallbacks::iterator it = service_watcher_callbacks_.find(id); 406 WatcherProxies::iterator it = service_watcher_proxies_.find(id);
311 if (it != service_watcher_callbacks_.end() && !it->second.is_null()) 407 if (it != service_watcher_proxies_.end() && !it->second->callback().is_null())
312 it->second.Run(update, service_name); 408 it->second->callback().Run(update, service_name);
313 } 409 }
314 410
315 void ServiceDiscoveryHostClient::RunResolverCallback( 411 void ServiceDiscoveryHostClient::RunResolverCallback(
316 uint64 id, 412 uint64 id,
317 ServiceResolver::RequestStatus status, 413 ServiceResolver::RequestStatus status,
318 const ServiceDescription& description) { 414 const ServiceDescription& description) {
319 DCHECK(CalledOnValidThread()); 415 DCHECK(CalledOnValidThread());
320 ResolverCallbacks::iterator it = service_resolver_callbacks_.find(id); 416 ResolverProxies::iterator it = service_resolver_proxies_.find(id);
321 if (it != service_resolver_callbacks_.end() && !it->second.is_null()) 417 if (it != service_resolver_proxies_.end()
322 it->second.Run(status, description); 418 && !it->second->callback().is_null())
419 it->second->callback().Run(status, description);
323 } 420 }
324 421
325 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback( 422 void ServiceDiscoveryHostClient::RunLocalDomainResolverCallback(
326 uint64 id, 423 uint64 id,
327 bool success, 424 bool success,
328 const net::IPAddressNumber& ip_address_ipv4, 425 const net::IPAddressNumber& ip_address_ipv4,
329 const net::IPAddressNumber& ip_address_ipv6) { 426 const net::IPAddressNumber& ip_address_ipv6) {
330 DCHECK(CalledOnValidThread()); 427 DCHECK(CalledOnValidThread());
331 DomainResolverCallbacks::iterator it = domain_resolver_callbacks_.find(id); 428 DomainResolverProxies::iterator it = domain_resolver_proxies_.find(id);
332 if (it != domain_resolver_callbacks_.end() && !it->second.is_null()) 429 if (it != domain_resolver_proxies_.end()
333 it->second.Run(success, ip_address_ipv4, ip_address_ipv6); 430 && !it->second->callback().is_null())
431 it->second->callback().Run(success, ip_address_ipv4, ip_address_ipv6);
334 } 432 }
335 433
336 ServiceDiscoveryHostClientFactory::ServiceDiscoveryHostClientFactory() 434 ServiceDiscoveryHostClientFactory::ServiceDiscoveryHostClientFactory()
337 : instance_(NULL), references_(0) { 435 : instance_(NULL), references_(0) {
338 } 436 }
339 437
340 ServiceDiscoveryHostClientFactory::~ServiceDiscoveryHostClientFactory() { 438 ServiceDiscoveryHostClientFactory::~ServiceDiscoveryHostClientFactory() {
341 } 439 }
342 440
343 // static 441 // static
(...skipping 27 matching lines...) Expand all
371 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() { 469 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() {
372 DCHECK(CalledOnValidThread()); 470 DCHECK(CalledOnValidThread());
373 references_--; 471 references_--;
374 if (references_ == 0) { 472 if (references_ == 0) {
375 instance_->Shutdown(); 473 instance_->Shutdown();
376 instance_ = NULL; 474 instance_ = NULL;
377 } 475 }
378 } 476 }
379 477
380 } // namespace local_discovery 478 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698