diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-13 02:33:54 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-13 02:33:54 +0000 |
commit | f0053949ae0ead01a11ab32fbd61a4788f344e42 (patch) | |
tree | 51d0b63497e1b797455fd7ba9208ccabe7b4a083 /chrome/browser/chromeos/cros | |
parent | b8113a55465521d094d5c035e5d38b2e2237d014 (diff) | |
download | chromium_src-f0053949ae0ead01a11ab32fbd61a4788f344e42.zip chromium_src-f0053949ae0ead01a11ab32fbd61a4788f344e42.tar.gz chromium_src-f0053949ae0ead01a11ab32fbd61a4788f344e42.tar.bz2 |
Notification fix for case when there is no mobile plan. Fixed network menu to properly
redirect to partner payment portal when we run out of plan. Changed usage notification
to display "More info..." instead of "Buy plan".
BUG=chromium-os:8745, chromium-os:8724, chromium-os:8853, chromium-os:8685
TEST=see listed bugs for details
Review URL: http://codereview.chromium.org/4699004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/cros')
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.cc | 127 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.h | 19 |
2 files changed, 143 insertions, 3 deletions
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index 7e878dd..b983daa1 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -8,6 +8,7 @@ #include <map> #include "app/l10n_util.h" +#include "base/i18n/time_formatting.h" #include "base/stl_util-inl.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -15,6 +16,7 @@ #include "base/values.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/common/time_format.h" #include "grit/generated_resources.h" namespace { @@ -342,6 +344,124 @@ void WirelessNetwork::Clear() { favorite_ = false; } +//////////////////////////////////////////////////////////////////////////////// +// CellularDataPlan + +string16 CellularDataPlan::GetPlanDesciption() const { + switch (plan_type) { + case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: { + return l10n_util::GetStringFUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_UNLIMITED_DATA, + WideToUTF16(base::TimeFormatFriendlyDate(plan_start_time))); + break; + } + case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: { + return l10n_util::GetStringFUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_DATA, + FormatBytes(plan_data_bytes, + GetByteDisplayUnits(plan_data_bytes), + true), + WideToUTF16(base::TimeFormatFriendlyDate( + plan_start_time))); + } + case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: { + return l10n_util::GetStringFUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA, + FormatBytes(plan_data_bytes, + GetByteDisplayUnits(plan_data_bytes), + true), + WideToUTF16(base::TimeFormatFriendlyDate( + plan_start_time))); + default: + break; + } + } + return string16(); +} + +string16 CellularDataPlan::GetRemainingWarning() const { + if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { + // Time based plan. Show nearing expiration and data expiration. + int64 time_left = base::TimeDelta( + plan_end_time - update_time).InSeconds(); + if (time_left <= 0) { + return l10n_util::GetStringFUTF16( + IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")); + } else if (time_left <= chromeos::kCellularDataVeryLowSecs) { + return l10n_util::GetStringFUTF16( + IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, + UTF8ToUTF16(base::Int64ToString(time_left/60))); + } + } else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || + plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { + // Metered plan. Show low data and out of data. + int64 bytes_remaining = plan_data_bytes - data_bytes_used; + if (bytes_remaining <= 0) { + return l10n_util::GetStringFUTF16( + IDS_NETWORK_DATA_REMAINING_MESSAGE, ASCIIToUTF16("0")); + } else if (bytes_remaining <= chromeos::kCellularDataVeryLowBytes) { + return l10n_util::GetStringFUTF16( + IDS_NETWORK_DATA_REMAINING_MESSAGE, + UTF8ToUTF16(base::Int64ToString(bytes_remaining/(1024*1024)))); + } + } + return string16(); +} + +string16 CellularDataPlan::GetDataRemainingDesciption() const { + switch (plan_type) { + case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: { + return l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_UNLIMITED); + } + case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: { + return FormatBytes(plan_data_bytes - data_bytes_used, + GetByteDisplayUnits(plan_data_bytes - data_bytes_used), + true); + } + case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: { + return FormatBytes(plan_data_bytes - data_bytes_used, + GetByteDisplayUnits(plan_data_bytes - data_bytes_used), + true); + } + default: + break; + } + return string16(); +} + +string16 CellularDataPlan::GetUsageInfo() const { + if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { + // Time based plan. Show nearing expiration and data expiration. + int64 time_left = base::TimeDelta( + plan_end_time - update_time).InSeconds(); + return l10n_util::GetStringFUTF16( + IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, + UTF8ToUTF16(base::Int64ToString(time_left/60))); + } else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || + plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { + // Metered plan. Show low data and out of data. + int64 bytes_remaining = plan_data_bytes - data_bytes_used; + if (bytes_remaining <= 0) + bytes_remaining = 0; + return l10n_util::GetStringFUTF16( + IDS_NETWORK_DATA_AVAILABLE_MESSAGE, + UTF8ToUTF16(base::Int64ToString(bytes_remaining/(1024*1024)))); + } + return string16(); +} + +int64 CellularDataPlan::remaining_minutes() const { + return base::TimeDelta(plan_end_time - update_time).InMinutes(); +} + +int64 CellularDataPlan::remaining_mbytes() const { + return (plan_data_bytes - data_bytes_used) / (1024 * 1024); +} + +string16 CellularDataPlan::GetPlanExpiration() const { + return TimeFormat::TimeRemaining(plan_end_time - base::Time::Now()); +} //////////////////////////////////////////////////////////////////////////////// // CellularNetwork @@ -1424,6 +1544,8 @@ class NetworkLibraryImpl : public NetworkLibrary { std::string prev_cellular_service_path = cellular_ ? cellular_->service_path() : std::string(); + bool prev_cellular_connected = cellular_ ? + cellular_->connected() : false; ClearNetworks(); @@ -1442,8 +1564,9 @@ class NetworkLibraryImpl : public NetworkLibrary { if (cellular_networks_[i]->connecting_or_connected()) { cellular_ = cellular_networks_[i]; // If new cellular, then request update of the data plan list. - if (cellular_networks_[i]->service_path() != - prev_cellular_service_path) { + if ((cellular_networks_[i]->service_path() != + prev_cellular_service_path) || + (!prev_cellular_connected && cellular_networks_[i]->connected())) { RefreshCellularDataPlans(cellular_); } break; // There is only one connected or connecting cellular network. diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 8296660..714bc80 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -12,6 +12,7 @@ #include "base/observer_list.h" #include "base/platform_thread.h" #include "base/singleton.h" +#include "base/string16.h" #include "base/timer.h" #include "cros/chromeos_network.h" @@ -172,7 +173,19 @@ class CellularDataPlan { plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)), plan_data_bytes(plan.plan_data_bytes), data_bytes_used(plan.data_bytes_used) { } - + // Formats cellular plan description. + string16 GetPlanDesciption() const; + // Evaluates cellular plans status and returns warning string if it is near + // expiration. + string16 GetRemainingWarning() const; + // Formats remaining plan data description. + string16 GetDataRemainingDesciption() const; + // Formats plan expiration description. + string16 GetPlanExpiration() const; + // Formats plan usage info. + string16 GetUsageInfo() const; + int64 remaining_minutes() const; + int64 remaining_mbytes() const; std::string plan_name; CellularDataPlanType plan_type; base::Time update_time; @@ -206,6 +219,10 @@ class CellularNetwork : public WirelessNetwork { } const NetworkRoamingState roaming_state() const { return roaming_state_; } bool restricted_pool() const { return restricted_pool_; } + bool needs_new_plan() const { + return restricted_pool() && connected() && + activation_state() == ACTIVATION_STATE_ACTIVATED; + } const std::string& service_name() const { return service_name_; } const std::string& operator_name() const { return operator_name_; } const std::string& operator_code() const { return operator_code_; } |