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

Side by Side Diff: net/base/network_change_notifier.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « net/base/network_change_notifier.h ('k') | net/base/upload_bytes_element_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/network_change_notifier.h" 5 #include "net/base/network_change_notifier.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 fastest_RTT_since_last_connection_change_ = request_duration; 298 fastest_RTT_since_last_connection_change_ = request_duration;
299 } 299 }
300 bytes_read_since_last_connection_change_ += bytes_read; 300 bytes_read_since_last_connection_change_ += bytes_read;
301 if (request_duration < fastest_RTT_since_last_connection_change_) 301 if (request_duration < fastest_RTT_since_last_connection_change_)
302 fastest_RTT_since_last_connection_change_ = request_duration; 302 fastest_RTT_since_last_connection_change_ = request_duration;
303 // Ignore tiny transfers which will not produce accurate rates. 303 // Ignore tiny transfers which will not produce accurate rates.
304 // Ignore zero duration transfers which might cause divide by zero. 304 // Ignore zero duration transfers which might cause divide by zero.
305 if (bytes_read > 10000 && 305 if (bytes_read > 10000 &&
306 request_duration > base::TimeDelta::FromMilliseconds(1) && 306 request_duration > base::TimeDelta::FromMilliseconds(1) &&
307 request.creation_time() > last_connection_change_) { 307 request.creation_time() > last_connection_change_) {
308 int32 kbps = bytes_read * 8 / request_duration.InMilliseconds(); 308 int32 kbps = static_cast<int32>(
309 bytes_read * 8 / request_duration.InMilliseconds());
309 if (kbps > peak_kbps_since_last_connection_change_) 310 if (kbps > peak_kbps_since_last_connection_change_)
310 peak_kbps_since_last_connection_change_ = kbps; 311 peak_kbps_since_last_connection_change_ = kbps;
311 } 312 }
312 313
313 if (last_connection_type_ != NetworkChangeNotifier::CONNECTION_NONE) 314 if (last_connection_type_ != NetworkChangeNotifier::CONNECTION_NONE)
314 return; 315 return;
315 316
316 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv", 317 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv",
317 now - last_connection_change_); 318 now - last_connection_change_);
318 offline_packets_received_++; 319 offline_packets_received_++;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 double NetworkChangeNotifier::GetCurrentMaxBandwidth() const { 778 double NetworkChangeNotifier::GetCurrentMaxBandwidth() const {
778 // This default implementation conforms to the NetInfo V3 specification but 779 // This default implementation conforms to the NetInfo V3 specification but
779 // should be overridden to provide specific bandwidth data based on the 780 // should be overridden to provide specific bandwidth data based on the
780 // platform. 781 // platform.
781 if (GetCurrentConnectionType() == CONNECTION_NONE) 782 if (GetCurrentConnectionType() == CONNECTION_NONE)
782 return 0.0; 783 return 0.0;
783 return std::numeric_limits<double>::infinity(); 784 return std::numeric_limits<double>::infinity();
784 } 785 }
785 786
786 // static 787 // static
788 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype(
789 ConnectionSubtype subtype) {
790 switch (subtype) {
791 case SUBTYPE_GSM:
792 return 0.01;
793 case SUBTYPE_IDEN:
794 return 0.064;
795 case SUBTYPE_CDMA:
796 return 0.115;
797 case SUBTYPE_1XRTT:
798 return 0.153;
799 case SUBTYPE_GPRS:
800 return 0.237;
801 case SUBTYPE_EDGE:
802 return 0.384;
803 case SUBTYPE_UMTS:
804 return 2.0;
805 case SUBTYPE_EVDO_REV_0:
806 return 2.46;
807 case SUBTYPE_EVDO_REV_A:
808 return 3.1;
809 case SUBTYPE_HSPA:
810 return 3.6;
811 case SUBTYPE_EVDO_REV_B:
812 return 14.7;
813 case SUBTYPE_HSDPA:
814 return 14.3;
815 case SUBTYPE_HSUPA:
816 return 14.4;
817 case SUBTYPE_EHRPD:
818 return 21.0;
819 case SUBTYPE_HSPAP:
820 return 42.0;
821 case SUBTYPE_LTE:
822 return 100.0;
823 case SUBTYPE_LTE_ADVANCED:
824 return 100.0;
825 case SUBTYPE_BLUETOOTH_1_2:
826 return 1.0;
827 case SUBTYPE_BLUETOOTH_2_1:
828 return 3.0;
829 case SUBTYPE_BLUETOOTH_3_0:
830 return 24.0;
831 case SUBTYPE_BLUETOOTH_4_0:
832 return 1.0;
833 case SUBTYPE_ETHERNET:
834 return 10.0;
835 case SUBTYPE_FAST_ETHERNET:
836 return 100.0;
837 case SUBTYPE_GIGABIT_ETHERNET:
838 return 1000.0;
839 case SUBTYPE_10_GIGABIT_ETHERNET:
840 return 10000.0;
841 case SUBTYPE_WIFI_B:
842 return 11.0;
843 case SUBTYPE_WIFI_G:
844 return 54.0;
845 case SUBTYPE_WIFI_N:
846 return 600.0;
847 case SUBTYPE_WIFI_AC:
848 return 1300.0;
849 case SUBTYPE_WIFI_AD:
850 return 7000.0;
851 case SUBTYPE_UNKNOWN:
852 return std::numeric_limits<double>::infinity();
853 case SUBTYPE_NONE:
854 return 0.0;
855 case SUBTYPE_OTHER:
856 return std::numeric_limits<double>::infinity();
857 }
858 NOTREACHED();
859 return std::numeric_limits<double>::infinity();
860 }
861
862 // static
787 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { 863 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() {
788 if (g_network_change_notifier && 864 if (g_network_change_notifier &&
789 !g_network_change_notifier->test_notifications_only_) { 865 !g_network_change_notifier->test_notifications_only_) {
790 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl(); 866 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl();
791 } 867 }
792 } 868 }
793 869
794 // static 870 // static
795 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { 871 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() {
796 if (g_network_change_notifier && 872 if (g_network_change_notifier &&
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 DCHECK(g_network_change_notifier); 926 DCHECK(g_network_change_notifier);
851 g_network_change_notifier = NULL; 927 g_network_change_notifier = NULL;
852 } 928 }
853 929
854 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 930 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
855 DCHECK(!g_network_change_notifier); 931 DCHECK(!g_network_change_notifier);
856 g_network_change_notifier = network_change_notifier_; 932 g_network_change_notifier = network_change_notifier_;
857 } 933 }
858 934
859 } // namespace net 935 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_change_notifier.h ('k') | net/base/upload_bytes_element_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698