| 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/utility/local_discovery/service_discovery_message_handler.h" | 5 #include "chrome/utility/local_discovery/service_discovery_message_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "chrome/common/local_discovery/local_discovery_messages.h" | 10 #include "chrome/common/local_discovery/local_discovery_messages.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 VLOG(1) << "Failed to start MDnsClient"; | 190 VLOG(1) << "Failed to start MDnsClient"; |
| 191 Send(new LocalDiscoveryHostMsg_Error()); | 191 Send(new LocalDiscoveryHostMsg_Error()); |
| 192 return; | 192 return; |
| 193 } | 193 } |
| 194 | 194 |
| 195 service_discovery_client_.reset( | 195 service_discovery_client_.reset( |
| 196 new local_discovery::ServiceDiscoveryClientImpl(mdns_client_.get())); | 196 new local_discovery::ServiceDiscoveryClientImpl(mdns_client_.get())); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool ServiceDiscoveryMessageHandler::InitializeThread() { | 199 bool ServiceDiscoveryMessageHandler::InitializeThread() { |
| 200 if (discovery_task_runner_) | 200 if (discovery_task_runner_.get()) |
| 201 return true; | 201 return true; |
| 202 if (discovery_thread_) | 202 if (discovery_thread_) |
| 203 return false; | 203 return false; |
| 204 utility_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); | 204 utility_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); |
| 205 discovery_thread_.reset(new base::Thread("ServiceDiscoveryThread")); | 205 discovery_thread_.reset(new base::Thread("ServiceDiscoveryThread")); |
| 206 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 206 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 207 if (discovery_thread_->StartWithOptions(thread_options)) { | 207 if (discovery_thread_->StartWithOptions(thread_options)) { |
| 208 discovery_task_runner_ = discovery_thread_->message_loop_proxy(); | 208 discovery_task_runner_ = discovery_thread_->message_loop_proxy(); |
| 209 discovery_task_runner_->PostTask(FROM_HERE, | 209 discovery_task_runner_->PostTask(FROM_HERE, |
| 210 base::Bind(&ServiceDiscoveryMessageHandler::InitializeMdns, | 210 base::Bind(&ServiceDiscoveryMessageHandler::InitializeMdns, |
| 211 base::Unretained(this))); | 211 base::Unretained(this))); |
| 212 } | 212 } |
| 213 return discovery_task_runner_ != NULL; | 213 return discovery_task_runner_.get() != NULL; |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool ServiceDiscoveryMessageHandler::OnMessageReceived( | 216 bool ServiceDiscoveryMessageHandler::OnMessageReceived( |
| 217 const IPC::Message& message) { | 217 const IPC::Message& message) { |
| 218 bool handled = true; | 218 bool handled = true; |
| 219 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryMessageHandler, message) | 219 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryMessageHandler, message) |
| 220 #if defined(OS_POSIX) | 220 #if defined(OS_POSIX) |
| 221 IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_SetSockets, OnSetSockets) | 221 IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_SetSockets, OnSetSockets) |
| 222 #endif // OS_POSIX | 222 #endif // OS_POSIX |
| 223 IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_StartWatcher, OnStartWatcher) | 223 IPC_MESSAGE_HANDLER(LocalDiscoveryMsg_StartWatcher, OnStartWatcher) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 398 } |
| 399 | 399 |
| 400 void ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver(uint64 id) { | 400 void ServiceDiscoveryMessageHandler::DestroyLocalDomainResolver(uint64 id) { |
| 401 VLOG(1) << "DestroyLocalDomainResolver, id=" << id; | 401 VLOG(1) << "DestroyLocalDomainResolver, id=" << id; |
| 402 if (!service_discovery_client_) | 402 if (!service_discovery_client_) |
| 403 return; | 403 return; |
| 404 local_domain_resolvers_.erase(id); | 404 local_domain_resolvers_.erase(id); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void ServiceDiscoveryMessageHandler::ShutdownLocalDiscovery() { | 407 void ServiceDiscoveryMessageHandler::ShutdownLocalDiscovery() { |
| 408 if (!discovery_task_runner_) | 408 if (!discovery_task_runner_.get()) |
| 409 return; | 409 return; |
| 410 | 410 |
| 411 discovery_task_runner_->PostTask( | 411 discovery_task_runner_->PostTask( |
| 412 FROM_HERE, | 412 FROM_HERE, |
| 413 base::Bind(&ServiceDiscoveryMessageHandler::ShutdownOnIOThread, | 413 base::Bind(&ServiceDiscoveryMessageHandler::ShutdownOnIOThread, |
| 414 base::Unretained(this))); | 414 base::Unretained(this))); |
| 415 | 415 |
| 416 // This will wait for message loop to drain, so ShutdownOnIOThread will | 416 // This will wait for message loop to drain, so ShutdownOnIOThread will |
| 417 // definitely be called. | 417 // definitely be called. |
| 418 discovery_thread_.reset(); | 418 discovery_thread_.reset(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 id, success, address_ipv4, address_ipv6)); | 466 id, success, address_ipv4, address_ipv6)); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { | 469 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { |
| 470 utility_task_runner_->PostTask(FROM_HERE, | 470 utility_task_runner_->PostTask(FROM_HERE, |
| 471 base::Bind(&SendHostMessageOnUtilityThread, | 471 base::Bind(&SendHostMessageOnUtilityThread, |
| 472 msg)); | 472 msg)); |
| 473 } | 473 } |
| 474 | 474 |
| 475 } // namespace local_discovery | 475 } // namespace local_discovery |
| OLD | NEW |