| 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 17 matching lines...) Expand all Loading... |
| 28 net::PlatformSocketFactory::SetInstance(this); | 28 net::PlatformSocketFactory::SetInstance(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual ~ScopedSocketFactory() { | 31 virtual ~ScopedSocketFactory() { |
| 32 net::PlatformSocketFactory::SetInstance(NULL); | 32 net::PlatformSocketFactory::SetInstance(NULL); |
| 33 ClosePlatformSocket(socket_); | 33 ClosePlatformSocket(socket_); |
| 34 socket_ = net::kInvalidSocket; | 34 socket_ = net::kInvalidSocket; |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual net::SocketDescriptor CreateSocket(int family, int type, | 37 virtual net::SocketDescriptor CreateSocket(int family, int type, |
| 38 int protocol) OVERRIDE { | 38 int protocol) override { |
| 39 DCHECK_EQ(type, SOCK_DGRAM); | 39 DCHECK_EQ(type, SOCK_DGRAM); |
| 40 DCHECK(family == AF_INET || family == AF_INET6); | 40 DCHECK(family == AF_INET || family == AF_INET6); |
| 41 net::SocketDescriptor result = net::kInvalidSocket; | 41 net::SocketDescriptor result = net::kInvalidSocket; |
| 42 std::swap(result, socket_); | 42 std::swap(result, socket_); |
| 43 return result; | 43 return result; |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 net::SocketDescriptor socket_; | 47 net::SocketDescriptor socket_; |
| 48 DISALLOW_COPY_AND_ASSIGN(ScopedSocketFactory); | 48 DISALLOW_COPY_AND_ASSIGN(ScopedSocketFactory); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 public: | 66 public: |
| 67 PreCreatedMDnsSocketFactory() {} | 67 PreCreatedMDnsSocketFactory() {} |
| 68 virtual ~PreCreatedMDnsSocketFactory() { | 68 virtual ~PreCreatedMDnsSocketFactory() { |
| 69 // Not empty if process exits too fast, before starting mDns code. If | 69 // Not empty if process exits too fast, before starting mDns code. If |
| 70 // happened, destructors may crash accessing destroyed global objects. | 70 // happened, destructors may crash accessing destroyed global objects. |
| 71 sockets_.weak_clear(); | 71 sockets_.weak_clear(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // net::MDnsSocketFactory implementation: | 74 // net::MDnsSocketFactory implementation: |
| 75 virtual void CreateSockets( | 75 virtual void CreateSockets( |
| 76 ScopedVector<net::DatagramServerSocket>* sockets) OVERRIDE { | 76 ScopedVector<net::DatagramServerSocket>* sockets) override { |
| 77 sockets->swap(sockets_); | 77 sockets->swap(sockets_); |
| 78 Reset(); | 78 Reset(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void AddSocket(const SocketInfo& socket_info) { | 81 void AddSocket(const SocketInfo& socket_info) { |
| 82 // Takes ownership of socket_info.socket; | 82 // Takes ownership of socket_info.socket; |
| 83 ScopedSocketFactory platform_factory(socket_info.socket); | 83 ScopedSocketFactory platform_factory(socket_info.socket); |
| 84 scoped_ptr<net::DatagramServerSocket> socket( | 84 scoped_ptr<net::DatagramServerSocket> socket( |
| 85 net::CreateAndBindMDnsSocket(socket_info.address_family, | 85 net::CreateAndBindMDnsSocket(socket_info.address_family, |
| 86 socket_info.interface_index)); | 86 socket_info.interface_index)); |
| (...skipping 379 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 |