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

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

Issue 2821443002: Revert of Move ScriptState::GetExecutionContext (Part 5) (Closed)
Patch Set: Revert Created 3 years, 8 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
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"
10 #include "core/events/Event.h" 9 #include "core/events/Event.h"
11 #include "modules/battery/BatteryDispatcher.h" 10 #include "modules/battery/BatteryDispatcher.h"
12 #include "platform/wtf/Assertions.h" 11 #include "platform/wtf/Assertions.h"
13 12
14 namespace blink { 13 namespace blink {
15 14
16 BatteryManager* BatteryManager::Create(ExecutionContext* context) { 15 BatteryManager* BatteryManager::Create(ExecutionContext* context) {
17 BatteryManager* battery_manager = new BatteryManager(context); 16 BatteryManager* battery_manager = new BatteryManager(context);
18 battery_manager->SuspendIfNeeded(); 17 battery_manager->SuspendIfNeeded();
19 return battery_manager; 18 return battery_manager;
20 } 19 }
21 20
22 BatteryManager::~BatteryManager() {} 21 BatteryManager::~BatteryManager() {}
23 22
24 BatteryManager::BatteryManager(ExecutionContext* context) 23 BatteryManager::BatteryManager(ExecutionContext* context)
25 : SuspendableObject(context), 24 : SuspendableObject(context),
26 PlatformEventController(ToDocument(context)->GetFrame()) {} 25 PlatformEventController(ToDocument(context)->GetFrame()) {}
27 26
28 ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) { 27 ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) {
29 if (!battery_property_) { 28 if (!battery_property_) {
30 battery_property_ = new BatteryProperty( 29 battery_property_ = new BatteryProperty(script_state->GetExecutionContext(),
31 ExecutionContext::From(script_state), this, BatteryProperty::kReady); 30 this, BatteryProperty::kReady);
32 31
33 // If the context is in a stopped state already, do not start updating. 32 // If the context is in a stopped state already, do not start updating.
34 if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) { 33 if (!GetExecutionContext() || GetExecutionContext()->IsContextDestroyed()) {
35 battery_property_->Resolve(this); 34 battery_property_->Resolve(this);
36 } else { 35 } else {
37 has_event_listener_ = true; 36 has_event_listener_ = true;
38 StartUpdating(); 37 StartUpdating();
39 } 38 }
40 } 39 }
41 40
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 118 }
120 119
121 DEFINE_TRACE(BatteryManager) { 120 DEFINE_TRACE(BatteryManager) {
122 visitor->Trace(battery_property_); 121 visitor->Trace(battery_property_);
123 PlatformEventController::Trace(visitor); 122 PlatformEventController::Trace(visitor);
124 EventTargetWithInlineData::Trace(visitor); 123 EventTargetWithInlineData::Trace(visitor);
125 SuspendableObject::Trace(visitor); 124 SuspendableObject::Trace(visitor);
126 } 125 }
127 126
128 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698