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 "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() | |
| 25 ? 0 | |
|
Daniel Erat
2014/08/12 18:40:18
this should just be indented four spaces beyond th
Daniel Nishi
2014/08/12 19:57:34
Whoops. An errant git cl format knocked out the fo
| |
| 26 : static_cast<int>(it->second * 100 / total_consumed_ + 0.5); | |
| 27 } | |
| 28 | |
| 29 void OriginPowerMap::AddPowerForOrigin(const GURL& url, double power) { | |
| 30 DCHECK_GE(power, 0); | |
| 31 GURL origin = url.GetOrigin(); | |
| 32 if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme)) | |
| 33 return; | |
| 34 | |
| 35 origin_map_[origin] += power; | |
| 36 total_consumed_ += power; | |
| 37 } | |
| 38 | |
| 39 OriginPowerMap::PercentOriginMap OriginPowerMap::GetPercentOriginMap() { | |
| 40 OriginPowerMap::PercentOriginMap percent_map; | |
| 41 | |
| 42 if (!total_consumed_) | |
| 43 return percent_map; | |
| 44 | |
| 45 for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end(); | |
| 46 ++it) { | |
| 47 percent_map[it->first] = | |
| 48 static_cast<int>(it->second * 100 / total_consumed_ + 0.5); | |
| 49 } | |
| 50 return percent_map; | |
| 51 } | |
| 52 | |
| 53 } // namespace power | |
| OLD | NEW |