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 #include "chrome/browser/local_discovery/service_discovery_host_client.h" | 5 #include "chrome/browser/local_discovery/service_discovery_host_client.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
9 #endif // OS_POSIX | 9 #endif // OS_POSIX |
10 | 10 |
11 #include "chrome/common/local_discovery/local_discovery_messages.h" | 11 #include "chrome/common/local_discovery/local_discovery_messages.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/utility_process_host.h" | 13 #include "content/public/browser/utility_process_host.h" |
14 #include "net/socket/socket_descriptor.h" | 14 #include "net/socket/socket_descriptor.h" |
15 | 15 |
16 namespace local_discovery { | 16 namespace local_discovery { |
17 | 17 |
18 namespace { | |
19 | |
20 void LogInterfaces() { | |
21 net::NetworkInterfaceList list; | |
22 net::GetNetworkList(&list); | |
23 std::string log; | |
24 for (net::NetworkInterfaceList::iterator it = list.begin(); it != list.end(); | |
25 ++it) { | |
26 log += " " + net::IPAddressToString(it->address); | |
27 } | |
28 VLOG(1) << "Local addresses:" << log; | |
29 } | |
30 | |
31 } // namespace | |
32 | |
33 using content::BrowserThread; | 18 using content::BrowserThread; |
34 using content::UtilityProcessHost; | 19 using content::UtilityProcessHost; |
35 | 20 |
36 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher { | 21 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher { |
37 public: | 22 public: |
38 ServiceWatcherProxy(ServiceDiscoveryHostClient* host, | 23 ServiceWatcherProxy(ServiceDiscoveryHostClient* host, |
39 const std::string& service_type, | 24 const std::string& service_type, |
40 const ServiceWatcher::UpdatedCallback& callback) | 25 const ServiceWatcher::UpdatedCallback& callback) |
41 : host_(host), | 26 : host_(host), |
42 service_type_(service_type), | 27 service_type_(service_type), |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 if (utility_host_) { | 261 if (utility_host_) { |
277 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery); | 262 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery); |
278 utility_host_->EndBatchMode(); | 263 utility_host_->EndBatchMode(); |
279 } | 264 } |
280 } | 265 } |
281 | 266 |
282 void ServiceDiscoveryHostClient::Restart() { | 267 void ServiceDiscoveryHostClient::Restart() { |
283 DCHECK(CalledOnValidThread()); | 268 DCHECK(CalledOnValidThread()); |
284 | 269 |
285 VLOG(1) << "ServiceDiscoveryHostClient::Restart"; | 270 VLOG(1) << "ServiceDiscoveryHostClient::Restart"; |
286 LogInterfaces(); | |
287 | 271 |
288 io_runner_->PostTask( | 272 io_runner_->PostTask( |
289 FROM_HERE, | 273 FROM_HERE, |
290 base::Bind(&ServiceDiscoveryHostClient::RestartOnIOThread, this)); | 274 base::Bind(&ServiceDiscoveryHostClient::RestartOnIOThread, this)); |
291 | 275 |
292 WatcherCallbacks service_watcher_callbacks; | 276 WatcherCallbacks service_watcher_callbacks; |
293 service_watcher_callbacks_.swap(service_watcher_callbacks); | 277 service_watcher_callbacks_.swap(service_watcher_callbacks); |
294 | 278 |
295 for (WatcherCallbacks::iterator i = service_watcher_callbacks.begin(); | 279 for (WatcherCallbacks::iterator i = service_watcher_callbacks.begin(); |
296 i != service_watcher_callbacks.end(); i++) { | 280 i != service_watcher_callbacks.end(); i++) { |
(...skipping 19 matching lines...) Expand all Loading... |
316 | 300 |
317 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) { | 301 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) { |
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
319 if (utility_host_) | 303 if (utility_host_) |
320 utility_host_->Send(msg); | 304 utility_host_->Send(msg); |
321 } | 305 } |
322 | 306 |
323 void ServiceDiscoveryHostClient::OnNetworkChanged( | 307 void ServiceDiscoveryHostClient::OnNetworkChanged( |
324 net::NetworkChangeNotifier::ConnectionType type) { | 308 net::NetworkChangeNotifier::ConnectionType type) { |
325 VLOG(1) << "ServiceDiscoveryHostClient::OnNetworkChanged"; | 309 VLOG(1) << "ServiceDiscoveryHostClient::OnNetworkChanged"; |
326 LogInterfaces(); | |
327 callback_runner_->PostDelayedTask( | 310 callback_runner_->PostDelayedTask( |
328 FROM_HERE, | 311 FROM_HERE, |
329 base::Bind(&ServiceDiscoveryHostClient::Restart, this), | 312 base::Bind(&ServiceDiscoveryHostClient::Restart, this), |
330 base::TimeDelta::FromSeconds(10)); | 313 base::TimeDelta::FromSeconds(10)); |
331 } | 314 } |
332 | 315 |
333 bool ServiceDiscoveryHostClient::OnMessageReceived( | 316 bool ServiceDiscoveryHostClient::OnMessageReceived( |
334 const IPC::Message& message) { | 317 const IPC::Message& message) { |
335 bool handled = true; | 318 bool handled = true; |
336 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message) | 319 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() { | 431 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() { |
449 DCHECK(CalledOnValidThread()); | 432 DCHECK(CalledOnValidThread()); |
450 references_--; | 433 references_--; |
451 if (references_ == 0) { | 434 if (references_ == 0) { |
452 instance_->Shutdown(); | 435 instance_->Shutdown(); |
453 instance_ = NULL; | 436 instance_ = NULL; |
454 } | 437 } |
455 } | 438 } |
456 | 439 |
457 } // namespace local_discovery | 440 } // namespace local_discovery |
OLD | NEW |