Commit 22bdcdd3 authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Rename SuspendableObject to PausableObject and keep SuspendablObject as an alias

This is the first step to replace all SuspendableObject with PausableObject.

This CL is part of the giant CL https://chromium-review.googlesource.com/c/chromium/src/+/748663

Bug: 780378
Change-Id: I76781b850f8a1c71f4a01178d3fd7432534adc06
Reviewed-on: https://chromium-review.googlesource.com/749022Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513099}
parent f975d25e
...@@ -1429,6 +1429,7 @@ jumbo_source_set("unit_tests") { ...@@ -1429,6 +1429,7 @@ jumbo_source_set("unit_tests") {
"dom/MutationObserverTest.cpp", "dom/MutationObserverTest.cpp",
"dom/NodeTest.cpp", "dom/NodeTest.cpp",
"dom/NthIndexCacheTest.cpp", "dom/NthIndexCacheTest.cpp",
"dom/PausableObjectTest.cpp",
"dom/RangeTest.cpp", "dom/RangeTest.cpp",
"dom/ScriptModuleResolverImplTest.cpp", "dom/ScriptModuleResolverImplTest.cpp",
"dom/ScriptRunnerTest.cpp", "dom/ScriptRunnerTest.cpp",
...@@ -1437,7 +1438,6 @@ jumbo_source_set("unit_tests") { ...@@ -1437,7 +1438,6 @@ jumbo_source_set("unit_tests") {
"dom/ShadowDOMV0Test.cpp", "dom/ShadowDOMV0Test.cpp",
"dom/SpaceSplitStringTest.cpp", "dom/SpaceSplitStringTest.cpp",
"dom/StaticRangeTest.cpp", "dom/StaticRangeTest.cpp",
"dom/SuspendableObjectTest.cpp",
"dom/TextTest.cpp", "dom/TextTest.cpp",
"dom/TreeScopeTest.cpp", "dom/TreeScopeTest.cpp",
"dom/UserGestureIndicatorTest.cpp", "dom/UserGestureIndicatorTest.cpp",
......
...@@ -213,6 +213,8 @@ blink_core_sources("dom") { ...@@ -213,6 +213,8 @@ blink_core_sources("dom") {
"NthIndexCache.h", "NthIndexCache.h",
"ParentNode.h", "ParentNode.h",
"ParserContentPolicy.h", "ParserContentPolicy.h",
"PausableObject.cpp",
"PausableObject.h",
"PendingScript.cpp", "PendingScript.cpp",
"PendingScript.h", "PendingScript.h",
"PresentationAttributeStyle.cpp", "PresentationAttributeStyle.cpp",
...@@ -263,7 +265,6 @@ blink_core_sources("dom") { ...@@ -263,7 +265,6 @@ blink_core_sources("dom") {
"StaticNodeList.h", "StaticNodeList.h",
"StaticRange.cpp", "StaticRange.cpp",
"StaticRange.h", "StaticRange.h",
"SuspendableObject.cpp",
"SuspendableObject.h", "SuspendableObject.h",
"SyncReattachContext.cpp", "SyncReattachContext.cpp",
"SyncReattachContext.h", "SyncReattachContext.h",
......
...@@ -34,9 +34,11 @@ ...@@ -34,9 +34,11 @@
namespace blink { namespace blink {
class SuspendableObject;
class ContextLifecycleObserver; class ContextLifecycleObserver;
class ExecutionContext; class ExecutionContext;
class PausableObject;
using SuspendableObject = PausableObject;
class CORE_EXPORT ContextLifecycleNotifier class CORE_EXPORT ContextLifecycleNotifier
: public LifecycleNotifier<ExecutionContext, ContextLifecycleObserver> { : public LifecycleNotifier<ExecutionContext, ContextLifecycleObserver> {
......
...@@ -56,11 +56,14 @@ class ErrorEvent; ...@@ -56,11 +56,14 @@ class ErrorEvent;
class EventQueue; class EventQueue;
class EventTarget; class EventTarget;
class LocalDOMWindow; class LocalDOMWindow;
class SuspendableObject; class PausableObject;
class PublicURLManager; class PublicURLManager;
class ResourceFetcher; class ResourceFetcher;
class SecurityOrigin; class SecurityOrigin;
class ScriptState; class ScriptState;
using SuspendableObject = PausableObject;
enum class TaskType : unsigned; enum class TaskType : unsigned;
enum ReasonForCallingCanExecuteScripts { enum ReasonForCallingCanExecuteScripts {
......
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
* *
*/ */
#include "core/dom/SuspendableObject.h" #include "core/dom/PausableObject.h"
#include "core/dom/ExecutionContext.h" #include "core/dom/ExecutionContext.h"
#include "platform/InstanceCounters.h" #include "platform/InstanceCounters.h"
namespace blink { namespace blink {
SuspendableObject::SuspendableObject(ExecutionContext* execution_context) PausableObject::PausableObject(ExecutionContext* execution_context)
: ContextLifecycleObserver(execution_context, kSuspendableObjectType) : ContextLifecycleObserver(execution_context, kSuspendableObjectType)
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
, ,
...@@ -43,7 +43,7 @@ SuspendableObject::SuspendableObject(ExecutionContext* execution_context) ...@@ -43,7 +43,7 @@ SuspendableObject::SuspendableObject(ExecutionContext* execution_context)
InstanceCounters::kSuspendableObjectCounter); InstanceCounters::kSuspendableObjectCounter);
} }
SuspendableObject::~SuspendableObject() { PausableObject::~PausableObject() {
InstanceCounters::DecrementCounter( InstanceCounters::DecrementCounter(
InstanceCounters::kSuspendableObjectCounter); InstanceCounters::kSuspendableObjectCounter);
...@@ -52,7 +52,7 @@ SuspendableObject::~SuspendableObject() { ...@@ -52,7 +52,7 @@ SuspendableObject::~SuspendableObject() {
#endif #endif
} }
void SuspendableObject::SuspendIfNeeded() { void PausableObject::SuspendIfNeeded() {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK(!suspend_if_needed_called_); DCHECK(!suspend_if_needed_called_);
suspend_if_needed_called_ = true; suspend_if_needed_called_ = true;
...@@ -61,12 +61,11 @@ void SuspendableObject::SuspendIfNeeded() { ...@@ -61,12 +61,11 @@ void SuspendableObject::SuspendIfNeeded() {
context->SuspendSuspendableObjectIfNeeded(this); context->SuspendSuspendableObjectIfNeeded(this);
} }
void SuspendableObject::Suspend() {} void PausableObject::Suspend() {}
void SuspendableObject::Resume() {} void PausableObject::Resume() {}
void SuspendableObject::DidMoveToNewExecutionContext( void PausableObject::DidMoveToNewExecutionContext(ExecutionContext* context) {
ExecutionContext* context) {
SetContext(context); SetContext(context);
if (context->IsContextDestroyed()) { if (context->IsContextDestroyed()) {
......
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef PausableObject_h
#define PausableObject_h
#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "platform/wtf/Assertions.h"
namespace blink {
class CORE_EXPORT PausableObject : public ContextLifecycleObserver {
public:
explicit PausableObject(ExecutionContext*);
// suspendIfNeeded() should be called exactly once after object construction
// to synchronize the suspend state with that in ExecutionContext.
void SuspendIfNeeded();
#if DCHECK_IS_ON()
bool SuspendIfNeededCalled() const { return suspend_if_needed_called_; }
#endif
// These methods have an empty default implementation so that subclasses
// which don't need special treatment can skip implementation.
// TODO(hajimehoshi): Rename Suspend to Pause (crbug/780378)
virtual void Suspend();
virtual void Resume();
void DidMoveToNewExecutionContext(ExecutionContext*);
protected:
virtual ~PausableObject();
private:
#if DCHECK_IS_ON()
bool suspend_if_needed_called_;
#endif
};
} // namespace blink
#endif // PausableObject_h
...@@ -28,27 +28,27 @@ ...@@ -28,27 +28,27 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "core/dom/SuspendableObject.h" #include "core/dom/PausableObject.h"
#include <memory>
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/testing/DummyPageHolder.h" #include "core/testing/DummyPageHolder.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include <memory>
namespace blink { namespace blink {
class MockSuspendableObject final class MockPausableObject final
: public GarbageCollectedFinalized<MockSuspendableObject>, : public GarbageCollectedFinalized<MockPausableObject>,
public SuspendableObject { public PausableObject {
USING_GARBAGE_COLLECTED_MIXIN(MockSuspendableObject); USING_GARBAGE_COLLECTED_MIXIN(MockPausableObject);
public: public:
explicit MockSuspendableObject(ExecutionContext* context) explicit MockPausableObject(ExecutionContext* context)
: SuspendableObject(context) {} : PausableObject(context) {}
virtual void Trace(blink::Visitor* visitor) { virtual void Trace(blink::Visitor* visitor) {
SuspendableObject::Trace(visitor); PausableObject::Trace(visitor);
} }
MOCK_METHOD0(Suspend, void()); MOCK_METHOD0(Suspend, void());
...@@ -56,56 +56,56 @@ class MockSuspendableObject final ...@@ -56,56 +56,56 @@ class MockSuspendableObject final
MOCK_METHOD1(ContextDestroyed, void(ExecutionContext*)); MOCK_METHOD1(ContextDestroyed, void(ExecutionContext*));
}; };
class SuspendableObjectTest : public ::testing::Test { class PausableObjectTest : public ::testing::Test {
protected: protected:
SuspendableObjectTest(); PausableObjectTest();
Document& SrcDocument() const { return src_page_holder_->GetDocument(); } Document& SrcDocument() const { return src_page_holder_->GetDocument(); }
Document& DestDocument() const { return dest_page_holder_->GetDocument(); } Document& DestDocument() const { return dest_page_holder_->GetDocument(); }
MockSuspendableObject& SuspendableObject() { return *suspendable_object_; } MockPausableObject& PausableObject() { return *pausable_object_; }
private: private:
std::unique_ptr<DummyPageHolder> src_page_holder_; std::unique_ptr<DummyPageHolder> src_page_holder_;
std::unique_ptr<DummyPageHolder> dest_page_holder_; std::unique_ptr<DummyPageHolder> dest_page_holder_;
Persistent<MockSuspendableObject> suspendable_object_; Persistent<MockPausableObject> pausable_object_;
}; };
SuspendableObjectTest::SuspendableObjectTest() PausableObjectTest::PausableObjectTest()
: src_page_holder_(DummyPageHolder::Create(IntSize(800, 600))), : src_page_holder_(DummyPageHolder::Create(IntSize(800, 600))),
dest_page_holder_(DummyPageHolder::Create(IntSize(800, 600))), dest_page_holder_(DummyPageHolder::Create(IntSize(800, 600))),
suspendable_object_( pausable_object_(
new MockSuspendableObject(&src_page_holder_->GetDocument())) { new MockPausableObject(&src_page_holder_->GetDocument())) {
suspendable_object_->SuspendIfNeeded(); pausable_object_->SuspendIfNeeded();
} }
TEST_F(SuspendableObjectTest, NewContextObserved) { TEST_F(PausableObjectTest, NewContextObserved) {
unsigned initial_src_count = SrcDocument().SuspendableObjectCount(); unsigned initial_src_count = SrcDocument().SuspendableObjectCount();
unsigned initial_dest_count = DestDocument().SuspendableObjectCount(); unsigned initial_dest_count = DestDocument().SuspendableObjectCount();
EXPECT_CALL(SuspendableObject(), Resume()); EXPECT_CALL(PausableObject(), Resume());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument()); PausableObject().DidMoveToNewExecutionContext(&DestDocument());
EXPECT_EQ(initial_src_count - 1, SrcDocument().SuspendableObjectCount()); EXPECT_EQ(initial_src_count - 1, SrcDocument().SuspendableObjectCount());
EXPECT_EQ(initial_dest_count + 1, DestDocument().SuspendableObjectCount()); EXPECT_EQ(initial_dest_count + 1, DestDocument().SuspendableObjectCount());
} }
TEST_F(SuspendableObjectTest, MoveToActiveDocument) { TEST_F(PausableObjectTest, MoveToActiveDocument) {
EXPECT_CALL(SuspendableObject(), Resume()); EXPECT_CALL(PausableObject(), Resume());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument()); PausableObject().DidMoveToNewExecutionContext(&DestDocument());
} }
TEST_F(SuspendableObjectTest, MoveToSuspendedDocument) { TEST_F(PausableObjectTest, MoveToSuspendedDocument) {
DestDocument().SuspendScheduledTasks(); DestDocument().SuspendScheduledTasks();
EXPECT_CALL(SuspendableObject(), Suspend()); EXPECT_CALL(PausableObject(), Suspend());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument()); PausableObject().DidMoveToNewExecutionContext(&DestDocument());
} }
TEST_F(SuspendableObjectTest, MoveToStoppedDocument) { TEST_F(PausableObjectTest, MoveToStoppedDocument) {
DestDocument().Shutdown(); DestDocument().Shutdown();
EXPECT_CALL(SuspendableObject(), ContextDestroyed(&DestDocument())); EXPECT_CALL(PausableObject(), ContextDestroyed(&DestDocument()));
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument()); PausableObject().DidMoveToNewExecutionContext(&DestDocument());
} }
} // namespace blink } // namespace blink
...@@ -27,38 +27,14 @@ ...@@ -27,38 +27,14 @@
#ifndef SuspendableObject_h #ifndef SuspendableObject_h
#define SuspendableObject_h #define SuspendableObject_h
#include "core/CoreExport.h" #include "core/dom/PausableObject.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "platform/wtf/Assertions.h"
namespace blink { namespace blink {
class CORE_EXPORT SuspendableObject : public ContextLifecycleObserver { // SuspendableObject is now just an alias to PausableObject, and all
public: // SuspendableObject will be replaced with PausableObject in near future.
explicit SuspendableObject(ExecutionContext*); // See crbug/780378.
using SuspendableObject = PausableObject;
// suspendIfNeeded() should be called exactly once after object construction
// to synchronize the suspend state with that in ExecutionContext.
void SuspendIfNeeded();
#if DCHECK_IS_ON()
bool SuspendIfNeededCalled() const { return suspend_if_needed_called_; }
#endif
// These methods have an empty default implementation so that subclasses
// which don't need special treatment can skip implementation.
virtual void Suspend();
virtual void Resume();
void DidMoveToNewExecutionContext(ExecutionContext*);
protected:
virtual ~SuspendableObject();
private:
#if DCHECK_IS_ON()
bool suspend_if_needed_called_;
#endif
};
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment