| OLD | NEW |
| 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_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 if (!g_network_change_notifier) { | 548 if (!g_network_change_notifier) { |
| 549 *connection_type = CONNECTION_UNKNOWN; | 549 *connection_type = CONNECTION_UNKNOWN; |
| 550 *max_bandwidth_mbps = GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); | 550 *max_bandwidth_mbps = GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); |
| 551 } | 551 } |
| 552 | 552 |
| 553 g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType( | 553 g_network_change_notifier->GetCurrentMaxBandwidthAndConnectionType( |
| 554 max_bandwidth_mbps, connection_type); | 554 max_bandwidth_mbps, connection_type); |
| 555 } | 555 } |
| 556 | 556 |
| 557 // static | 557 // static |
| 558 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( |
| 559 ConnectionSubtype subtype) { |
| 560 switch (subtype) { |
| 561 case SUBTYPE_GSM: |
| 562 return 0.01; |
| 563 case SUBTYPE_IDEN: |
| 564 return 0.064; |
| 565 case SUBTYPE_CDMA: |
| 566 return 0.115; |
| 567 case SUBTYPE_1XRTT: |
| 568 return 0.153; |
| 569 case SUBTYPE_GPRS: |
| 570 return 0.237; |
| 571 case SUBTYPE_EDGE: |
| 572 return 0.384; |
| 573 case SUBTYPE_UMTS: |
| 574 return 2.0; |
| 575 case SUBTYPE_EVDO_REV_0: |
| 576 return 2.46; |
| 577 case SUBTYPE_EVDO_REV_A: |
| 578 return 3.1; |
| 579 case SUBTYPE_HSPA: |
| 580 return 3.6; |
| 581 case SUBTYPE_EVDO_REV_B: |
| 582 return 14.7; |
| 583 case SUBTYPE_HSDPA: |
| 584 return 14.3; |
| 585 case SUBTYPE_HSUPA: |
| 586 return 14.4; |
| 587 case SUBTYPE_EHRPD: |
| 588 return 21.0; |
| 589 case SUBTYPE_HSPAP: |
| 590 return 42.0; |
| 591 case SUBTYPE_LTE: |
| 592 return 100.0; |
| 593 case SUBTYPE_LTE_ADVANCED: |
| 594 return 100.0; |
| 595 case SUBTYPE_BLUETOOTH_1_2: |
| 596 return 1.0; |
| 597 case SUBTYPE_BLUETOOTH_2_1: |
| 598 return 3.0; |
| 599 case SUBTYPE_BLUETOOTH_3_0: |
| 600 return 24.0; |
| 601 case SUBTYPE_BLUETOOTH_4_0: |
| 602 return 1.0; |
| 603 case SUBTYPE_ETHERNET: |
| 604 return 10.0; |
| 605 case SUBTYPE_FAST_ETHERNET: |
| 606 return 100.0; |
| 607 case SUBTYPE_GIGABIT_ETHERNET: |
| 608 return 1000.0; |
| 609 case SUBTYPE_10_GIGABIT_ETHERNET: |
| 610 return 10000.0; |
| 611 case SUBTYPE_WIFI_B: |
| 612 return 11.0; |
| 613 case SUBTYPE_WIFI_G: |
| 614 return 54.0; |
| 615 case SUBTYPE_WIFI_N: |
| 616 return 600.0; |
| 617 case SUBTYPE_WIFI_AC: |
| 618 return 1300.0; |
| 619 case SUBTYPE_WIFI_AD: |
| 620 return 7000.0; |
| 621 case SUBTYPE_UNKNOWN: |
| 622 return std::numeric_limits<double>::infinity(); |
| 623 case SUBTYPE_NONE: |
| 624 return 0.0; |
| 625 case SUBTYPE_OTHER: |
| 626 return std::numeric_limits<double>::infinity(); |
| 627 } |
| 628 NOTREACHED(); |
| 629 return std::numeric_limits<double>::infinity(); |
| 630 } |
| 631 |
| 632 // static |
| 558 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { | 633 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { |
| 559 if (!g_network_change_notifier) { | 634 if (!g_network_change_notifier) { |
| 560 *config = DnsConfig(); | 635 *config = DnsConfig(); |
| 561 } else { | 636 } else { |
| 562 g_network_change_notifier->network_state_->GetDnsConfig(config); | 637 g_network_change_notifier->network_state_->GetDnsConfig(config); |
| 563 } | 638 } |
| 564 } | 639 } |
| 565 | 640 |
| 566 // static | 641 // static |
| 567 const char* NetworkChangeNotifier::ConnectionTypeToString( | 642 const char* NetworkChangeNotifier::ConnectionTypeToString( |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 // should be overridden to provide specific bandwidth data based on the | 927 // should be overridden to provide specific bandwidth data based on the |
| 853 // platform. | 928 // platform. |
| 854 *connection_type = GetCurrentConnectionType(); | 929 *connection_type = GetCurrentConnectionType(); |
| 855 *max_bandwidth_mbps = | 930 *max_bandwidth_mbps = |
| 856 *connection_type == CONNECTION_NONE | 931 *connection_type == CONNECTION_NONE |
| 857 ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE) | 932 ? GetMaxBandwidthForConnectionSubtype(SUBTYPE_NONE) |
| 858 : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); | 933 : GetMaxBandwidthForConnectionSubtype(SUBTYPE_UNKNOWN); |
| 859 } | 934 } |
| 860 | 935 |
| 861 // static | 936 // static |
| 862 double NetworkChangeNotifier::GetMaxBandwidthForConnectionSubtype( | |
| 863 ConnectionSubtype subtype) { | |
| 864 switch (subtype) { | |
| 865 case SUBTYPE_GSM: | |
| 866 return 0.01; | |
| 867 case SUBTYPE_IDEN: | |
| 868 return 0.064; | |
| 869 case SUBTYPE_CDMA: | |
| 870 return 0.115; | |
| 871 case SUBTYPE_1XRTT: | |
| 872 return 0.153; | |
| 873 case SUBTYPE_GPRS: | |
| 874 return 0.237; | |
| 875 case SUBTYPE_EDGE: | |
| 876 return 0.384; | |
| 877 case SUBTYPE_UMTS: | |
| 878 return 2.0; | |
| 879 case SUBTYPE_EVDO_REV_0: | |
| 880 return 2.46; | |
| 881 case SUBTYPE_EVDO_REV_A: | |
| 882 return 3.1; | |
| 883 case SUBTYPE_HSPA: | |
| 884 return 3.6; | |
| 885 case SUBTYPE_EVDO_REV_B: | |
| 886 return 14.7; | |
| 887 case SUBTYPE_HSDPA: | |
| 888 return 14.3; | |
| 889 case SUBTYPE_HSUPA: | |
| 890 return 14.4; | |
| 891 case SUBTYPE_EHRPD: | |
| 892 return 21.0; | |
| 893 case SUBTYPE_HSPAP: | |
| 894 return 42.0; | |
| 895 case SUBTYPE_LTE: | |
| 896 return 100.0; | |
| 897 case SUBTYPE_LTE_ADVANCED: | |
| 898 return 100.0; | |
| 899 case SUBTYPE_BLUETOOTH_1_2: | |
| 900 return 1.0; | |
| 901 case SUBTYPE_BLUETOOTH_2_1: | |
| 902 return 3.0; | |
| 903 case SUBTYPE_BLUETOOTH_3_0: | |
| 904 return 24.0; | |
| 905 case SUBTYPE_BLUETOOTH_4_0: | |
| 906 return 1.0; | |
| 907 case SUBTYPE_ETHERNET: | |
| 908 return 10.0; | |
| 909 case SUBTYPE_FAST_ETHERNET: | |
| 910 return 100.0; | |
| 911 case SUBTYPE_GIGABIT_ETHERNET: | |
| 912 return 1000.0; | |
| 913 case SUBTYPE_10_GIGABIT_ETHERNET: | |
| 914 return 10000.0; | |
| 915 case SUBTYPE_WIFI_B: | |
| 916 return 11.0; | |
| 917 case SUBTYPE_WIFI_G: | |
| 918 return 54.0; | |
| 919 case SUBTYPE_WIFI_N: | |
| 920 return 600.0; | |
| 921 case SUBTYPE_WIFI_AC: | |
| 922 return 1300.0; | |
| 923 case SUBTYPE_WIFI_AD: | |
| 924 return 7000.0; | |
| 925 case SUBTYPE_UNKNOWN: | |
| 926 return std::numeric_limits<double>::infinity(); | |
| 927 case SUBTYPE_NONE: | |
| 928 return 0.0; | |
| 929 case SUBTYPE_OTHER: | |
| 930 return std::numeric_limits<double>::infinity(); | |
| 931 } | |
| 932 NOTREACHED(); | |
| 933 return std::numeric_limits<double>::infinity(); | |
| 934 } | |
| 935 | |
| 936 // static | |
| 937 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { | 937 void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { |
| 938 if (g_network_change_notifier && | 938 if (g_network_change_notifier && |
| 939 !NetworkChangeNotifier::test_notifications_only_) { | 939 !NetworkChangeNotifier::test_notifications_only_) { |
| 940 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl(); | 940 g_network_change_notifier->NotifyObserversOfIPAddressChangeImpl(); |
| 941 } | 941 } |
| 942 } | 942 } |
| 943 | 943 |
| 944 // static | 944 // static |
| 945 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { | 945 void NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange() { |
| 946 if (g_network_change_notifier && | 946 if (g_network_change_notifier && |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 | 1050 |
| 1051 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 1051 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
| 1052 DCHECK(!g_network_change_notifier); | 1052 DCHECK(!g_network_change_notifier); |
| 1053 g_network_change_notifier = network_change_notifier_; | 1053 g_network_change_notifier = network_change_notifier_; |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { | 1056 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 } // namespace net | 1059 } // namespace net |
| OLD | NEW |