summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 23:14:23 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 23:14:23 +0000
commit1a3497826eea1d31fe8fce408907c01bd57c137e (patch)
tree78ce3ac667715b104b67fed62f3f341c65224ab6
parentdbc63d7f9d649871346e8ef54bf6746bcdc12ff8 (diff)
downloadchromium_src-1a3497826eea1d31fe8fce408907c01bd57c137e.zip
chromium_src-1a3497826eea1d31fe8fce408907c01bd57c137e.tar.gz
chromium_src-1a3497826eea1d31fe8fce408907c01bd57c137e.tar.bz2
Merge 67176 - 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 TBR=chocobo@chromium.org Review URL: http://codereview.chromium.org/5366001 git-svn-id: svn://svn.chromium.org/chrome/branches/552d/src@67179 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc45
-rw-r--r--chrome/browser/chromeos/network_message_observer.cc26
3 files changed, 27 insertions, 50 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 2406779..869e6c7 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -8843,12 +8843,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 169b75e..8379fee 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 fd0a9d2..c275171 100644
--- a/chrome/browser/chromeos/network_message_observer.cc
+++ b/chrome/browser/chromeos/network_message_observer.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/profile.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);