| 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 "jingle/glue/fake_network_manager.h" | 5 #include "jingle/glue/fake_network_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| 10 #include "jingle/glue/utils.h" | 11 #include "jingle/glue/utils.h" |
| 11 #include "third_party/libjingle/source/talk/base/socketaddress.h" | 12 #include "third_party/libjingle/source/talk/base/socketaddress.h" |
| 12 | 13 |
| 13 namespace jingle_glue { | 14 namespace jingle_glue { |
| 14 | 15 |
| 15 FakeNetworkManager::FakeNetworkManager(const net::IPAddressNumber& address) | 16 FakeNetworkManager::FakeNetworkManager(const net::IPAddressNumber& address) |
| 16 : started_(false), | 17 : started_(false), |
| 17 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 18 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 18 net::IPEndPoint endpoint(address, 0); | 19 net::IPEndPoint endpoint(address, 0); |
| 19 talk_base::SocketAddress socket_address; | 20 talk_base::SocketAddress socket_address; |
| 20 CHECK(IPEndPointToSocketAddress(endpoint, &socket_address)); | 21 CHECK(IPEndPointToSocketAddress(endpoint, &socket_address)); |
| 21 network_.reset(new talk_base::Network("fake", "Fake Network", | 22 network_.reset(new talk_base::Network("fake", "Fake Network", |
| 22 socket_address.ip(), 0)); | 23 socket_address.ip(), 0)); |
| 23 } | 24 } |
| 24 | 25 |
| 25 FakeNetworkManager::~FakeNetworkManager() { | 26 FakeNetworkManager::~FakeNetworkManager() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 void FakeNetworkManager::StartUpdating() { | 29 void FakeNetworkManager::StartUpdating() { |
| 29 started_ = true; | 30 started_ = true; |
| 30 MessageLoop::current()->PostTask( | 31 MessageLoop::current()->PostTask( |
| 31 FROM_HERE,task_factory_.NewRunnableMethod( | 32 FROM_HERE, base::Bind(&FakeNetworkManager::SendNetworksChangedSignal, |
| 32 &FakeNetworkManager::SendNetworksChangedSignal)); | 33 weak_factory_.GetWeakPtr())); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void FakeNetworkManager::StopUpdating() { | 36 void FakeNetworkManager::StopUpdating() { |
| 36 started_ = false; | 37 started_ = false; |
| 37 } | 38 } |
| 38 | 39 |
| 39 void FakeNetworkManager::GetNetworks(NetworkList* networks) const { | 40 void FakeNetworkManager::GetNetworks(NetworkList* networks) const { |
| 40 networks->clear(); | 41 networks->clear(); |
| 41 networks->push_back(network_.get()); | 42 networks->push_back(network_.get()); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void FakeNetworkManager::SendNetworksChangedSignal() { | 45 void FakeNetworkManager::SendNetworksChangedSignal() { |
| 45 SignalNetworksChanged(); | 46 SignalNetworksChanged(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace jingle_glue | 49 } // namespace jingle_glue |
| OLD | NEW |