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 DCHECK_EQ(origin, origin.GetOrigin()); | |
| 19 if (origin_map_.find(origin) == origin_map_.end()) | |
| 20 return -1; | |
|
sky
2014/08/08 19:12:25
Why the -1 here? I would have expected 0.
Daniel Nishi
2014/08/08 19:41:05
Fair enough. If it's not in the map, it hasn't con
| |
| 21 else if (!total_consumed_) | |
|
sky
2014/08/08 19:12:25
nit: no else after a return (see chromium specific
Daniel Nishi
2014/08/08 19:41:05
Changed the return value if not found to 0 and mer
| |
| 22 return 0; | |
| 23 return origin_map_[origin] * 100 / total_consumed_; | |
| 24 } | |
| 25 | |
| 26 void OriginPowerMap::AddPowerForOrigin(const GURL& origin, double power) { | |
| 27 DCHECK_EQ(origin, origin.GetOrigin()); | |
|
sky
2014/08/08 19:12:25
Why does the caller have to have called GetOrigin(
Daniel Nishi
2014/08/08 19:41:05
Looking over the GetOrigin() call, I agree. For on
| |
| 28 if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme)) | |
|
sky
2014/08/08 19:12:25
Why do you special case chrome urls?
Daniel Nishi
2014/08/08 19:41:05
When they appear in the resource monitoring UI, th
| |
| 29 return; | |
| 30 | |
| 31 if (origin_map_.find(origin) == origin_map_.end()) { | |
|
sky
2014/08/08 19:12:25
nit: no {}
sky
2014/08/08 19:12:25
And you actually shouldn't need this if at all. or
Daniel Nishi
2014/08/08 19:41:05
Good point. I've removed this if.
| |
| 32 origin_map_[origin] = 0; | |
| 33 } | |
| 34 origin_map_[origin] += power; | |
| 35 total_consumed_ += power; | |
| 36 } | |
| 37 | |
| 38 scoped_ptr<const OriginPowerMap::PercentOriginMap> | |
| 39 OriginPowerMap::GetPercentOriginMap() { | |
| 40 OriginPowerMap::PercentOriginMap* percent_map = | |
|
sky
2014/08/08 19:12:25
Create a scoped_ptr here and use .Pass() in the re
Daniel Nishi
2014/08/08 19:41:05
I think I'd lose the const-ness if I did this, sin
sky
2014/08/08 23:15:28
There is no point in returning a const value here.
Daniel Nishi
2014/08/08 23:38:07
Done.
| |
| 41 new OriginPowerMap::PercentOriginMap; | |
| 42 for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end(); | |
| 43 ++it) { | |
| 44 (*percent_map)[it->first] = (it->second / total_consumed_ * 100); | |
| 45 } | |
| 46 return scoped_ptr<const OriginPowerMap::PercentOriginMap>(percent_map).Pass(); | |
| 47 } | |
| OLD | NEW |