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

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

Issue 16298005: Remove Battery Status API support code from Blink (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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
« no previous file with comments | « Source/modules/battery/BatteryManager.h ('k') | Source/modules/battery/BatteryManager.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Samsung Electronics
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "modules/battery/BatteryManager.h"
22
23 #if ENABLE(BATTERY_STATUS)
24
25 #include "core/dom/Document.h"
26 #include "core/dom/Event.h"
27 #include "core/page/Frame.h"
28 #include "core/page/Navigator.h"
29 #include "modules/battery/BatteryController.h"
30 #include "modules/battery/BatteryStatus.h"
31 #include <limits>
32
33 namespace WebCore {
34
35 PassRefPtr<BatteryManager> BatteryManager::create(Navigator* navigator)
36 {
37 RefPtr<BatteryManager> batteryManager(adoptRef(new BatteryManager(navigator) ));
38 batteryManager->suspendIfNeeded();
39 return batteryManager.release();
40 }
41
42 BatteryManager::~BatteryManager()
43 {
44 }
45
46 BatteryManager::BatteryManager(Navigator* navigator)
47 : ActiveDOMObject(navigator->frame()->document())
48 , m_batteryController(BatteryController::from(navigator->frame()->page()))
49 , m_batteryStatus(0)
50 {
51 m_batteryController->addListener(this);
52 }
53
54 bool BatteryManager::charging()
55 {
56 return m_batteryStatus ? m_batteryStatus->charging() : true;
57 }
58
59 double BatteryManager::chargingTime()
60 {
61 if (!m_batteryStatus || !m_batteryStatus->charging())
62 return std::numeric_limits<double>::infinity();
63
64 return m_batteryStatus->chargingTime();
65 }
66
67 double BatteryManager::dischargingTime()
68 {
69 if (!m_batteryStatus || m_batteryStatus->charging())
70 return std::numeric_limits<double>::infinity();
71
72 return m_batteryStatus->dischargingTime();
73 }
74
75 double BatteryManager::level()
76 {
77 return m_batteryStatus ? m_batteryStatus->level() : 1;
78 }
79
80 void BatteryManager::didChangeBatteryStatus(PassRefPtr<Event> event, PassRefPtr< BatteryStatus> batteryStatus)
81 {
82 m_batteryStatus = batteryStatus;
83 dispatchEvent(event);
84 }
85
86 void BatteryManager::suspend(ReasonForSuspension)
87 {
88 if (m_batteryController)
89 m_batteryController->removeListener(this);
90 }
91
92 void BatteryManager::resume()
93 {
94 if (m_batteryController)
95 m_batteryController->addListener(this);
96 }
97
98 void BatteryManager::stop()
99 {
100 if (m_batteryController)
101 m_batteryController->removeListener(this);
102 }
103
104 } // namespace WebCore
105
106 #endif // BATTERY_STATUS
107
OLDNEW
« no previous file with comments | « Source/modules/battery/BatteryManager.h ('k') | Source/modules/battery/BatteryManager.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698