| 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 "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 10 #include "chrome/common/local_discovery/local_discovery_messages.h" | 12 #include "chrome/common/local_discovery/local_discovery_messages.h" |
| 11 #include "chrome/common/local_discovery/service_discovery_client_impl.h" | 13 #include "chrome/common/local_discovery/service_discovery_client_impl.h" |
| 12 #include "content/public/utility/utility_thread.h" | 14 #include "content/public/utility/utility_thread.h" |
| 13 #include "net/socket/socket_descriptor.h" | 15 #include "net/socket/socket_descriptor.h" |
| 14 #include "net/udp/datagram_server_socket.h" | 16 #include "net/udp/datagram_server_socket.h" |
| 15 | 17 |
| 16 namespace local_discovery { | 18 namespace local_discovery { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 197 |
| 196 service_discovery_client_.reset( | 198 service_discovery_client_.reset( |
| 197 new local_discovery::ServiceDiscoveryClientImpl(mdns_client_.get())); | 199 new local_discovery::ServiceDiscoveryClientImpl(mdns_client_.get())); |
| 198 } | 200 } |
| 199 | 201 |
| 200 bool ServiceDiscoveryMessageHandler::InitializeThread() { | 202 bool ServiceDiscoveryMessageHandler::InitializeThread() { |
| 201 if (discovery_task_runner_.get()) | 203 if (discovery_task_runner_.get()) |
| 202 return true; | 204 return true; |
| 203 if (discovery_thread_) | 205 if (discovery_thread_) |
| 204 return false; | 206 return false; |
| 205 utility_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); | 207 utility_task_runner_ = base::MessageLoop::current()->task_runner(); |
| 206 discovery_thread_.reset(new base::Thread("ServiceDiscoveryThread")); | 208 discovery_thread_.reset(new base::Thread("ServiceDiscoveryThread")); |
| 207 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 209 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 208 if (discovery_thread_->StartWithOptions(thread_options)) { | 210 if (discovery_thread_->StartWithOptions(thread_options)) { |
| 209 discovery_task_runner_ = discovery_thread_->message_loop_proxy(); | 211 discovery_task_runner_ = discovery_thread_->task_runner(); |
| 210 discovery_task_runner_->PostTask(FROM_HERE, | 212 discovery_task_runner_->PostTask(FROM_HERE, |
| 211 base::Bind(&ServiceDiscoveryMessageHandler::InitializeMdns, | 213 base::Bind(&ServiceDiscoveryMessageHandler::InitializeMdns, |
| 212 base::Unretained(this))); | 214 base::Unretained(this))); |
| 213 } | 215 } |
| 214 return discovery_task_runner_.get() != NULL; | 216 return discovery_task_runner_.get() != NULL; |
| 215 } | 217 } |
| 216 | 218 |
| 217 bool ServiceDiscoveryMessageHandler::OnMessageReceived( | 219 bool ServiceDiscoveryMessageHandler::OnMessageReceived( |
| 218 const IPC::Message& message) { | 220 const IPC::Message& message) { |
| 219 bool handled = true; | 221 bool handled = true; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 id, success, address_ipv4, address_ipv6)); | 469 id, success, address_ipv4, address_ipv6)); |
| 468 } | 470 } |
| 469 | 471 |
| 470 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { | 472 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { |
| 471 utility_task_runner_->PostTask(FROM_HERE, | 473 utility_task_runner_->PostTask(FROM_HERE, |
| 472 base::Bind(&SendHostMessageOnUtilityThread, | 474 base::Bind(&SendHostMessageOnUtilityThread, |
| 473 msg)); | 475 msg)); |
| 474 } | 476 } |
| 475 | 477 |
| 476 } // namespace local_discovery | 478 } // namespace local_discovery |
| OLD | NEW |