| OLD | NEW |
| 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 #include <memory> |
| 9 | 10 |
| 10 #include "base/callback_list.h" | 11 #include "base/callback_list.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace power { | 16 namespace power { |
| 17 | 17 |
| 18 // Tracks app and website origins and how much power they are consuming while | 18 // Tracks app and website origins and how much power they are consuming while |
| 19 // running. | 19 // running. |
| 20 class OriginPowerMap : public KeyedService { | 20 class OriginPowerMap : public KeyedService { |
| 21 public: | 21 public: |
| 22 typedef std::map<GURL, int> PercentOriginMap; | 22 typedef std::map<GURL, int> PercentOriginMap; |
| 23 typedef base::CallbackList<void(void)>::Subscription Subscription; | 23 typedef base::CallbackList<void(void)>::Subscription Subscription; |
| 24 | 24 |
| 25 OriginPowerMap(); | 25 OriginPowerMap(); |
| 26 ~OriginPowerMap() override; | 26 ~OriginPowerMap() override; |
| 27 | 27 |
| 28 // Returns the integer percentage usage of the total power consumed by a | 28 // Returns the integer percentage usage of the total power consumed by a |
| 29 // given URL's origin. | 29 // given URL's origin. |
| 30 int GetPowerForOrigin(const GURL& url); | 30 int GetPowerForOrigin(const GURL& url); |
| 31 | 31 |
| 32 // Adds a certain amount of power consumption to a given URL's origin. | 32 // Adds a certain amount of power consumption to a given URL's origin. |
| 33 // |power| is a platform-specific heuristic estimating power consumption. | 33 // |power| is a platform-specific heuristic estimating power consumption. |
| 34 void AddPowerForOrigin(const GURL& url, double power); | 34 void AddPowerForOrigin(const GURL& url, double power); |
| 35 | 35 |
| 36 // Returns a map of all origins to the integer percentage usage of power | 36 // Returns a map of all origins to the integer percentage usage of power |
| 37 // consumed. | 37 // consumed. |
| 38 PercentOriginMap GetPercentOriginMap(); | 38 PercentOriginMap GetPercentOriginMap(); |
| 39 | 39 |
| 40 // Adds a callback for the completion of a round of updates to |origin_map_|. | 40 // Adds a callback for the completion of a round of updates to |origin_map_|. |
| 41 scoped_ptr<Subscription> AddPowerConsumptionUpdatedCallback( | 41 std::unique_ptr<Subscription> AddPowerConsumptionUpdatedCallback( |
| 42 const base::Closure& callback); | 42 const base::Closure& callback); |
| 43 | 43 |
| 44 // Notifies observers to let them know that the origin power map has finished | 44 // Notifies observers to let them know that the origin power map has finished |
| 45 // updating for all origins this cycle. | 45 // updating for all origins this cycle. |
| 46 void OnAllOriginsUpdated(); | 46 void OnAllOriginsUpdated(); |
| 47 | 47 |
| 48 // Clears all URLs out of the map. | 48 // Clears all URLs out of the map. |
| 49 void ClearOriginMap(); | 49 void ClearOriginMap(); |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // OriginMap maps a URL to the amount of power consumed by the URL using the | 52 // OriginMap maps a URL to the amount of power consumed by the URL using the |
| 53 // same units as |total_consumed_|. | 53 // same units as |total_consumed_|. |
| 54 typedef std::map<GURL, double> OriginMap; | 54 typedef std::map<GURL, double> OriginMap; |
| 55 OriginMap origin_map_; | 55 OriginMap origin_map_; |
| 56 | 56 |
| 57 // Total amount of power consumed using units determined by | 57 // Total amount of power consumed using units determined by |
| 58 // the power heuristics available to the platform. | 58 // the power heuristics available to the platform. |
| 59 double total_consumed_; | 59 double total_consumed_; |
| 60 | 60 |
| 61 base::CallbackList<void(void)> callback_list_; | 61 base::CallbackList<void(void)> callback_list_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(OriginPowerMap); | 63 DISALLOW_COPY_AND_ASSIGN(OriginPowerMap); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 } // namespace power | 66 } // namespace power |
| 67 | 67 |
| 68 #endif // COMPONENTS_POWER_ORIGIN_POWER_MAP_H_ | 68 #endif // COMPONENTS_POWER_ORIGIN_POWER_MAP_H_ |
| OLD | NEW |