Commit d872517c authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate ApplicationCacheHost to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free bugs.

Bug: 1049056
Change-Id: I8b0881035d4ca718c2f973276bf4411356dbfbcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2143888Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759583}
parent fdef2414
...@@ -63,8 +63,12 @@ const char* const kEventNames[] = {"Checking", "Error", "NoUpdate", ...@@ -63,8 +63,12 @@ const char* const kEventNames[] = {"Checking", "Error", "NoUpdate",
ApplicationCacheHost::ApplicationCacheHost( ApplicationCacheHost::ApplicationCacheHost(
const BrowserInterfaceBrokerProxy& interface_broker_proxy, const BrowserInterfaceBrokerProxy& interface_broker_proxy,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner,
: task_runner_(std::move(task_runner)), ContextLifecycleNotifier* notifier)
: backend_host_(notifier),
receiver_(this, notifier),
backend_remote_(notifier),
task_runner_(std::move(task_runner)),
interface_broker_proxy_(interface_broker_proxy) {} interface_broker_proxy_(interface_broker_proxy) {}
ApplicationCacheHost::~ApplicationCacheHost() = default; ApplicationCacheHost::~ApplicationCacheHost() = default;
...@@ -230,6 +234,12 @@ void ApplicationCacheHost::ErrorEventRaised( ...@@ -230,6 +234,12 @@ void ApplicationCacheHost::ErrorEventRaised(
} }
} }
void ApplicationCacheHost::Trace(Visitor* visitor) {
visitor->Trace(backend_host_);
visitor->Trace(receiver_);
visitor->Trace(backend_remote_);
}
void ApplicationCacheHost::GetAssociatedCacheInfo( void ApplicationCacheHost::GetAssociatedCacheInfo(
ApplicationCacheHost::CacheInfo* info) { ApplicationCacheHost::CacheInfo* info) {
if (!backend_host_.is_bound()) if (!backend_host_.is_bound())
......
...@@ -36,15 +36,17 @@ ...@@ -36,15 +36,17 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
#include "third_party/blink/public/mojom/appcache/appcache_info.mojom-blink-forward.h" #include "third_party/blink/public/mojom/appcache/appcache_info.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink-forward.h" #include "third_party/blink/public/mojom/devtools/console_message.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/context_lifecycle_notifier.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_response.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_response.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_wrapper_mode.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
...@@ -57,7 +59,8 @@ class CORE_EXPORT ApplicationCacheHost ...@@ -57,7 +59,8 @@ class CORE_EXPORT ApplicationCacheHost
public: public:
ApplicationCacheHost( ApplicationCacheHost(
const BrowserInterfaceBrokerProxy& interface_broker_proxy, const BrowserInterfaceBrokerProxy& interface_broker_proxy,
scoped_refptr<base::SingleThreadTaskRunner> task_runner); scoped_refptr<base::SingleThreadTaskRunner> task_runner,
ContextLifecycleNotifier* notifier);
~ApplicationCacheHost() override; ~ApplicationCacheHost() override;
virtual void Detach(); virtual void Detach();
...@@ -108,10 +111,12 @@ class CORE_EXPORT ApplicationCacheHost ...@@ -108,10 +111,12 @@ class CORE_EXPORT ApplicationCacheHost
mojo::PendingRemote<network::mojom::blink::URLLoaderFactory> mojo::PendingRemote<network::mojom::blink::URLLoaderFactory>
url_loader_factory) override {} url_loader_factory) override {}
virtual void Trace(Visitor*) {} virtual void Trace(Visitor*);
protected: protected:
mojo::Remote<mojom::blink::AppCacheHost> backend_host_; HeapMojoRemote<mojom::blink::AppCacheHost,
HeapMojoWrapperMode::kWithoutContextObserver>
backend_host_;
mojom::blink::AppCacheStatus status_ = mojom::blink::AppCacheStatus status_ =
mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED; mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
...@@ -129,8 +134,13 @@ class CORE_EXPORT ApplicationCacheHost ...@@ -129,8 +134,13 @@ class CORE_EXPORT ApplicationCacheHost
void GetAssociatedCacheInfo(CacheInfo* info); void GetAssociatedCacheInfo(CacheInfo* info);
mojo::Receiver<mojom::blink::AppCacheFrontend> receiver_{this}; HeapMojoReceiver<mojom::blink::AppCacheFrontend,
mojo::Remote<mojom::blink::AppCacheBackend> backend_remote_; ApplicationCacheHost,
HeapMojoWrapperMode::kWithoutContextObserver>
receiver_;
HeapMojoRemote<mojom::blink::AppCacheBackend,
HeapMojoWrapperMode::kWithoutContextObserver>
backend_remote_;
base::UnguessableToken host_id_; base::UnguessableToken host_id_;
mojom::blink::AppCacheInfo cache_info_; mojom::blink::AppCacheInfo cache_info_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/events/application_cache_error_event.h" #include "third_party/blink/renderer/core/events/application_cache_error_event.h"
#include "third_party/blink/renderer/core/events/progress_event.h" #include "third_party/blink/renderer/core/events/progress_event.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
...@@ -47,7 +48,9 @@ ApplicationCacheHostForFrame::ApplicationCacheHostForFrame( ...@@ -47,7 +48,9 @@ ApplicationCacheHostForFrame::ApplicationCacheHostForFrame(
const BrowserInterfaceBrokerProxy& interface_broker_proxy, const BrowserInterfaceBrokerProxy& interface_broker_proxy,
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const base::UnguessableToken& appcache_host_id) const base::UnguessableToken& appcache_host_id)
: ApplicationCacheHost(interface_broker_proxy, std::move(task_runner)), : ApplicationCacheHost(interface_broker_proxy,
std::move(task_runner),
document_loader->GetFrame()->DomWindow()),
local_frame_(document_loader->GetFrame()), local_frame_(document_loader->GetFrame()),
document_loader_(document_loader) { document_loader_(document_loader) {
// PlzNavigate: The browser passes the ID to be used. // PlzNavigate: The browser passes the ID to be used.
......
...@@ -9,8 +9,11 @@ namespace blink { ...@@ -9,8 +9,11 @@ namespace blink {
ApplicationCacheHostForWorker::ApplicationCacheHostForWorker( ApplicationCacheHostForWorker::ApplicationCacheHostForWorker(
const base::UnguessableToken& appcache_host_id, const base::UnguessableToken& appcache_host_id,
const BrowserInterfaceBrokerProxy& interface_broker_proxy, const BrowserInterfaceBrokerProxy& interface_broker_proxy,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner,
: ApplicationCacheHost(interface_broker_proxy, std::move(task_runner)) { ContextLifecycleNotifier* notifier)
: ApplicationCacheHost(interface_broker_proxy,
std::move(task_runner),
notifier) {
SetHostID(appcache_host_id ? appcache_host_id SetHostID(appcache_host_id ? appcache_host_id
: base::UnguessableToken::Create()); : base::UnguessableToken::Create());
BindBackend(); BindBackend();
......
...@@ -14,7 +14,8 @@ class ApplicationCacheHostForWorker final : public ApplicationCacheHost { ...@@ -14,7 +14,8 @@ class ApplicationCacheHostForWorker final : public ApplicationCacheHost {
ApplicationCacheHostForWorker( ApplicationCacheHostForWorker(
const base::UnguessableToken& appcache_host_id, const base::UnguessableToken& appcache_host_id,
const BrowserInterfaceBrokerProxy& interface_broker_proxy, const BrowserInterfaceBrokerProxy& interface_broker_proxy,
scoped_refptr<base::SingleThreadTaskRunner> task_runner); scoped_refptr<base::SingleThreadTaskRunner> task_runner,
ContextLifecycleNotifier* notifier);
~ApplicationCacheHostForWorker() override; ~ApplicationCacheHostForWorker() override;
}; };
......
...@@ -60,7 +60,7 @@ SharedWorkerGlobalScope::SharedWorkerGlobalScope( ...@@ -60,7 +60,7 @@ SharedWorkerGlobalScope::SharedWorkerGlobalScope(
: WorkerGlobalScope(std::move(creation_params), thread, time_origin) { : WorkerGlobalScope(std::move(creation_params), thread, time_origin) {
appcache_host_ = MakeGarbageCollected<ApplicationCacheHostForWorker>( appcache_host_ = MakeGarbageCollected<ApplicationCacheHostForWorker>(
appcache_host_id, GetBrowserInterfaceBroker(), appcache_host_id, GetBrowserInterfaceBroker(),
GetTaskRunner(TaskType::kInternalLoading)); GetTaskRunner(TaskType::kInternalLoading), this);
} }
SharedWorkerGlobalScope::~SharedWorkerGlobalScope() = default; SharedWorkerGlobalScope::~SharedWorkerGlobalScope() = default;
......
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