Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / power / origin_power_map.h
blob7592a2b56673084d0a2babd00e725a28bf42c716
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.
5 #ifndef COMPONENTS_POWER_ORIGIN_POWER_MAP_H_
6 #define COMPONENTS_POWER_ORIGIN_POWER_MAP_H_
8 #include <map>
10 #include "base/callback_list.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "url/gurl.h"
14 namespace power {
16 // Tracks app and website origins and how much power they are consuming while
17 // running.
18 class OriginPowerMap : public KeyedService {
19 public:
20 typedef std::map<GURL, int> PercentOriginMap;
21 typedef base::CallbackList<void(void)>::Subscription Subscription;
23 OriginPowerMap();
24 ~OriginPowerMap() override;
26 // Returns the integer percentage usage of the total power consumed by a
27 // given URL's origin.
28 int GetPowerForOrigin(const GURL& url);
30 // Adds a certain amount of power consumption to a given URL's origin.
31 // |power| is a platform-specific heuristic estimating power consumption.
32 void AddPowerForOrigin(const GURL& url, double power);
34 // Returns a map of all origins to the integer percentage usage of power
35 // consumed.
36 PercentOriginMap GetPercentOriginMap();
38 // Adds a callback for the completion of a round of updates to |origin_map_|.
39 scoped_ptr<Subscription> AddPowerConsumptionUpdatedCallback(
40 const base::Closure& callback);
42 // Notifies observers to let them know that the origin power map has finished
43 // updating for all origins this cycle.
44 void OnAllOriginsUpdated();
46 // Clears all URLs out of the map.
47 void ClearOriginMap();
49 private:
50 // OriginMap maps a URL to the amount of power consumed by the URL using the
51 // same units as |total_consumed_|.
52 typedef std::map<GURL, double> OriginMap;
53 OriginMap origin_map_;
55 // Total amount of power consumed using units determined by
56 // the power heuristics available to the platform.
57 double total_consumed_;
59 base::CallbackList<void(void)> callback_list_;
61 DISALLOW_COPY_AND_ASSIGN(OriginPowerMap);
64 } // namespace power
66 #endif // COMPONENTS_POWER_ORIGIN_POWER_MAP_H_