Commit 9ccbce94 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Remove InterfaceInvalidator & RevocableInterfacePtr

RevocableInterfacePtr was never completed to provide what it needed to.
As well it needed to be written to use new mojo definitions. It was
decided to just remove its use at this time.

BUG=978694

Change-Id: I7632be4f8d6f164fd47c1cf985f3a52978b02999
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841736
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#703736}
parent 5e7f7e8a
......@@ -63,7 +63,6 @@
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/mojo/interface_invalidator.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
......@@ -974,27 +973,6 @@ TEST_F(DocumentTest, ViewportPropagationNoRecalc) {
EXPECT_EQ(1, new_element_count - old_element_count);
}
class InvalidatorObserver : public InterfaceInvalidator::Observer {
public:
void OnInvalidate() override { ++invalidate_called_counter_; }
int CountInvalidateCalled() const { return invalidate_called_counter_; }
private:
int invalidate_called_counter_ = 0;
};
TEST_F(DocumentTest, InterfaceInvalidatorDestruction) {
InvalidatorObserver obs;
InterfaceInvalidator* invalidator = GetDocument().GetInterfaceInvalidator();
invalidator->AddObserver(&obs);
EXPECT_EQ(obs.CountInvalidateCalled(), 0);
GetDocument().Shutdown();
EXPECT_FALSE(GetDocument().GetInterfaceInvalidator());
EXPECT_EQ(1, obs.CountInvalidateCalled());
}
// Test fixture parameterized on whether the "IsolatedWorldCSP" feature is
// enabled.
class IsolatedWorldCSPTest : public DocumentTest,
......
......@@ -46,7 +46,6 @@
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/mojo/interface_invalidator.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/weborigin/security_policy.h"
......@@ -64,8 +63,7 @@ ExecutionContext::ExecutionContext(v8::Isolate* isolate,
agent_(agent),
origin_trial_context_(origin_trial_context),
window_interaction_tokens_(0),
referrer_policy_(network::mojom::ReferrerPolicy::kDefault),
invalidator_(std::make_unique<InterfaceInvalidator>()) {
referrer_policy_(network::mojom::ReferrerPolicy::kDefault) {
if (origin_trial_context_)
origin_trial_context_->BindExecutionContext(this);
}
......@@ -107,7 +105,6 @@ void ExecutionContext::SetLifecycleState(mojom::FrameLifecycleState state) {
void ExecutionContext::NotifyContextDestroyed() {
is_context_destroyed_ = true;
invalidator_.reset();
ContextLifecycleNotifier::NotifyContextDestroyed();
}
......
......@@ -71,7 +71,6 @@ class DOMTimerCoordinator;
class ErrorEvent;
class EventTarget;
class FrameOrWorkerScheduler;
class InterfaceInvalidator;
class KURL;
class LocalDOMWindow;
class OriginTrialContext;
......@@ -287,8 +286,6 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier,
virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
TaskType) = 0;
InterfaceInvalidator* GetInterfaceInvalidator() { return invalidator_.get(); }
v8::Isolate* GetIsolate() const { return isolate_; }
Agent* GetAgent() const { return agent_; }
......@@ -352,8 +349,6 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier,
network::mojom::ReferrerPolicy referrer_policy_;
std::unique_ptr<InterfaceInvalidator> invalidator_;
// Tracks which feature policies have already been parsed, so as not to count
// them multiple times.
// The size of this vector is 0 until FeaturePolicyFeatureObserved is called.
......
......@@ -21,8 +21,6 @@ void ViewportData::Trace(Visitor* visitor) {
}
void ViewportData::Shutdown() {
// TODO(https://crbug.com/800641): Use InterfaceInvalidator once it works with
// associated interfaces.
display_cutout_host_.reset();
}
......
......@@ -1227,10 +1227,7 @@ jumbo_component("platform") {
"mojo/canonical_cookie_mojom_traits.cc",
"mojo/canonical_cookie_mojom_traits.h",
"mojo/fetch_api_request_headers_mojom_traits.h",
"mojo/interface_invalidator.cc",
"mojo/interface_invalidator.h",
"mojo/mojo_helper.h",
"mojo/revocable_interface_ptr.h",
"mojo/string16_mojom_traits.cc",
"mojo/string16_mojom_traits.h",
"p2p/empty_network_manager.cc",
......@@ -1845,7 +1842,6 @@ jumbo_source_set("blink_platform_unittests_sources") {
"mhtml/mhtml_parser_test.cc",
"mojo/big_string_mojom_traits_test.cc",
"mojo/geometry_mojom_traits_test.cc",
"mojo/interface_invalidator_test.cc",
"mojo/kurl_security_origin_test.cc",
"mojo/string16_mojom_traits_test.cc",
"p2p/filtering_network_manager_test.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/mojo/interface_invalidator.h"
namespace blink {
InterfaceInvalidator::InterfaceInvalidator() {}
InterfaceInvalidator::~InterfaceInvalidator() {
weak_factory_.InvalidateWeakPtrs();
NotifyInvalidate();
}
void InterfaceInvalidator::AddObserver(Observer* observer) {
DCHECK(observer);
observers_.AddObserver(observer);
}
void InterfaceInvalidator::RemoveObserver(const Observer* observer) {
DCHECK(observer);
observers_.RemoveObserver(observer);
}
base::WeakPtr<InterfaceInvalidator> InterfaceInvalidator::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
void InterfaceInvalidator::NotifyInvalidate() {
for (auto& observer : observers_)
observer.OnInvalidate();
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_INTERFACE_INVALIDATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_INTERFACE_INVALIDATOR_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
// Notifies weak interface bindings to be invalidated when this object is
// destroyed.
class PLATFORM_EXPORT InterfaceInvalidator {
USING_FAST_MALLOC(InterfaceInvalidator);
public:
InterfaceInvalidator();
~InterfaceInvalidator();
class Observer {
public:
virtual void OnInvalidate() = 0;
};
void AddObserver(Observer*);
void RemoveObserver(const Observer*);
base::WeakPtr<InterfaceInvalidator> GetWeakPtr();
private:
void NotifyInvalidate();
base::ObserverList<Observer>::Unchecked observers_;
base::WeakPtrFactory<InterfaceInvalidator> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(InterfaceInvalidator);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_INTERFACE_INVALIDATOR_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_REVOCABLE_INTERFACE_PTR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_REVOCABLE_INTERFACE_PTR_H_
#include <stdint.h>
#include <cstddef>
#include <string>
#include <utility>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/connection_error_callback.h"
#include "mojo/public/cpp/bindings/interface_ptr_info.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/lib/interface_ptr_state.h"
#include "third_party/blink/renderer/platform/mojo/interface_invalidator.h"
namespace blink {
// RevocableInterfacePtr is a wrapper around an InterfacePtr that has to be tied
// to an InterfaceInvalidator when bound to a message pipe. The underlying
// connection is closed once the InterfaceInvalidator is destroyed and the
// interface will behave as if its peer had closed the connection. This is
// useful for tying the lifetime of interface pointers to another object.
template <typename Interface>
class RevocableInterfacePtr : public InterfaceInvalidator::Observer {
public:
using PtrType = mojo::InterfacePtr<Interface>;
using PtrInfoType = mojo::InterfacePtrInfo<Interface>;
using Proxy = typename Interface::Proxy_;
// Constructs an unbound RevocableInterfacePtr.
RevocableInterfacePtr() {}
RevocableInterfacePtr(std::nullptr_t) {}
// Takes over the binding of another RevocableInterfacePtr.
RevocableInterfacePtr(RevocableInterfacePtr&& other) {
interface_ptr_ = std::move(other.interface_ptr_);
SetInvalidator(other.invalidator_.get());
// Reset the other interface ptr to remove it as an observer of the
// invalidator.
other.reset();
}
RevocableInterfacePtr(
PtrInfoType info,
InterfaceInvalidator* invalidator,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Bind(std::move(info), invalidator, task_runner);
}
// Takes over the binding of another RevocableInterfacePtr, and closes any
// message pipe already bound to this pointer.
RevocableInterfacePtr& operator=(RevocableInterfacePtr&& other) {
reset();
interface_ptr_ = std::move(other.interface_ptr_);
SetInvalidator(other.invalidator_.get());
// Reset the other interface ptr to remove it as an observer of the
// invalidator.
other.reset();
return *this;
}
// Assigning nullptr to this class causes it to close the currently bound
// message pipe (if any) and returns the pointer to the unbound state.
RevocableInterfacePtr& operator=(std::nullptr_t) {
reset();
return *this;
}
// Closes the bound message pipe (if any) on destruction.
~RevocableInterfacePtr() {
if (invalidator_) {
invalidator_->RemoveObserver(this);
}
}
// Binds the RevocableInterfacePtr to a remote implementation of Interface.
//
// Calling with an invalid |info| (containing an invalid message pipe handle)
// has the same effect as reset(). In this case, the InterfacePtr is not
// considered as bound.
//
// |runner| must belong to the same thread. It will be used to dispatch all
// callbacks and connection error notification. It is useful when you attach
// multiple task runners to a single thread for the purposes of task
// scheduling.
void Bind(PtrInfoType info,
InterfaceInvalidator* invalidator,
scoped_refptr<base::SingleThreadTaskRunner> runner = nullptr) {
DCHECK(invalidator);
reset();
if (info.is_valid()) {
interface_ptr_.Bind(std::move(info), std::move(runner));
invalidator_ = invalidator->GetWeakPtr();
invalidator_->AddObserver(this);
}
}
// Returns a raw pointer to the local proxy. Caller does not take ownership.
// Note that the local proxy is thread hostile, as stated above.
Proxy* get() const { return interface_ptr_.get(); }
// Functions like a pointer to Interface. Must already be bound.
Proxy* operator->() const { return get(); }
Proxy& operator*() const { return *get(); }
// Returns the version number of the interface that the remote side supports.
uint32_t version() const { return interface_ptr_.version(); }
// Queries the max version that the remote side supports. On completion, the
// result will be returned as the input of |callback|. The version number of
// this interface pointer will also be updated.
void QueryVersion(const base::RepeatingCallback<void(uint32_t)>& callback) {
interface_ptr_.QueryVersion(callback);
}
// If the remote side doesn't support the specified version, it will close its
// end of the message pipe asynchronously. This does nothing if it's already
// known that the remote side supports the specified version, i.e., if
// |version <= this->version()|.
//
// After calling RequireVersion() with a version not supported by the remote
// side, all subsequent calls to interface methods will be ignored.
void RequireVersion(uint32_t version) {
interface_ptr_.RequireVersion(version);
}
// Sends a no-op message on the underlying message pipe and runs the current
// message loop until its response is received. This can be used in tests to
// verify that no message was sent on a message pipe in response to some
// stimulus.
void FlushForTesting() { interface_ptr_.FlushForTesting(); }
// Closes the bound message pipe, if any.
void reset() {
interface_ptr_.reset();
SetInvalidator(nullptr);
}
// Similar to the method above, but also specifies a disconnect reason.
void ResetWithReason(uint32_t custom_reason, const std::string& description) {
interface_ptr_.ResetWithReason(custom_reason, description);
SetInvalidator(nullptr);
}
// Whether there are any associated interfaces running on the pipe currently.
bool HasAssociatedInterfaces() const {
return interface_ptr_.HasAssociatedInterfaces();
}
// Indicates whether the message pipe has encountered an error. If true,
// method calls made on this interface will be dropped (and may already have
// been dropped).
bool encountered_error() const { return interface_ptr_.encountered_error(); }
// Registers a handler to receive error notifications. The handler will be
// called from the sequence that owns this RevocableInterfacePtr.
//
// This method may only be called after the RevocableInterfacePtr has been
// bound to a message pipe.
void set_connection_error_handler(base::OnceClosure error_handler) {
interface_ptr_.set_connection_error_handler(std::move(error_handler));
}
void set_connection_error_with_reason_handler(
mojo::ConnectionErrorWithReasonCallback error_handler) {
interface_ptr_.set_connection_error_with_reason_handler(
std::move(error_handler));
}
// Unbinds the RevocableInterfacePtr and returns the information which could
// be used to setup a RevocableInterfacePtr again. See comments on
// InterfacePtr::PassInterface for details.
PtrInfoType PassInterface() {
SetInvalidator(nullptr);
return interface_ptr_.PassInterface();
}
bool operator==(const RevocableInterfacePtr& other) const {
if (this == &other)
return true;
// Now that the two refer to different objects, they are equivalent if
// and only if they are both null.
return !(*this) && !other;
}
// Allow RevocableInterfacePtr<> to be used in boolean expressions.
explicit operator bool() const { return static_cast<bool>(interface_ptr_); }
private:
// InterfaceInvalidator::Observer
void OnInvalidate() override {
interface_ptr_.internal_state()->RaiseError();
if (invalidator_) {
invalidator_->RemoveObserver(this);
}
invalidator_.reset();
}
// Replaces the existing invalidator with a new invalidator and changes the
// invalidator being observed.
void SetInvalidator(InterfaceInvalidator* invalidator) {
if (invalidator_)
invalidator_->RemoveObserver(this);
invalidator_.reset();
if (invalidator) {
invalidator_ = invalidator->GetWeakPtr();
invalidator_->AddObserver(this);
}
}
PtrType interface_ptr_;
base::WeakPtr<InterfaceInvalidator> invalidator_;
DISALLOW_COPY_AND_ASSIGN(RevocableInterfacePtr);
};
template <typename Interface>
mojo::InterfaceRequest<Interface> MakeRequest(
RevocableInterfacePtr<Interface>* ptr,
InterfaceInvalidator* invalidator,
scoped_refptr<base::SingleThreadTaskRunner> runner = nullptr) {
mojo::MessagePipe pipe;
ptr->Bind(mojo::InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u),
invalidator, std::move(runner));
return mojo::InterfaceRequest<Interface>(std::move(pipe.handle1));
}
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_REVOCABLE_INTERFACE_PTR_H_
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