diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 22:58:09 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 22:58:09 +0000 |
commit | 8a4624215a3cbb5f2a48de816a460dda2d8b2ad3 (patch) | |
tree | cbfce72c4bf76e33f01713b30eaecd281414645a | |
parent | cfa25bde323a4c21b8814cbc1df61ccbfa9d9314 (diff) | |
download | chromium_src-8a4624215a3cbb5f2a48de816a460dda2d8b2ad3.zip chromium_src-8a4624215a3cbb5f2a48de816a460dda2d8b2ad3.tar.gz chromium_src-8a4624215a3cbb5f2a48de816a460dda2d8b2ad3.tar.bz2 |
Use TimeFormat::TimeRemaining for CellularDataPlan::GetUsageInfo.
CellularDataPlan::GetUsageInfo is used for network menu's expiration
label and TimeFormat::TimeRemaining is prefered per chromium-os:9331.
BUG=chromium-os:9331
TEST=Verify fix for chromium-os:9331
Review URL: http://codereview.chromium.org/5221004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67176 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.cc | 45 | ||||
-rw-r--r-- | chrome/browser/chromeos/network_message_observer.cc | 26 |
3 files changed, 27 insertions, 50 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index e7536bf..9777cdd 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -9060,12 +9060,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_NETWORK_DATA_EXPIRED_TITLE" desc="Title for network data expired notification"> <ph name="network">$1<ex>YBH</ex></ph> data expired </message> - <message name="IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE" desc="Message for network minutes until expirations notification"> - <ph name="minues">$1<ex>30</ex></ph> minutes until expiration - </message> - <message name="IDS_NETWORK_MINUTES_REMAINING_MESSAGE" desc="Message for network minutes remaining notification"> - <ph name="minues">$1<ex>30</ex></ph> minutes remaining - </message> <message name="IDS_NETWORK_CONNECTION_ERROR_TITLE" desc="Title for network connection error notification"> Network Connection Error </message> diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index 5833a8b..13fa2a8 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -416,46 +416,36 @@ string16 CellularDataPlan::GetPlanDesciption() const { 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))); + if (remaining_time().InSeconds() <= chromeos::kCellularDataVeryLowSecs) { + return GetPlanExpiration(); } } 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) { + if (remaining_data() <= chromeos::kCellularDataVeryLowBytes) { return l10n_util::GetStringFUTF16( IDS_NETWORK_DATA_REMAINING_MESSAGE, - UTF8ToUTF16(base::Int64ToString(bytes_remaining/(1024*1024)))); + UTF8ToUTF16(base::Int64ToString(remaining_mbytes()))); } } return string16(); } string16 CellularDataPlan::GetDataRemainingDesciption() const { + int64 remaining_bytes = remaining_data(); 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), + return FormatBytes(remaining_bytes, + GetByteDisplayUnits(remaining_bytes), true); } case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: { - return FormatBytes(plan_data_bytes - data_bytes_used, - GetByteDisplayUnits(plan_data_bytes - data_bytes_used), + return FormatBytes(remaining_bytes, + GetByteDisplayUnits(remaining_bytes), true); } default: @@ -467,26 +457,19 @@ string16 CellularDataPlan::GetDataRemainingDesciption() const { 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))); + return GetPlanExpiration(); } 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)))); + UTF8ToUTF16(base::Int64ToString(remaining_mbytes()))); } return string16(); } base::TimeDelta CellularDataPlan::remaining_time() const { - base::TimeDelta time = plan_end_time - update_time; + base::TimeDelta time = plan_end_time - base::Time::Now(); return time.InMicroseconds() < 0 ? base::TimeDelta() : time; } @@ -628,7 +611,7 @@ CellularNetwork::DataLeft CellularNetwork::GetDataLeft() const { if (!plan) return DATA_NORMAL; if (plan->plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { - base::TimeDelta remaining = plan->plan_end_time - plan->update_time; + base::TimeDelta remaining = plan->remaining_time(); if (remaining <= base::TimeDelta::FromSeconds(0)) return DATA_NONE; if (remaining <= base::TimeDelta::FromSeconds(kCellularDataVeryLowSecs)) @@ -637,7 +620,7 @@ CellularNetwork::DataLeft CellularNetwork::GetDataLeft() const { return DATA_LOW; } else if (plan->plan_type == CELLULAR_DATA_PLAN_METERED_PAID || plan->plan_type == CELLULAR_DATA_PLAN_METERED_BASE) { - int64 remaining = plan->plan_data_bytes - plan->data_bytes_used; + int64 remaining = plan->remaining_data(); if (remaining <= 0) return DATA_NONE; if (remaining <= kCellularDataVeryLowBytes) diff --git a/chrome/browser/chromeos/network_message_observer.cc b/chrome/browser/chromeos/network_message_observer.cc index 6980eb7..9a8f2e4 100644 --- a/chrome/browser/chromeos/network_message_observer.cc +++ b/chrome/browser/chromeos/network_message_observer.cc @@ -20,6 +20,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/views/window.h" #include "chrome/common/pref_names.h" +#include "chrome/common/time_format.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "views/window/dialog_delegate.h" @@ -255,24 +256,23 @@ void NetworkMessageObserver::OnCellularDataPlanChanged(NetworkLibrary* obj) { if (cellular->GetDataLeft() == CellularNetwork::DATA_NONE) { notification_low_data_.Hide(); - int message = cellular_data_plan_type_ == CELLULAR_DATA_PLAN_UNLIMITED ? - IDS_NETWORK_MINUTES_REMAINING_MESSAGE : - IDS_NETWORK_DATA_REMAINING_MESSAGE; - notification_no_data_.Show(l10n_util::GetStringFUTF16( - message, ASCIIToUTF16("0")), + string16 message = + cellular_data_plan_type_ == CELLULAR_DATA_PLAN_UNLIMITED ? + TimeFormat::TimeRemaining(base::TimeDelta()) : + l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_REMAINING_MESSAGE, + ASCIIToUTF16("0")); + notification_no_data_.Show(message, l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), NewCallback(this, &NetworkMessageObserver::OpenMobileSetupPage), false, false); } else if (cellular->GetDataLeft() == CellularNetwork::DATA_VERY_LOW) { notification_no_data_.Hide(); - int message = cellular_data_plan_type_ == CELLULAR_DATA_PLAN_UNLIMITED ? - IDS_NETWORK_MINUTES_REMAINING_MESSAGE : - IDS_NETWORK_DATA_REMAINING_MESSAGE; - int64 remaining = cellular_data_plan_type_ == CELLULAR_DATA_PLAN_UNLIMITED ? - plan->remaining_minutes() : - plan->remaining_mbytes(); - notification_low_data_.Show(l10n_util::GetStringFUTF16( - message, UTF8ToUTF16(base::Int64ToString(remaining))), + string16 message = + cellular_data_plan_type_ == CELLULAR_DATA_PLAN_UNLIMITED ? + plan->GetPlanExpiration() : + l10n_util::GetStringFUTF16(IDS_NETWORK_DATA_REMAINING_MESSAGE, + UTF8ToUTF16(base::Int64ToString(plan->remaining_mbytes()))); + notification_low_data_.Show(message, l10n_util::GetStringUTF16(IDS_NETWORK_MORE_INFO_MESSAGE), NewCallback(this, &NetworkMessageObserver::OpenMoreInfoPage), false, false); |