OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/p2p/ipc_network_manager.h" | 5 #include "content/renderer/p2p/ipc_network_manager.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "net/base/net_util.h" | 8 #include "net/base/net_util.h" |
8 #include "net/base/sys_byteorder.h" | 9 #include "net/base/sys_byteorder.h" |
9 | 10 |
10 namespace content { | 11 namespace content { |
11 | 12 |
12 IpcNetworkManager::IpcNetworkManager(P2PSocketDispatcher* socket_dispatcher) | 13 IpcNetworkManager::IpcNetworkManager(P2PSocketDispatcher* socket_dispatcher) |
13 : socket_dispatcher_(socket_dispatcher), | 14 : socket_dispatcher_(socket_dispatcher), |
14 started_(false), | 15 started_(false), |
15 first_update_sent_(false), | 16 first_update_sent_(false), |
16 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 17 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
17 } | 18 } |
18 | 19 |
19 IpcNetworkManager::~IpcNetworkManager() { | 20 IpcNetworkManager::~IpcNetworkManager() { |
20 socket_dispatcher_->RemoveNetworkListObserver(this); | 21 socket_dispatcher_->RemoveNetworkListObserver(this); |
21 } | 22 } |
22 | 23 |
23 void IpcNetworkManager::StartUpdating() { | 24 void IpcNetworkManager::StartUpdating() { |
24 if (!started_) { | 25 if (!started_) { |
25 first_update_sent_ = false; | 26 first_update_sent_ = false; |
26 started_ = true; | 27 started_ = true; |
27 socket_dispatcher_->AddNetworkListObserver(this); | 28 socket_dispatcher_->AddNetworkListObserver(this); |
28 } else { | 29 } else { |
29 // Post a task to avoid reentrancy. | 30 // Post a task to avoid reentrancy. |
30 MessageLoop::current()->PostTask( | 31 MessageLoop::current()->PostTask( |
31 FROM_HERE,task_factory_.NewRunnableMethod( | 32 FROM_HERE, base::Bind(&IpcNetworkManager::SendNetworksChangedSignal, |
32 &IpcNetworkManager::SendNetworksChangedSignal)); | 33 weak_factory_.GetWeakPtr())); |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 void IpcNetworkManager::StopUpdating() { | 37 void IpcNetworkManager::StopUpdating() { |
37 started_ = false; | 38 started_ = false; |
38 socket_dispatcher_->RemoveNetworkListObserver(this); | 39 socket_dispatcher_->RemoveNetworkListObserver(this); |
39 } | 40 } |
40 | 41 |
41 void IpcNetworkManager::OnNetworkListChanged( | 42 void IpcNetworkManager::OnNetworkListChanged( |
42 const net::NetworkInterfaceList& list) { | 43 const net::NetworkInterfaceList& list) { |
(...skipping 14 matching lines...) Expand all Loading... |
57 | 58 |
58 MergeNetworkList(networks, !first_update_sent_); | 59 MergeNetworkList(networks, !first_update_sent_); |
59 first_update_sent_ = false; | 60 first_update_sent_ = false; |
60 } | 61 } |
61 | 62 |
62 void IpcNetworkManager::SendNetworksChangedSignal() { | 63 void IpcNetworkManager::SendNetworksChangedSignal() { |
63 SignalNetworksChanged(); | 64 SignalNetworksChanged(); |
64 } | 65 } |
65 | 66 |
66 } // namespace content | 67 } // namespace content |
OLD | NEW |