summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-03 23:27:28 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-03 23:27:28 +0000
commit18d0ee3958b93177db2a9683e454407cf61a7026 (patch)
tree92940191b7bcb3983dafe5118c40a58b4f1b12e4
parentd815a1b2b93788ccd245136ce788eb4a9010c6bb (diff)
downloadchromium_src-18d0ee3958b93177db2a9683e454407cf61a7026.zip
chromium_src-18d0ee3958b93177db2a9683e454407cf61a7026.tar.gz
chromium_src-18d0ee3958b93177db2a9683e454407cf61a7026.tar.bz2
Valgrind fix for chromium-os:5601
BUG=chromium-os:6441 (valgrind error) TEST=Run Valgrind, verify it doesn't fail in PowerMenuButton. Original CL: http://codereview.chromium.org/3158014/show Two changes: 1. Re-ordered the member variables so that members used by GetLabelAt() are initialized before power_menu_ which calls into GetLabelAt(). 2. Modified GetLabelAt() to explicitly check for index == 1 for the second line, just for clarity. Review URL: http://codereview.chromium.org/3291010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58559 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/status/power_menu_button.cc66
-rw-r--r--chrome/browser/chromeos/status/power_menu_button.h9
2 files changed, 40 insertions, 35 deletions
diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc
index 98cda08..85f5e72 100644
--- a/chrome/browser/chromeos/status/power_menu_button.cc
+++ b/chrome/browser/chromeos/status/power_menu_button.cc
@@ -24,12 +24,12 @@ const int PowerMenuButton::kNumPowerImages = 12;
PowerMenuButton::PowerMenuButton()
: StatusAreaButton(this),
- ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)),
battery_is_present_(false),
line_power_on_(false),
battery_fully_charged_(false),
battery_percentage_(0.0),
- icon_id_(-1) {
+ icon_id_(-1),
+ ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) {
UpdateIconAndLabelInfo();
CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this);
}
@@ -56,36 +56,40 @@ string16 PowerMenuButton::GetLabelAt(int index) const {
base::IntToString16(static_cast<int>(battery_percentage_)));
}
- // The second item shows the battery is charged if it is.
- if (battery_fully_charged_)
- return l10n_util::GetStringUTF16(IDS_STATUSBAR_BATTERY_IS_CHARGED);
-
- // If battery is in an intermediate charge state, we show how much time left.
- base::TimeDelta time = line_power_on_ ? battery_time_to_full_ :
- battery_time_to_empty_;
- if (time.InSeconds() == 0) {
- // If time is 0, then that means we are still calculating how much time.
- // Depending if line power is on, we either show a message saying that we
- // are calculating time until full or calculating remaining time.
- int msg = line_power_on_ ?
- IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_FULL :
- IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_EMPTY;
- return l10n_util::GetStringUTF16(msg);
- } else {
- // Depending if line power is on, we either show a message saying XX:YY
- // until full or XX:YY remaining where XX is number of hours and YY is
- // number of minutes.
- int msg = line_power_on_ ? IDS_STATUSBAR_BATTERY_TIME_UNTIL_FULL :
- IDS_STATUSBAR_BATTERY_TIME_UNTIL_EMPTY;
- int hour = time.InHours();
- int min = (time - base::TimeDelta::FromHours(hour)).InMinutes();
- string16 hour_str = base::IntToString16(hour);
- string16 min_str = base::IntToString16(min);
- // Append a "0" before the minute if it's only a single digit.
- if (min < 10)
- min_str = ASCIIToUTF16("0") + min_str;
- return l10n_util::GetStringFUTF16(msg, hour_str, min_str);
+ if (index == 1) {
+ // The second item shows the battery is charged if it is.
+ if (battery_fully_charged_)
+ return l10n_util::GetStringUTF16(IDS_STATUSBAR_BATTERY_IS_CHARGED);
+
+ // If battery is in an intermediate charge state, we show how much time left.
+ base::TimeDelta time = line_power_on_ ? battery_time_to_full_ :
+ battery_time_to_empty_;
+ if (time.InSeconds() == 0) {
+ // If time is 0, then that means we are still calculating how much time.
+ // Depending if line power is on, we either show a message saying that we
+ // are calculating time until full or calculating remaining time.
+ int msg = line_power_on_ ?
+ IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_FULL :
+ IDS_STATUSBAR_BATTERY_CALCULATING_TIME_UNTIL_EMPTY;
+ return l10n_util::GetStringUTF16(msg);
+ } else {
+ // Depending if line power is on, we either show a message saying XX:YY
+ // until full or XX:YY remaining where XX is number of hours and YY is
+ // number of minutes.
+ int msg = line_power_on_ ? IDS_STATUSBAR_BATTERY_TIME_UNTIL_FULL :
+ IDS_STATUSBAR_BATTERY_TIME_UNTIL_EMPTY;
+ int hour = time.InHours();
+ int min = (time - base::TimeDelta::FromHours(hour)).InMinutes();
+ string16 hour_str = base::IntToString16(hour);
+ string16 min_str = base::IntToString16(min);
+ // Append a "0" before the minute if it's only a single digit.
+ if (min < 10)
+ min_str = ASCIIToUTF16("0") + min_str;
+ return l10n_util::GetStringFUTF16(msg, hour_str, min_str);
+ }
}
+
+ return string16();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/status/power_menu_button.h b/chrome/browser/chromeos/status/power_menu_button.h
index abf758a..7f27333 100644
--- a/chrome/browser/chromeos/status/power_menu_button.h
+++ b/chrome/browser/chromeos/status/power_menu_button.h
@@ -74,10 +74,7 @@ class PowerMenuButton : public StatusAreaButton,
// The number of power images.
static const int kNumPowerImages;
- // The power menu.
- views::Menu2 power_menu_;
-
- // Stored data gathered CrosLibrary::PowerLibrary.
+ // Stored data gathered from CrosLibrary::PowerLibrary.
bool battery_is_present_;
bool line_power_on_;
bool battery_fully_charged_;
@@ -88,6 +85,10 @@ class PowerMenuButton : public StatusAreaButton,
// The currently showing icon bitmap id.
int icon_id_;
+ // The power menu. This needs to be initialized last since it calls into
+ // GetLabelAt() during construction.
+ views::Menu2 power_menu_;
+
DISALLOW_COPY_AND_ASSIGN(PowerMenuButton);
};