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") {
"dom/MutationObserverTest.cpp",
"dom/NodeTest.cpp",
"dom/NthIndexCacheTest.cpp",
"dom/PausableObjectTest.cpp",
"dom/RangeTest.cpp",
"dom/ScriptModuleResolverImplTest.cpp",
"dom/ScriptRunnerTest.cpp",
......@@ -1437,7 +1438,6 @@ jumbo_source_set("unit_tests") {
"dom/ShadowDOMV0Test.cpp",
"dom/SpaceSplitStringTest.cpp",
"dom/StaticRangeTest.cpp",
"dom/SuspendableObjectTest.cpp",
"dom/TextTest.cpp",
"dom/TreeScopeTest.cpp",
"dom/UserGestureIndicatorTest.cpp",
......
......@@ -213,6 +213,8 @@ blink_core_sources("dom") {
"NthIndexCache.h",
"ParentNode.h",
"ParserContentPolicy.h",
"PausableObject.cpp",
"PausableObject.h",
"PendingScript.cpp",
"PendingScript.h",
"PresentationAttributeStyle.cpp",
......@@ -263,7 +265,6 @@ blink_core_sources("dom") {
"StaticNodeList.h",
"StaticRange.cpp",
"StaticRange.h",
"SuspendableObject.cpp",
"SuspendableObject.h",
"SyncReattachContext.cpp",
"SyncReattachContext.h",
......
......@@ -34,9 +34,11 @@
namespace blink {
class SuspendableObject;
class ContextLifecycleObserver;
class ExecutionContext;
class PausableObject;
using SuspendableObject = PausableObject;
class CORE_EXPORT ContextLifecycleNotifier
: public LifecycleNotifier<ExecutionContext, ContextLifecycleObserver> {
......
......@@ -56,11 +56,14 @@ class ErrorEvent;
class EventQueue;
class EventTarget;
class LocalDOMWindow;
class SuspendableObject;
class PausableObject;
class PublicURLManager;
class ResourceFetcher;
class SecurityOrigin;
class ScriptState;
using SuspendableObject = PausableObject;
enum class TaskType : unsigned;
enum ReasonForCallingCanExecuteScripts {
......
......@@ -24,14 +24,14 @@
*
*/
#include "core/dom/SuspendableObject.h"
#include "core/dom/PausableObject.h"
#include "core/dom/ExecutionContext.h"
#include "platform/InstanceCounters.h"
namespace blink {
SuspendableObject::SuspendableObject(ExecutionContext* execution_context)
PausableObject::PausableObject(ExecutionContext* execution_context)
: ContextLifecycleObserver(execution_context, kSuspendableObjectType)
#if DCHECK_IS_ON()
,
......@@ -43,7 +43,7 @@ SuspendableObject::SuspendableObject(ExecutionContext* execution_context)
InstanceCounters::kSuspendableObjectCounter);
}
SuspendableObject::~SuspendableObject() {
PausableObject::~PausableObject() {
InstanceCounters::DecrementCounter(
InstanceCounters::kSuspendableObjectCounter);
......@@ -52,7 +52,7 @@ SuspendableObject::~SuspendableObject() {
#endif
}
void SuspendableObject::SuspendIfNeeded() {
void PausableObject::SuspendIfNeeded() {
#if DCHECK_IS_ON()
DCHECK(!suspend_if_needed_called_);
suspend_if_needed_called_ = true;
......@@ -61,12 +61,11 @@ void SuspendableObject::SuspendIfNeeded() {
context->SuspendSuspendableObjectIfNeeded(this);
}
void SuspendableObject::Suspend() {}
void PausableObject::Suspend() {}
void SuspendableObject::Resume() {}
void PausableObject::Resume() {}
void SuspendableObject::DidMoveToNewExecutionContext(
ExecutionContext* context) {
void PausableObject::DidMoveToNewExecutionContext(ExecutionContext* context) {
SetContext(context);
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 @@
* 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/testing/DummyPageHolder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <memory>
namespace blink {
class MockSuspendableObject final
: public GarbageCollectedFinalized<MockSuspendableObject>,
public SuspendableObject {
USING_GARBAGE_COLLECTED_MIXIN(MockSuspendableObject);
class MockPausableObject final
: public GarbageCollectedFinalized<MockPausableObject>,
public PausableObject {
USING_GARBAGE_COLLECTED_MIXIN(MockPausableObject);
public:
explicit MockSuspendableObject(ExecutionContext* context)
: SuspendableObject(context) {}
explicit MockPausableObject(ExecutionContext* context)
: PausableObject(context) {}
virtual void Trace(blink::Visitor* visitor) {
SuspendableObject::Trace(visitor);
PausableObject::Trace(visitor);
}
MOCK_METHOD0(Suspend, void());
......@@ -56,56 +56,56 @@ class MockSuspendableObject final
MOCK_METHOD1(ContextDestroyed, void(ExecutionContext*));
};
class SuspendableObjectTest : public ::testing::Test {
class PausableObjectTest : public ::testing::Test {
protected:
SuspendableObjectTest();
PausableObjectTest();
Document& SrcDocument() const { return src_page_holder_->GetDocument(); }
Document& DestDocument() const { return dest_page_holder_->GetDocument(); }
MockSuspendableObject& SuspendableObject() { return *suspendable_object_; }
MockPausableObject& PausableObject() { return *pausable_object_; }
private:
std::unique_ptr<DummyPageHolder> src_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))),
dest_page_holder_(DummyPageHolder::Create(IntSize(800, 600))),
suspendable_object_(
new MockSuspendableObject(&src_page_holder_->GetDocument())) {
suspendable_object_->SuspendIfNeeded();
pausable_object_(
new MockPausableObject(&src_page_holder_->GetDocument())) {
pausable_object_->SuspendIfNeeded();
}
TEST_F(SuspendableObjectTest, NewContextObserved) {
TEST_F(PausableObjectTest, NewContextObserved) {
unsigned initial_src_count = SrcDocument().SuspendableObjectCount();
unsigned initial_dest_count = DestDocument().SuspendableObjectCount();
EXPECT_CALL(SuspendableObject(), Resume());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument());
EXPECT_CALL(PausableObject(), Resume());
PausableObject().DidMoveToNewExecutionContext(&DestDocument());
EXPECT_EQ(initial_src_count - 1, SrcDocument().SuspendableObjectCount());
EXPECT_EQ(initial_dest_count + 1, DestDocument().SuspendableObjectCount());
}
TEST_F(SuspendableObjectTest, MoveToActiveDocument) {
EXPECT_CALL(SuspendableObject(), Resume());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument());
TEST_F(PausableObjectTest, MoveToActiveDocument) {
EXPECT_CALL(PausableObject(), Resume());
PausableObject().DidMoveToNewExecutionContext(&DestDocument());
}
TEST_F(SuspendableObjectTest, MoveToSuspendedDocument) {
TEST_F(PausableObjectTest, MoveToSuspendedDocument) {
DestDocument().SuspendScheduledTasks();
EXPECT_CALL(SuspendableObject(), Suspend());
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument());
EXPECT_CALL(PausableObject(), Suspend());
PausableObject().DidMoveToNewExecutionContext(&DestDocument());
}
TEST_F(SuspendableObjectTest, MoveToStoppedDocument) {
TEST_F(PausableObjectTest, MoveToStoppedDocument) {
DestDocument().Shutdown();
EXPECT_CALL(SuspendableObject(), ContextDestroyed(&DestDocument()));
SuspendableObject().DidMoveToNewExecutionContext(&DestDocument());
EXPECT_CALL(PausableObject(), ContextDestroyed(&DestDocument()));
PausableObject().DidMoveToNewExecutionContext(&DestDocument());
}
} // namespace blink
......@@ -27,38 +27,14 @@
#ifndef SuspendableObject_h
#define SuspendableObject_h
#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "platform/wtf/Assertions.h"
#include "core/dom/PausableObject.h"
namespace blink {
class CORE_EXPORT SuspendableObject : public ContextLifecycleObserver {
public:
explicit SuspendableObject(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.
virtual void Suspend();
virtual void Resume();
void DidMoveToNewExecutionContext(ExecutionContext*);
protected:
virtual ~SuspendableObject();
private:
#if DCHECK_IS_ON()
bool suspend_if_needed_called_;
#endif
};
// SuspendableObject is now just an alias to PausableObject, and all
// SuspendableObject will be replaced with PausableObject in near future.
// See crbug/780378.
using SuspendableObject = PausableObject;
} // 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