Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: webrtc/base/networkmonitor.cc

Issue 1556743002: Bind a socket to a network if the network handle is set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a compiling issue for Windows Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/networkmonitor.h" 11 #include "webrtc/base/networkmonitor.h"
12 12
13 #include "webrtc/base/common.h" 13 #include "webrtc/base/common.h"
14 14
15 namespace { 15 namespace {
16 const uint32_t UPDATE_NETWORKS_MESSAGE = 1; 16 const uint32_t UPDATE_NETWORKS_MESSAGE = 1;
17 17
18 // This is set by NetworkMonitorFactory::SetFactory and the caller of 18 // This is set by NetworkMonitorFactory::SetFactory and the caller of
19 // NetworkMonitorFactory::SetFactory must be responsible for calling 19 // NetworkMonitorFactory::SetFactory must be responsible for calling
20 // ReleaseFactory to destroy the factory. 20 // ReleaseFactory to destroy the factory.
21 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; 21 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
22 } // namespace 22 } // namespace
23 23
24 namespace rtc { 24 namespace rtc {
25 NetworkMonitorInterface::NetworkMonitorInterface() {} 25 NetworkMonitorInterface::NetworkMonitorInterface() {}
26 26
27 NetworkMonitorInterface::~NetworkMonitorInterface() {} 27 NetworkMonitorInterface::~NetworkMonitorInterface() {}
28 28
29 NetworkMonitorBase::NetworkMonitorBase() : thread_(Thread::Current()) {} 29 NetworkMonitorBase::NetworkMonitorBase() : thread_(nullptr) {}
30 NetworkMonitorBase::~NetworkMonitorBase() {} 30 NetworkMonitorBase::~NetworkMonitorBase() {}
31 31
32 void NetworkMonitorBase::Start() {
pthatcher1 2016/01/14 20:07:24 Should we check to make sure Start() isn't called
honghaiz3 2016/01/15 01:00:38 Removed this change.
33 if (thread_ == nullptr) {
34 thread_ = Thread::Current();
35 }
36 }
32 void NetworkMonitorBase::OnNetworksChanged() { 37 void NetworkMonitorBase::OnNetworksChanged() {
33 LOG(LS_VERBOSE) << "Network change is received at the network monitor"; 38 LOG(LS_VERBOSE) << "Network change is received at the network monitor";
39 ASSERT(thread_ != nullptr);
34 thread_->Post(this, UPDATE_NETWORKS_MESSAGE); 40 thread_->Post(this, UPDATE_NETWORKS_MESSAGE);
35 } 41 }
36 42
37 void NetworkMonitorBase::OnMessage(Message* msg) { 43 void NetworkMonitorBase::OnMessage(Message* msg) {
38 ASSERT(msg->message_id == UPDATE_NETWORKS_MESSAGE); 44 ASSERT(msg->message_id == UPDATE_NETWORKS_MESSAGE);
39 SignalNetworksChanged(); 45 SignalNetworksChanged();
40 } 46 }
41 47
42 NetworkMonitorFactory::NetworkMonitorFactory() {} 48 NetworkMonitorFactory::NetworkMonitorFactory() {}
43 NetworkMonitorFactory::~NetworkMonitorFactory() {} 49 NetworkMonitorFactory::~NetworkMonitorFactory() {}
44 50
45 void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) { 51 void NetworkMonitorFactory::SetFactory(NetworkMonitorFactory* factory) {
46 if (network_monitor_factory != nullptr) { 52 if (network_monitor_factory != nullptr) {
47 delete network_monitor_factory; 53 delete network_monitor_factory;
48 } 54 }
49 network_monitor_factory = factory; 55 network_monitor_factory = factory;
50 } 56 }
51 57
52 void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) { 58 void NetworkMonitorFactory::ReleaseFactory(NetworkMonitorFactory* factory) {
53 if (factory == network_monitor_factory) { 59 if (factory == network_monitor_factory) {
54 SetFactory(nullptr); 60 SetFactory(nullptr);
55 } 61 }
56 } 62 }
57 63
58 NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() { 64 NetworkMonitorFactory* NetworkMonitorFactory::GetFactory() {
59 return network_monitor_factory; 65 return network_monitor_factory;
60 } 66 }
61 67
62 } // namespace rtc 68 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698