OLD | NEW |
---|---|
(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 "chrome/browser/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 OriginPowerMap::OriginPowerMap() { | |
12 } | |
13 | |
14 OriginPowerMap::~OriginPowerMap() { | |
15 } | |
16 | |
17 int OriginPowerMap::GetPowerForOrigin(const GURL& url) { | |
18 GURL origin = url.GetOrigin(); | |
19 if (origin_map_.find(origin) == origin_map_.end() || !total_consumed_) | |
20 return 0; | |
21 return origin_map_[origin] * 100 / total_consumed_; | |
22 } | |
23 | |
24 void OriginPowerMap::AddPowerForOrigin(const GURL& url, double power) { | |
25 GURL origin = url.GetOrigin(); | |
sky
2014/08/08 23:44:56
DCHECK_GE(power, 0)
Daniel Nishi
2014/08/08 23:50:55
Done.
| |
26 if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme)) | |
27 return; | |
28 | |
29 origin_map_[origin] += power; | |
30 total_consumed_ += power; | |
31 } | |
32 | |
33 scoped_ptr<OriginPowerMap::PercentOriginMap> | |
34 OriginPowerMap::GetPercentOriginMap() { | |
35 scoped_ptr<OriginPowerMap::PercentOriginMap> percent_map( | |
36 new OriginPowerMap::PercentOriginMap); | |
37 for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end(); | |
38 ++it) { | |
39 (*percent_map)[it->first] = (it->second / total_consumed_ * 100); | |
40 } | |
41 return percent_map.Pass(); | |
42 } | |
OLD | NEW |