Chromium Code Reviews| 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& origin) { | |
| 18 if (origin_map_.find(origin) == origin_map_.end() || !total_consumed_) | |
| 19 return 0; | |
| 20 return origin_map_[origin] * 100 / total_consumed_; | |
| 21 } | |
| 22 | |
| 23 void OriginPowerMap::AddPowerForOrigin(const GURL& origin, double power) { | |
| 24 if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme)) | |
| 25 return; | |
| 26 | |
| 27 origin_map_[origin] += power; | |
|
sky
2014/08/08 23:15:28
I was actually saying something differently. I thi
Daniel Nishi
2014/08/08 23:38:07
Oh, I see. I misunderstood.
I've allowed arbitrar
| |
| 28 total_consumed_ += power; | |
| 29 } | |
| 30 | |
| 31 scoped_ptr<const OriginPowerMap::PercentOriginMap> | |
| 32 OriginPowerMap::GetPercentOriginMap() { | |
| 33 OriginPowerMap::PercentOriginMap* percent_map = | |
| 34 new OriginPowerMap::PercentOriginMap; | |
| 35 for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end(); | |
| 36 ++it) { | |
| 37 (*percent_map)[it->first] = (it->second / total_consumed_ * 100); | |
| 38 } | |
| 39 return scoped_ptr<const OriginPowerMap::PercentOriginMap>(percent_map); | |
| 40 } | |
| OLD | NEW |