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

Side by Side Diff: webrtc/base/network.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: Merge with head 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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 364 }
365 return false; 365 return false;
366 } 366 }
367 367
368 BasicNetworkManager::BasicNetworkManager() 368 BasicNetworkManager::BasicNetworkManager()
369 : thread_(NULL), sent_first_update_(false), start_count_(0), 369 : thread_(NULL), sent_first_update_(false), start_count_(0),
370 ignore_non_default_routes_(false) { 370 ignore_non_default_routes_(false) {
371 } 371 }
372 372
373 BasicNetworkManager::~BasicNetworkManager() { 373 BasicNetworkManager::~BasicNetworkManager() {
374 if (thread_ && network_monitor_ &&
375 thread_->socketserver()->network_binder() == network_monitor_.get()) {
376 // In case that network binder is still being used by the socket server
377 // after it is released here.
378 thread_->socketserver()->set_network_binder(nullptr);
379 }
374 } 380 }
375 381
376 void BasicNetworkManager::OnNetworksChanged() { 382 void BasicNetworkManager::OnNetworksChanged() {
377 LOG(LS_VERBOSE) << "Network change was observed at the network manager"; 383 LOG(LS_VERBOSE) << "Network change was observed at the network manager";
378 UpdateNetworksOnce(); 384 UpdateNetworksOnce();
379 } 385 }
380 386
381 #if defined(__native_client__) 387 #if defined(__native_client__)
382 388
383 bool BasicNetworkManager::CreateNetworks(bool include_ignored, 389 bool BasicNetworkManager::CreateNetworks(bool include_ignored,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 sent_first_update_ = false; 730 sent_first_update_ = false;
725 StopNetworkMonitor(); 731 StopNetworkMonitor();
726 } 732 }
727 } 733 }
728 734
729 void BasicNetworkManager::StartNetworkMonitor() { 735 void BasicNetworkManager::StartNetworkMonitor() {
730 NetworkMonitorFactory* factory = NetworkMonitorFactory::GetFactory(); 736 NetworkMonitorFactory* factory = NetworkMonitorFactory::GetFactory();
731 if (factory == nullptr) { 737 if (factory == nullptr) {
732 return; 738 return;
733 } 739 }
734 network_monitor_.reset(factory->CreateNetworkMonitor());
735 if (!network_monitor_) { 740 if (!network_monitor_) {
736 return; 741 network_monitor_.reset(factory->CreateNetworkMonitor());
742 ASSERT(network_monitor_);
743 ASSERT(thread_ && thread_->socketserver());
744 thread_->socketserver()->set_network_binder(network_monitor_.get());
737 } 745 }
746
738 network_monitor_->SignalNetworksChanged.connect( 747 network_monitor_->SignalNetworksChanged.connect(
739 this, &BasicNetworkManager::OnNetworksChanged); 748 this, &BasicNetworkManager::OnNetworksChanged);
740 network_monitor_->Start(); 749 network_monitor_->Start();
741 } 750 }
742 751
743 void BasicNetworkManager::StopNetworkMonitor() { 752 void BasicNetworkManager::StopNetworkMonitor() {
744 if (!network_monitor_) { 753 if (!network_monitor_) {
745 return; 754 return;
746 } 755 }
747 network_monitor_->Stop(); 756 network_monitor_->Stop();
748 network_monitor_.reset();
749 } 757 }
750 758
751 void BasicNetworkManager::OnMessage(Message* msg) { 759 void BasicNetworkManager::OnMessage(Message* msg) {
752 switch (msg->message_id) { 760 switch (msg->message_id) {
753 case kUpdateNetworksMessage: { 761 case kUpdateNetworksMessage: {
754 UpdateNetworksContinually(); 762 UpdateNetworksContinually();
755 break; 763 break;
756 } 764 }
757 case kSignalNetworksMessage: { 765 case kSignalNetworksMessage: {
758 SignalNetworksChanged(); 766 SignalNetworksChanged();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 std::stringstream ss; 920 std::stringstream ss;
913 // Print out the first space-terminated token of the network desc, plus 921 // Print out the first space-terminated token of the network desc, plus
914 // the IP address. 922 // the IP address.
915 ss << "Net[" << description_.substr(0, description_.find(' ')) 923 ss << "Net[" << description_.substr(0, description_.find(' '))
916 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_ 924 << ":" << prefix_.ToSensitiveString() << "/" << prefix_length_
917 << ":" << AdapterTypeToString(type_) << "]"; 925 << ":" << AdapterTypeToString(type_) << "]";
918 return ss.str(); 926 return ss.str();
919 } 927 }
920 928
921 } // namespace rtc 929 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698