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" | 10 #include "base/location.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 uint32 interface_index; | 65 uint32 interface_index; |
66 }; | 66 }; |
67 | 67 |
68 // Returns list of sockets preallocated before. | 68 // Returns list of sockets preallocated before. |
69 class PreCreatedMDnsSocketFactory : public net::MDnsSocketFactory { | 69 class PreCreatedMDnsSocketFactory : public net::MDnsSocketFactory { |
70 public: | 70 public: |
71 PreCreatedMDnsSocketFactory() {} | 71 PreCreatedMDnsSocketFactory() {} |
72 ~PreCreatedMDnsSocketFactory() override { | 72 ~PreCreatedMDnsSocketFactory() override { |
73 // Not empty if process exits too fast, before starting mDns code. If | 73 // Not empty if process exits too fast, before starting mDns code. If |
74 // happened, destructors may crash accessing destroyed global objects. | 74 // happened, destructors may crash accessing destroyed global objects. |
75 sockets_.weak_clear(); | 75 // TODO This sounds memory leak, check and do better if possible |
76 for (scoped_ptr<net::DatagramServerSocket>& it : sockets_) { | |
77 base::IgnoreResult(it.release()); | |
78 } | |
79 sockets_.clear(); | |
76 } | 80 } |
77 | 81 |
78 // net::MDnsSocketFactory implementation: | 82 // net::MDnsSocketFactory implementation: |
79 void CreateSockets( | 83 void CreateSockets( |
80 ScopedVector<net::DatagramServerSocket>* sockets) override { | 84 std::vector<scoped_ptr<net::DatagramServerSocket>>* sockets) override { |
mmenke
2015/11/24 17:39:33
include vector / scoped_ptr (At least in net, we g
| |
81 sockets->swap(sockets_); | 85 sockets->swap(sockets_); |
82 Reset(); | 86 Reset(); |
83 } | 87 } |
84 | 88 |
85 void AddSocket(const SocketInfo& socket_info) { | 89 void AddSocket(const SocketInfo& socket_info) { |
86 // Takes ownership of socket_info.socket; | 90 // Takes ownership of socket_info.socket; |
87 ScopedSocketFactory platform_factory(socket_info.socket); | 91 ScopedSocketFactory platform_factory(socket_info.socket); |
88 scoped_ptr<net::DatagramServerSocket> socket( | 92 scoped_ptr<net::DatagramServerSocket> socket( |
89 net::CreateAndBindMDnsSocket(socket_info.address_family, | 93 net::CreateAndBindMDnsSocket(socket_info.address_family, |
90 socket_info.interface_index)); | 94 socket_info.interface_index)); |
91 if (socket) { | 95 if (socket) { |
92 socket->DetachFromThread(); | 96 socket->DetachFromThread(); |
93 sockets_.push_back(socket.release()); | 97 sockets_.push_back(std::move(socket)); |
94 } | 98 } |
95 } | 99 } |
96 | 100 |
97 void Reset() { | 101 void Reset() { |
98 sockets_.clear(); | 102 sockets_.clear(); |
99 } | 103 } |
100 | 104 |
101 private: | 105 private: |
102 ScopedVector<net::DatagramServerSocket> sockets_; | 106 std::vector<scoped_ptr<net::DatagramServerSocket>> sockets_; |
103 | 107 |
104 DISALLOW_COPY_AND_ASSIGN(PreCreatedMDnsSocketFactory); | 108 DISALLOW_COPY_AND_ASSIGN(PreCreatedMDnsSocketFactory); |
105 }; | 109 }; |
106 | 110 |
107 base::LazyInstance<PreCreatedMDnsSocketFactory> | 111 base::LazyInstance<PreCreatedMDnsSocketFactory> |
108 g_local_discovery_socket_factory = LAZY_INSTANCE_INITIALIZER; | 112 g_local_discovery_socket_factory = LAZY_INSTANCE_INITIALIZER; |
109 | 113 |
110 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
111 | 115 |
112 void ClosePlatformSocket(net::SocketDescriptor socket) { | 116 void ClosePlatformSocket(net::SocketDescriptor socket) { |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 id, success, address_ipv4, address_ipv6)); | 474 id, success, address_ipv4, address_ipv6)); |
471 } | 475 } |
472 | 476 |
473 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { | 477 void ServiceDiscoveryMessageHandler::Send(IPC::Message* msg) { |
474 utility_task_runner_->PostTask(FROM_HERE, | 478 utility_task_runner_->PostTask(FROM_HERE, |
475 base::Bind(&SendHostMessageOnUtilityThread, | 479 base::Bind(&SendHostMessageOnUtilityThread, |
476 msg)); | 480 msg)); |
477 } | 481 } |
478 | 482 |
479 } // namespace local_discovery | 483 } // namespace local_discovery |
OLD | NEW |