OLD | NEW |
---|---|
(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/BatteryDispatcher.h" | |
7 | |
8 #include "core/events/Event.h" | |
9 #include "modules/battery/BatteryStatus.h" | |
10 #include "public/platform/Platform.h" | |
11 | |
12 namespace WebCore { | |
13 | |
14 BatteryDispatcher& BatteryDispatcher::instance() | |
15 { | |
16 DEFINE_STATIC_LOCAL(BatteryDispatcher, batteryDispatcher, ()); | |
17 return batteryDispatcher; | |
18 } | |
19 | |
20 BatteryDispatcher::BatteryDispatcher() | |
21 { | |
22 } | |
23 | |
24 BatteryDispatcher::~BatteryDispatcher() | |
25 { | |
26 } | |
27 | |
28 void BatteryDispatcher::addClient(BatteryManager* batteryManager) | |
29 { | |
30 addController(batteryManager); | |
31 } | |
32 | |
33 void BatteryDispatcher::removeClient(BatteryManager* batteryManager) | |
34 { | |
35 removeController(batteryManager); | |
36 } | |
37 | |
38 void BatteryDispatcher::updateBatteryStatus(const blink::WebBatteryStatus& batte ryStatus) | |
39 { | |
40 RefPtr<BatteryStatus> status = BatteryStatus::create(batteryStatus.charging, batteryStatus.chargingTime, batteryStatus.dischargingTime, batteryStatus.level) ; | |
41 | |
42 if (m_batteryStatus) { | |
43 if (m_batteryStatus->charging() != status->charging()) | |
44 didChangeBatteryStatus(EventTypeNames::chargingchange, status); | |
45 else if (status->charging() && m_batteryStatus->chargingTime() != status ->chargingTime()) | |
timvolodine
2014/04/02 14:24:51
do you need an 'else if' here? looks like this sho
Srini
2014/04/02 17:25:36
Yes, I think I over thought this. Ill fix this.
| |
46 didChangeBatteryStatus(EventTypeNames::chargingtimechange, status); | |
47 else if (!status->charging() && m_batteryStatus->dischargingTime() != st atus->dischargingTime()) | |
48 didChangeBatteryStatus(EventTypeNames::dischargingtimechange, status ); | |
49 | |
50 if (m_batteryStatus->level() != status->level()) | |
51 didChangeBatteryStatus(EventTypeNames::levelchange, status); | |
52 } else { | |
53 // There was no previous state. | |
54 didChangeBatteryStatus(EventTypeNames::chargingchange, status); | |
55 didChangeBatteryStatus(EventTypeNames::levelchange, status); | |
56 } | |
57 | |
58 m_batteryStatus = status.release(); | |
59 } | |
60 | |
61 void BatteryDispatcher::didChangeBatteryStatus(const AtomicString& eventType, Pa ssRefPtr<BatteryStatus> batteryStatus) | |
62 { | |
63 RefPtr<Event> event = Event::create(eventType); | |
sof
2014/04/07 12:52:44
Change RefPtr<Event> to the Oilpan transition type
| |
64 RefPtr<BatteryStatus> battery = batteryStatus; | |
65 | |
66 { | |
67 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); | |
68 // Don't fire listeners removed or added during event dispatch. | |
69 size_t size = m_controllers.size(); | |
70 for (size_t i = 0; i < size; ++i) { | |
71 if (m_controllers[i]) | |
72 static_cast<BatteryManager*>(m_controllers[i])->didChangeBattery Status(event, battery); | |
73 } | |
74 } | |
75 | |
76 if (m_needsPurge) | |
77 purgeControllers(); | |
78 } | |
79 | |
80 void BatteryDispatcher::startListening() | |
81 { | |
82 // blink::Platform::current()->setBatteryListener(this); | |
83 } | |
84 | |
85 void BatteryDispatcher::stopListening() | |
86 { | |
87 // blink::Platform::current()->setBatteryListener(0); | |
88 } | |
89 | |
90 } | |
OLD | NEW |