| 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 "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
| 6 | 6 |
| 7 #include <dbus/dbus-glib.h> | 7 #include <dbus/dbus-glib.h> |
| 8 | 8 |
| 9 #include "base/i18n/icu_encoding_detection.h" | 9 #include "base/i18n/icu_encoding_detection.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| 11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/json/json_writer.h" // for debug output only. | 12 #include "base/json/json_writer.h" // for debug output only. |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_tokenizer.h" | 14 #include "base/string_tokenizer.h" |
| 15 #include "base/utf_string_conversion_utils.h" | 15 #include "base/utf_string_conversion_utils.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/chromeos/cros/certificate_pattern.h" | 17 #include "chrome/browser/chromeos/cros/certificate_pattern.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 19 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 20 #include "chrome/browser/chromeos/cros/native_network_parser.h" | 20 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
| 21 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" | 21 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" |
| 22 #include "chrome/browser/chromeos/cros/network_library_impl_stub.h" | 22 #include "chrome/browser/chromeos/cros/network_library_impl_stub.h" |
| 23 #include "chrome/browser/net/browser_url_util.h" | 23 #include "chrome/browser/net/browser_url_util.h" |
| 24 #include "chrome/common/time_format.h" | |
| 25 #include "chrome/common/net/x509_certificate_model.h" | 24 #include "chrome/common/net/x509_certificate_model.h" |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 27 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 28 #include "third_party/cros_system_api/dbus/service_constants.h" | 27 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/text/bytes_formatting.h" | |
| 31 | 29 |
| 32 using content::BrowserThread; | 30 using content::BrowserThread; |
| 33 | 31 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 35 // Implementation notes. | 33 // Implementation notes. |
| 36 // NetworkLibraryImpl manages a series of classes that describe network devices | 34 // NetworkLibraryImpl manages a series of classes that describe network devices |
| 37 // and services: | 35 // and services: |
| 38 // | 36 // |
| 39 // NetworkDevice: e.g. ethernet, wifi modem, cellular modem | 37 // NetworkDevice: e.g. ethernet, wifi modem, cellular modem |
| 40 // device_map_: canonical map<path, NetworkDevice*> for devices | 38 // device_map_: canonical map<path, NetworkDevice*> for devices |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 return; | 738 return; |
| 741 } | 739 } |
| 742 } | 740 } |
| 743 connect.Run(); | 741 connect.Run(); |
| 744 } | 742 } |
| 745 | 743 |
| 746 //////////////////////////////////////////////////////////////////////////////// | 744 //////////////////////////////////////////////////////////////////////////////// |
| 747 // WirelessNetwork | 745 // WirelessNetwork |
| 748 | 746 |
| 749 //////////////////////////////////////////////////////////////////////////////// | 747 //////////////////////////////////////////////////////////////////////////////// |
| 750 // CellularDataPlan | |
| 751 | |
| 752 CellularDataPlan::CellularDataPlan() | |
| 753 : plan_name("Unknown"), | |
| 754 plan_type(CELLULAR_DATA_PLAN_UNLIMITED), | |
| 755 plan_data_bytes(0), | |
| 756 data_bytes_used(0) { | |
| 757 } | |
| 758 | |
| 759 CellularDataPlan::CellularDataPlan(const CellularDataPlanInfo &plan) | |
| 760 : plan_name(plan.plan_name ? plan.plan_name : ""), | |
| 761 plan_type(plan.plan_type), | |
| 762 update_time(base::Time::FromInternalValue(plan.update_time)), | |
| 763 plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)), | |
| 764 plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)), | |
| 765 plan_data_bytes(plan.plan_data_bytes), | |
| 766 data_bytes_used(plan.data_bytes_used) { | |
| 767 } | |
| 768 | |
| 769 CellularDataPlan::~CellularDataPlan() {} | |
| 770 | |
| 771 string16 CellularDataPlan::GetPlanDesciption() const { | |
| 772 switch (plan_type) { | |
| 773 case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: { | |
| 774 return l10n_util::GetStringFUTF16( | |
| 775 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_UNLIMITED_DATA, | |
| 776 base::TimeFormatFriendlyDate(plan_start_time)); | |
| 777 break; | |
| 778 } | |
| 779 case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: { | |
| 780 return l10n_util::GetStringFUTF16( | |
| 781 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_DATA, | |
| 782 ui::FormatBytes(plan_data_bytes), | |
| 783 base::TimeFormatFriendlyDate(plan_start_time)); | |
| 784 } | |
| 785 case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: { | |
| 786 return l10n_util::GetStringFUTF16( | |
| 787 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA, | |
| 788 ui::FormatBytes(plan_data_bytes), | |
| 789 base::TimeFormatFriendlyDate(plan_start_time)); | |
| 790 default: | |
| 791 break; | |
| 792 } | |
| 793 } | |
| 794 return string16(); | |
| 795 } | |
| 796 | |
| 797 string16 CellularDataPlan::GetRemainingWarning() const { | |
| 798 if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { | |
| 799 // Time based plan. Show nearing expiration and data expiration. | |
| 800 if (remaining_time().InSeconds() <= chromeos::kCellularDataVeryLowSecs) { | |
| 801 return GetPlanExpiration(); | |
| 802 } | |
| 803 } else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || | |
| 804 plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { | |
| 805 // Metered plan. Show low data and out of data. | |
| 806 if (remaining_data() <= chromeos::kCellularDataVeryLowBytes) { | |
| 807 int64 remaining_mbytes = remaining_data() / (1024 * 1024); | |
| 808 return l10n_util::GetStringFUTF16( | |
| 809 IDS_NETWORK_DATA_REMAINING_MESSAGE, | |
| 810 UTF8ToUTF16(base::Int64ToString(remaining_mbytes))); | |
| 811 } | |
| 812 } | |
| 813 return string16(); | |
| 814 } | |
| 815 | |
| 816 string16 CellularDataPlan::GetDataRemainingDesciption() const { | |
| 817 int64 remaining_bytes = remaining_data(); | |
| 818 switch (plan_type) { | |
| 819 case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: { | |
| 820 return l10n_util::GetStringUTF16( | |
| 821 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_UNLIMITED); | |
| 822 } | |
| 823 case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: { | |
| 824 return ui::FormatBytes(remaining_bytes); | |
| 825 } | |
| 826 case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: { | |
| 827 return ui::FormatBytes(remaining_bytes); | |
| 828 } | |
| 829 default: | |
| 830 break; | |
| 831 } | |
| 832 return string16(); | |
| 833 } | |
| 834 | |
| 835 string16 CellularDataPlan::GetUsageInfo() const { | |
| 836 if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { | |
| 837 // Time based plan. Show nearing expiration and data expiration. | |
| 838 return GetPlanExpiration(); | |
| 839 } else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || | |
| 840 plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { | |
| 841 // Metered plan. Show low data and out of data. | |
| 842 int64 remaining_bytes = remaining_data(); | |
| 843 if (remaining_bytes == 0) { | |
| 844 return l10n_util::GetStringUTF16( | |
| 845 IDS_NETWORK_DATA_NONE_AVAILABLE_MESSAGE); | |
| 846 } else if (remaining_bytes < 1024 * 1024) { | |
| 847 return l10n_util::GetStringUTF16( | |
| 848 IDS_NETWORK_DATA_LESS_THAN_ONE_MB_AVAILABLE_MESSAGE); | |
| 849 } else { | |
| 850 int64 remaining_mb = remaining_bytes / (1024 * 1024); | |
| 851 return l10n_util::GetStringFUTF16( | |
| 852 IDS_NETWORK_DATA_MB_AVAILABLE_MESSAGE, | |
| 853 UTF8ToUTF16(base::Int64ToString(remaining_mb))); | |
| 854 } | |
| 855 } | |
| 856 return string16(); | |
| 857 } | |
| 858 | |
| 859 std::string CellularDataPlan::GetUniqueIdentifier() const { | |
| 860 // A cellular plan is uniquely described by the union of name, type, | |
| 861 // start time, end time, and max bytes. | |
| 862 // So we just return a union of all these variables. | |
| 863 return plan_name + "|" + | |
| 864 base::Int64ToString(plan_type) + "|" + | |
| 865 base::Int64ToString(plan_start_time.ToInternalValue()) + "|" + | |
| 866 base::Int64ToString(plan_end_time.ToInternalValue()) + "|" + | |
| 867 base::Int64ToString(plan_data_bytes); | |
| 868 } | |
| 869 | |
| 870 base::TimeDelta CellularDataPlan::remaining_time() const { | |
| 871 base::TimeDelta time = plan_end_time - base::Time::Now(); | |
| 872 return time.InMicroseconds() < 0 ? base::TimeDelta() : time; | |
| 873 } | |
| 874 | |
| 875 int64 CellularDataPlan::remaining_minutes() const { | |
| 876 return remaining_time().InMinutes(); | |
| 877 } | |
| 878 | |
| 879 int64 CellularDataPlan::remaining_data() const { | |
| 880 int64 data = plan_data_bytes - data_bytes_used; | |
| 881 return data < 0 ? 0 : data; | |
| 882 } | |
| 883 | |
| 884 string16 CellularDataPlan::GetPlanExpiration() const { | |
| 885 return TimeFormat::TimeRemaining(remaining_time()); | |
| 886 } | |
| 887 | |
| 888 //////////////////////////////////////////////////////////////////////////////// | |
| 889 // CellTower | 748 // CellTower |
| 890 | 749 |
| 891 CellTower::CellTower() {} | 750 CellTower::CellTower() {} |
| 892 | 751 |
| 893 //////////////////////////////////////////////////////////////////////////////// | 752 //////////////////////////////////////////////////////////////////////////////// |
| 894 // WifiAccessPoint | 753 // WifiAccessPoint |
| 895 | 754 |
| 896 WifiAccessPoint::WifiAccessPoint() {} | 755 WifiAccessPoint::WifiAccessPoint() {} |
| 897 | 756 |
| 898 //////////////////////////////////////////////////////////////////////////////// | 757 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 NetworkLibrary* impl; | 1332 NetworkLibrary* impl; |
| 1474 if (stub) | 1333 if (stub) |
| 1475 impl = new NetworkLibraryImplStub(); | 1334 impl = new NetworkLibraryImplStub(); |
| 1476 else | 1335 else |
| 1477 impl = new NetworkLibraryImplCros(); | 1336 impl = new NetworkLibraryImplCros(); |
| 1478 impl->Init(); | 1337 impl->Init(); |
| 1479 return impl; | 1338 return impl; |
| 1480 } | 1339 } |
| 1481 | 1340 |
| 1482 } // namespace chromeos | 1341 } // namespace chromeos |
| OLD | NEW |