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

Side by Side Diff: components/power/origin_power_map.h

Issue 519883002: Update the Website Settings page when the power consumption is updated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove the Observer, replace with Subscription. Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_POWER_ORIGIN_POWER_MAP_H_ 5 #ifndef COMPONENTS_POWER_ORIGIN_POWER_MAP_H_
6 #define COMPONENTS_POWER_ORIGIN_POWER_MAP_H_ 6 #define COMPONENTS_POWER_ORIGIN_POWER_MAP_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/callback_list.h"
10 #include "components/keyed_service/core/keyed_service.h" 11 #include "components/keyed_service/core/keyed_service.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace power { 14 namespace power {
14 15
15 // Tracks app and website origins and how much power they are consuming while 16 // Tracks app and website origins and how much power they are consuming while
16 // running. 17 // running.
17 class OriginPowerMap : public KeyedService { 18 class OriginPowerMap : public KeyedService {
18 public: 19 public:
19 typedef std::map<GURL, int> PercentOriginMap; 20 typedef std::map<GURL, int> PercentOriginMap;
21 typedef base::CallbackList<void(void)>::Subscription Subscription;
20 22
21 OriginPowerMap(); 23 OriginPowerMap();
22 virtual ~OriginPowerMap(); 24 virtual ~OriginPowerMap();
23 25
24 // Returns the integer percentage usage of the total power consumed by a 26 // Returns the integer percentage usage of the total power consumed by a
25 // given URL's origin. 27 // given URL's origin.
26 int GetPowerForOrigin(const GURL& url); 28 int GetPowerForOrigin(const GURL& url);
27 29
28 // Adds a certain amount of power consumption to a given URL's origin. 30 // Adds a certain amount of power consumption to a given URL's origin.
29 // |power| is a platform-specific heuristic estimating power consumption. 31 // |power| is a platform-specific heuristic estimating power consumption.
30 void AddPowerForOrigin(const GURL& url, double power); 32 void AddPowerForOrigin(const GURL& url, double power);
31 33
32 // Returns a map of all origins to the integer percentage usage of power 34 // Returns a map of all origins to the integer percentage usage of power
33 // consumed. 35 // consumed.
34 PercentOriginMap GetPercentOriginMap(); 36 PercentOriginMap GetPercentOriginMap();
35 37
38 // Adds a callback for when the power consumption for the map finishes
Daniel Erat 2014/09/02 17:14:39 nit: maybe something like "Adds a callback for the
Daniel Nishi 2014/09/02 17:32:48 Done.
39 // updating.
40 scoped_ptr<Subscription> AddPowerConsumptionUpdatedCallback(
41 const base::Closure& callback);
42
43 // Notifies observers to let them know that the origin power map has finished
44 // updating for all origins this cycle.
45 void OnAllOriginsUpdated();
46
36 private: 47 private:
37 // OriginMap maps a URL to the amount of power consumed by the URL using the 48 // OriginMap maps a URL to the amount of power consumed by the URL using the
38 // same units as |total_consumed_|. 49 // same units as |total_consumed_|.
39 typedef std::map<GURL, double> OriginMap; 50 typedef std::map<GURL, double> OriginMap;
40 OriginMap origin_map_; 51 OriginMap origin_map_;
41 52
42 // Total amount of power consumed using units determined by 53 // Total amount of power consumed using units determined by
43 // the power heuristics available to the platform. 54 // the power heuristics available to the platform.
44 double total_consumed_; 55 double total_consumed_;
45 56
57 base::CallbackList<void(void)> callback_list_;
58
46 DISALLOW_COPY_AND_ASSIGN(OriginPowerMap); 59 DISALLOW_COPY_AND_ASSIGN(OriginPowerMap);
47 }; 60 };
48 61
49 } // namespace power 62 } // namespace power
50 63
51 #endif // COMPONENTS_POWER_ORIGIN_POWER_MAP_H_ 64 #endif // COMPONENTS_POWER_ORIGIN_POWER_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/website_settings_handler.cc ('k') | components/power/origin_power_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698