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

Side by Side Diff: Source/modules/battery/BatteryManager.cpp

Issue 182613002: Add support to Battery Status API in blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add to RunTimeEnabledFeatures Created 6 years, 9 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
(Empty)
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.
4
5 #include "config.h"
6 #include "modules/battery/BatteryManager.h"
7
8 #include "RuntimeEnabledFeatures.h"
9 #include "core/dom/Document.h"
10 #include "core/events/Event.h"
11 #include "core/frame/Frame.h"
12 #include "core/frame/Navigator.h"
13 #include "modules/battery/BatteryStatus.h"
14 #include <limits>
15
16 namespace WebCore {
17
18 PassRefPtr<BatteryManager> BatteryManager::create(Frame* frame)
19 {
20 RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(frame)));
21 batteryManager->suspendIfNeeded();
22 return batteryManager.release();
23 }
24
25 BatteryManager::~BatteryManager()
26 {
27 }
28
29 BatteryManager::BatteryManager(Navigator* navigator)
30 : ActiveDOMObject(navigator->frame()->document())
31 , m_batteryStatus(nullptr)
32 {
33 }
34
35 BatteryManager::BatteryManager(Frame* frame)
36 : ActiveDOMObject(frame->document())
abarth-chromium 2014/02/28 06:45:14 Notice that this base class (and ContextDestructio
37 , m_batteryStatus(nullptr)
38 {
39 }
40
41 bool BatteryManager::charging()
42 {
43 return m_batteryStatus ? m_batteryStatus->charging() : true;
44 }
45
46 double BatteryManager::chargingTime()
47 {
48 if (!m_batteryStatus || !m_batteryStatus->charging())
49 return std::numeric_limits<double>::infinity();
50
51 return m_batteryStatus->chargingTime();
52 }
53
54 double BatteryManager::dischargingTime()
55 {
56 if (!m_batteryStatus || m_batteryStatus->charging())
57 return std::numeric_limits<double>::infinity();
58
59 return m_batteryStatus->dischargingTime();
60 }
61
62 double BatteryManager::level()
63 {
64 return m_batteryStatus ? m_batteryStatus->level() : 1;
65 }
66
67 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr< BatteryStatus> batteryStatus)
68 {
69 if (RuntimeEnabledFeatures::batteryStatusEnabled()) {
abarth-chromium 2014/02/28 06:45:14 This check isn't correct. Instead, you should jus
70 m_batteryStatus = batteryStatus;
71 dispatchEvent(event);
72 }
73 }
74
75 void BatteryManager::suspend()
76 {
77 /* Stop listening from the Controller */
78 }
79
80 void BatteryManager::resume()
81 {
82 /* Start listening to the Controller */
83 }
84
85 void BatteryManager::stop()
86 {
87 /* Stop listening from the Controller */
88 }
abarth-chromium 2014/02/28 06:45:14 Please remove these functions. We can add them in
89
90 } // namespace WebCore
91
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698