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

Unified Diff: chrome/browser/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: Comments addressed. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/power/origin_power_map.h ('k') | chrome/browser/power/origin_power_map_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/power/origin_power_map.cc
diff --git a/chrome/browser/power/origin_power_map.cc b/chrome/browser/power/origin_power_map.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca65807dbf81cbf15962577f706e70a37dfaec4c
--- /dev/null
+++ b/chrome/browser/power/origin_power_map.cc
@@ -0,0 +1,40 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/power/origin_power_map.h"
+
+#include "base/logging.h"
+#include "content/public/common/url_constants.h"
+#include "url/gurl.h"
+
+OriginPowerMap::OriginPowerMap() {
+}
+
+OriginPowerMap::~OriginPowerMap() {
+}
+
+int OriginPowerMap::GetPowerForOrigin(const GURL& origin) {
+ if (origin_map_.find(origin) == origin_map_.end() || !total_consumed_)
+ return 0;
+ return origin_map_[origin] * 100 / total_consumed_;
+}
+
+void OriginPowerMap::AddPowerForOrigin(const GURL& origin, double power) {
+ if (!origin.is_valid() || origin.SchemeIs(content::kChromeUIScheme))
+ return;
+
+ 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
+ total_consumed_ += power;
+}
+
+scoped_ptr<const OriginPowerMap::PercentOriginMap>
+OriginPowerMap::GetPercentOriginMap() {
+ OriginPowerMap::PercentOriginMap* percent_map =
+ new OriginPowerMap::PercentOriginMap;
+ for (OriginMap::iterator it = origin_map_.begin(); it != origin_map_.end();
+ ++it) {
+ (*percent_map)[it->first] = (it->second / total_consumed_ * 100);
+ }
+ return scoped_ptr<const OriginPowerMap::PercentOriginMap>(percent_map);
+}
« no previous file with comments | « chrome/browser/power/origin_power_map.h ('k') | chrome/browser/power/origin_power_map_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698