| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/battery/BatteryManager.h" | 5 #include "modules/battery/BatteryManager.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/events/Event.h" | 10 #include "core/events/Event.h" |
| 10 #include "modules/battery/BatteryDispatcher.h" | 11 #include "modules/battery/BatteryDispatcher.h" |
| 11 #include "platform/wtf/Assertions.h" | 12 #include "platform/wtf/Assertions.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 BatteryManager* BatteryManager::Create(ExecutionContext* context) { | 16 BatteryManager* BatteryManager::Create(ExecutionContext* context) { |
| 16 BatteryManager* battery_manager = new BatteryManager(context); | 17 BatteryManager* battery_manager = new BatteryManager(context); |
| 17 battery_manager->SuspendIfNeeded(); | 18 battery_manager->SuspendIfNeeded(); |
| 18 return battery_manager; | 19 return battery_manager; |
| 19 } | 20 } |
| 20 | 21 |
| 21 BatteryManager::~BatteryManager() {} | 22 BatteryManager::~BatteryManager() {} |
| 22 | 23 |
| 23 BatteryManager::BatteryManager(ExecutionContext* context) | 24 BatteryManager::BatteryManager(ExecutionContext* context) |
| 24 : SuspendableObject(context), | 25 : SuspendableObject(context), |
| 25 PlatformEventController(ToDocument(context)->GetFrame()) {} | 26 PlatformEventController(ToDocument(context)->GetFrame()) {} |
| 26 | 27 |
| 27 ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) { | 28 ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) { |
| 28 if (!battery_property_) { | 29 if (!battery_property_) { |
| 29 battery_property_ = new BatteryProperty(script_state->GetExecutionContext(), | 30 battery_property_ = new BatteryProperty( |
| 30 this, BatteryProperty::kReady); | 31 ExecutionContext::From(script_state), this, BatteryProperty::kReady); |
| 31 | 32 |
| 32 // If the context is in a stopped state already, do not start updating. | 33 // If the context is in a stopped state already, do not start updating. |
| 33 if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) { | 34 if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) { |
| 34 battery_property_->Resolve(this); | 35 battery_property_->Resolve(this); |
| 35 } else { | 36 } else { |
| 36 has_event_listener_ = true; | 37 has_event_listener_ = true; |
| 37 StartUpdating(); | 38 StartUpdating(); |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 119 } |
| 119 | 120 |
| 120 DEFINE_TRACE(BatteryManager) { | 121 DEFINE_TRACE(BatteryManager) { |
| 121 visitor->Trace(battery_property_); | 122 visitor->Trace(battery_property_); |
| 122 PlatformEventController::Trace(visitor); | 123 PlatformEventController::Trace(visitor); |
| 123 EventTargetWithInlineData::Trace(visitor); | 124 EventTargetWithInlineData::Trace(visitor); |
| 124 SuspendableObject::Trace(visitor); | 125 SuspendableObject::Trace(visitor); |
| 125 } | 126 } |
| 126 | 127 |
| 127 } // namespace blink | 128 } // namespace blink |
| OLD | NEW |