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) ; | |
timvolodine
2014/04/09 15:19:18
could you just do:
RefPtr<BatteryStatus> oldStatus
Srini
2014/04/09 16:09:57
I thought of this, but then I wanted to find the c
timvolodine
2014/04/09 18:59:02
I am not exactly sure what you mean, can you just
| |
41 | |
42 if (m_batteryStatus) { | |
43 RefPtr<BatteryStatus> oldStatus = m_batteryStatus.release(); | |
44 m_batteryStatus = status.release(); | |
45 | |
46 if (m_batteryStatus->charging() != status->charging()) | |
47 didChangeBatteryStatus(EventTypeNames::chargingchange); | |
48 if (status->charging() && m_batteryStatus->chargingTime() != status->cha rgingTime()) | |
49 didChangeBatteryStatus(EventTypeNames::chargingtimechange); | |
50 if (!status->charging() && m_batteryStatus->dischargingTime() != status- >dischargingTime()) | |
51 didChangeBatteryStatus(EventTypeNames::dischargingtimechange); | |
52 if (m_batteryStatus->level() != status->level()) | |
53 didChangeBatteryStatus(EventTypeNames::levelchange); | |
54 } else { | |
55 // There was no previous state. | |
56 m_batteryStatus = status.release(); | |
57 didChangeBatteryStatus(EventTypeNames::chargingchange); | |
timvolodine
2014/04/09 15:19:18
also fire dischargingchange?
Srini
2014/04/09 16:09:57
This is the first time event fire. I wasn't sure,
timvolodine
2014/04/09 18:59:02
I think you should fire all, if chrome cannot prov
| |
58 didChangeBatteryStatus(EventTypeNames::levelchange); | |
59 } | |
60 | |
61 } | |
62 | |
63 const BatteryStatus* BatteryDispatcher::getLatestData() | |
64 { | |
65 if (m_batteryStatus) | |
timvolodine
2014/04/09 15:19:18
no need for if, just return m_batteryStatus.get();
Srini
2014/04/09 16:09:57
ok.
| |
66 return m_batteryStatus.get(); | |
67 | |
68 return 0; | |
69 } | |
70 | |
71 void BatteryDispatcher::didChangeBatteryStatus(const AtomicString& eventType) | |
72 { | |
73 RefPtrWillBeRawPtr<Event> event = Event::create(eventType); | |
74 | |
75 { | |
76 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); | |
77 // Don't fire listeners removed or added during event dispatch. | |
78 size_t size = m_controllers.size(); | |
79 for (size_t i = 0; i < size; ++i) { | |
80 if (m_controllers[i]) | |
81 static_cast<BatteryManager*>(m_controllers[i])->didChangeBattery Status(event); | |
82 } | |
83 } | |
84 | |
85 if (m_needsPurge) | |
86 purgeControllers(); | |
87 } | |
88 | |
89 void BatteryDispatcher::startListening() | |
90 { | |
91 // blink::Platform::current()->setBatteryListener(this); | |
92 } | |
93 | |
94 void BatteryDispatcher::stopListening() | |
95 { | |
96 // blink::Platform::current()->setBatteryListener(0); | |
97 } | |
98 | |
99 } | |
OLD | NEW |