Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: ash/system/chromeos/power/power_status.cc

Issue 258303002: chromeos: Fix a bug in the battery-time-rounding code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/system/chromeos/power/power_status.h" 5 #include "ash/system/chromeos/power/power_status.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return time >= base::TimeDelta::FromMinutes(1) && 110 return time >= base::TimeDelta::FromMinutes(1) &&
111 time.InSeconds() <= kMaxBatteryTimeToDisplaySec; 111 time.InSeconds() <= kMaxBatteryTimeToDisplaySec;
112 } 112 }
113 113
114 // static 114 // static
115 void PowerStatus::SplitTimeIntoHoursAndMinutes(const base::TimeDelta& time, 115 void PowerStatus::SplitTimeIntoHoursAndMinutes(const base::TimeDelta& time,
116 int* hours, 116 int* hours,
117 int* minutes) { 117 int* minutes) {
118 DCHECK(hours); 118 DCHECK(hours);
119 DCHECK(minutes); 119 DCHECK(minutes);
120 *hours = time.InHours(); 120 const int total_minutes = static_cast<int>(time.InSecondsF() / 60 + 0.5);
121 const double seconds = 121 *hours = total_minutes / 60;
122 (time - base::TimeDelta::FromHours(*hours)).InSecondsF(); 122 *minutes = total_minutes % 60;
123 *minutes = static_cast<int>(seconds / 60.0 + 0.5);
124 } 123 }
125 124
126 void PowerStatus::AddObserver(Observer* observer) { 125 void PowerStatus::AddObserver(Observer* observer) {
127 DCHECK(observer); 126 DCHECK(observer);
128 observers_.AddObserver(observer); 127 observers_.AddObserver(observer);
129 } 128 }
130 129
131 void PowerStatus::RemoveObserver(Observer* observer) { 130 void PowerStatus::RemoveObserver(Observer* observer) {
132 DCHECK(observer); 131 DCHECK(observer);
133 observers_.RemoveObserver(observer); 132 observers_.RemoveObserver(observer);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 296 }
298 297
299 void PowerStatus::PowerChanged( 298 void PowerStatus::PowerChanged(
300 const power_manager::PowerSupplyProperties& proto) { 299 const power_manager::PowerSupplyProperties& proto) {
301 proto_ = proto; 300 proto_ = proto;
302 SanitizeProto(&proto_); 301 SanitizeProto(&proto_);
303 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged()); 302 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged());
304 } 303 }
305 304
306 } // namespace ash 305 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698