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

Side by Side Diff: components/power/origin_power_map.cc

Issue 447053002: Add Origin Power Map to Store Battery Auditing Data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase. Created 6 years, 4 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
« no previous file with comments | « components/power/origin_power_map.h ('k') | components/power/origin_power_map_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/power/origin_power_map.h"
6
7 #include "base/logging.h"
8 #include "content/public/common/url_constants.h"
9 #include "url/gurl.h"
10
11 namespace power {
12
13 OriginPowerMap::OriginPowerMap() : total_consumed_(0.0) {
14 }
15
16 OriginPowerMap::~OriginPowerMap() {
17 }
18
19 int OriginPowerMap::GetPowerForOrigin(const GURL& url) {
20 if (!total_consumed_)
21 return 0;
22
23 OriginMap::const_iterator it = origin_map_.find(url.GetOrigin());
24 return it == origin_map_.end() ? 0 :
25 static_cast<int>(it->second * 100 / total_consumed_ + 0.5);
26 }
27
28 void OriginPowerMap::AddPowerForOrigin(const GURL& url, double power) {
29 DCHECK_GE(power, 0);
30 GURL origin = url.GetOrigin();
31 if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme))
32 return;
33
34 origin_map_[origin] += power;
35 total_consumed_ += power;
36 }
37
38 OriginPowerMap::PercentOriginMap OriginPowerMap::GetPercentOriginMap() {
39 OriginPowerMap::PercentOriginMap percent_map;
40
41 if (!total_consumed_)
42 return percent_map;
43
44 for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end();
45 ++it) {
46 percent_map[it->first] =
47 static_cast<int>(it->second * 100 / total_consumed_ + 0.5);
48 }
49 return percent_map;
50 }
51
52 } // namespace power
OLDNEW
« no previous file with comments | « components/power/origin_power_map.h ('k') | components/power/origin_power_map_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698