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

Side by Side Diff: device/battery/battery_status_service.h

Issue 457933002: Replace Chrome IPC with Mojo IPC for querying BatteryStatus service Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 | Annotate | Revision Log
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 CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ 5 #ifndef DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_
6 #define CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ 6 #define DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_
7 7
8 #include "base/callback_list.h" 8 #include "base/callback_list.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
10 #include "content/common/content_export.h" 11 #include "device/battery/battery_export.h"
11 #include "third_party/WebKit/public/platform/WebBatteryStatus.h" 12 #include "device/battery/battery_status.mojom.h"
12 13
13 namespace content { 14 namespace device {
14 class BatteryStatusManager; 15 class BatteryStatusManager;
15 16
16 class CONTENT_EXPORT BatteryStatusService { 17 class DEVICE_BATTERY_EXPORT BatteryStatusService {
17 public: 18 public:
18 typedef base::Callback<void(const blink::WebBatteryStatus&)> 19 typedef base::Callback<void(const BatteryStatus&)> BatteryUpdateCallback;
19 BatteryUpdateCallback; 20 typedef base::CallbackList<void(const BatteryStatus&)>
20 typedef base::CallbackList<void(const blink::WebBatteryStatus&)>
21 BatteryUpdateCallbackList; 21 BatteryUpdateCallbackList;
22 typedef BatteryUpdateCallbackList::Subscription BatteryUpdateSubscription; 22 typedef BatteryUpdateCallbackList::Subscription BatteryUpdateSubscription;
23 23
24 // Returns the BatteryStatusService singleton. 24 // Returns the BatteryStatusService singleton.
25 static BatteryStatusService* GetInstance(); 25 static BatteryStatusService* GetInstance();
26 26
27 // Adds a callback to receive battery status updates. 27 // Adds a callback to receive battery status updates.
28 // Must be called on the I/O thread. 28 // Must be called on the I/O thread.
29 scoped_ptr<BatteryUpdateSubscription> AddCallback( 29 scoped_ptr<BatteryUpdateSubscription> AddCallback(
30 const BatteryUpdateCallback& callback); 30 const BatteryUpdateCallback& callback);
31 31
32 // Gracefully clean-up. 32 // Gracefully clean-up.
33 void Shutdown(); 33 void Shutdown();
34 34
35 // Injects a custom battery status manager for testing purposes. 35 // Injects a custom battery status manager for testing purposes.
36 // This class takes ownership of the injected object. 36 void SetBatteryManagerForTesting(
37 void SetBatteryManagerForTesting(BatteryStatusManager* test_battery_manager); 37 scoped_ptr<BatteryStatusManager> test_battery_manager);
38 38
39 // Returns callback to invoke when battery is changed. Used for testing. 39 // Returns callback to invoke when battery is changed. Used for testing.
40 const BatteryUpdateCallback& GetUpdateCallbackForTesting() const; 40 const BatteryUpdateCallback& GetUpdateCallbackForTesting() const;
41 41
42 private: 42 private:
43 friend struct DefaultSingletonTraits<BatteryStatusService>; 43 friend struct DefaultSingletonTraits<BatteryStatusService>;
44 44
45 BatteryStatusService(); 45 BatteryStatusService();
46 virtual ~BatteryStatusService(); 46 virtual ~BatteryStatusService();
47 47
48 // Updates current battery status and sends new status to interested 48 // Updates current battery status and sends new status to interested
49 // render processes. Can be called on any thread via a callback. 49 // render processes. Can be called on any thread via a callback.
50 void UpdateBatteryStatus(const blink::WebBatteryStatus& status); 50 void NotifyConsumers(const BatteryStatus& status);
51 void NotifyConsumers(const blink::WebBatteryStatus& status);
52 void ConsumersChanged(); 51 void ConsumersChanged();
53 52
54 scoped_ptr<BatteryStatusManager> battery_fetcher_; 53 scoped_ptr<BatteryStatusManager> battery_fetcher_;
55 BatteryUpdateCallbackList callback_list_; 54 BatteryUpdateCallbackList callback_list_;
56 BatteryUpdateCallback update_callback_; 55 BatteryUpdateCallback update_callback_;
57 blink::WebBatteryStatus status_; 56 BatteryStatus status_;
58 bool status_updated_; 57 bool status_updated_;
59 bool is_shutdown_; 58 bool is_shutdown_;
60 59
61 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); 60 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService);
62 }; 61 };
63 62
64 } // namespace content 63 } // namespace device
65 64
66 #endif // CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ 65 #endif // DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_
OLDNEW
« no previous file with comments | « device/battery/battery_status_manager_win_unittest.cc ('k') | device/battery/battery_status_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698