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

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: Removed ActiveDOMWindow and added ContextLifeCycleObserver and other minor fixes. 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/events/Event.h"
10 #include "modules/battery/BatteryStatus.h"
11 #include <limits>
12
13 namespace WebCore {
14
15 PassRefPtr<BatteryManager> BatteryManager::create(ExecutionContext* context)
16 {
17 RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(context))) ;
18
19 return batteryManager.release();
abarth-chromium 2014/03/04 06:42:12 There's no need for this local variable. You can
20 }
21
22 BatteryManager::~BatteryManager()
23 {
24 }
25
26 BatteryManager::BatteryManager(ExecutionContext* context)
27 : ContextLifecycleObserver(context)
28 , m_batteryStatus(nullptr)
29 {
30 }
31
32 void BatteryManager::contextDestroyed()
33 {
34 ContextLifecycleObserver::contextDestroyed();
35 }
abarth-chromium 2014/03/04 06:42:12 There's no need for this override. You're just fo
36
37 bool BatteryManager::charging()
38 {
39 return m_batteryStatus ? m_batteryStatus->charging() : true;
40 }
41
42 double BatteryManager::chargingTime()
43 {
44 if (!m_batteryStatus || !m_batteryStatus->charging())
45 return std::numeric_limits<double>::infinity();
46
47 return m_batteryStatus->chargingTime();
48 }
49
50 double BatteryManager::dischargingTime()
51 {
52 if (!m_batteryStatus || m_batteryStatus->charging())
53 return std::numeric_limits<double>::infinity();
54
55 return m_batteryStatus->dischargingTime();
56 }
57
58 double BatteryManager::level()
59 {
60 return m_batteryStatus ? m_batteryStatus->level() : 1;
61 }
62
63 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassOwnPtr< BatteryStatus> batteryStatus)
64 {
65 ASSERT(RuntimeEnabledFeatures::batteryStatusEnabled());
66
67 m_batteryStatus = batteryStatus;
68 dispatchEvent(event);
69 }
70
71 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698