Commit 8b151265 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

AppCache: Reduce dependencies on DocumentLoader from ApplicationCacheHost for shared workers

In the current implementation, WorkerShadowPage provides DocumentLoader to
ApplicationCacheHost for shared workers. This blocks WorkerShadowPage removal
(see the issue). To unblock it, this and subsequent CLs reduce dependencies on
DocumentLoader from ApplicationCacheHost for shared workers.

As the first step, this CL moves ApplicationCacheHost::{Update,SwapCache}() that
are called only on Document to ApplicationCacheHostForFrame.

Bug: 982996
Change-Id: I6599316801e242c63208fcedae0d9feae63d2472
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697261Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676668}
parent 7b4d6c53
......@@ -252,38 +252,8 @@ mojom::AppCacheStatus ApplicationCacheHost::GetStatus() const {
return status_;
}
bool ApplicationCacheHost::Update() {
if (!backend_host_.is_bound())
return false;
bool result = false;
backend_host_->StartUpdate(&result);
if (!result)
return false;
if (status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE ||
status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY) {
status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
} else {
status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
backend_host_->GetStatus(&status_);
}
return true;
}
bool ApplicationCacheHost::SwapCache() {
if (!backend_host_.is_bound())
return false;
bool success = false;
backend_host_->SwapCache(&success);
if (!success)
return false;
backend_host_->GetStatus(&status_);
probe::UpdateApplicationCacheStatus(document_loader_->GetFrame());
return true;
}
void ApplicationCacheHost::Abort() {
// This is not implemented intentionally. See https://crbug.com/175063
}
bool ApplicationCacheHost::IsApplicationCacheEnabled() {
......
......@@ -92,8 +92,8 @@ class CORE_EXPORT ApplicationCacheHost
void WillStartLoading(ResourceRequest&);
mojom::blink::AppCacheStatus GetStatus() const;
bool Update();
bool SwapCache();
virtual bool Update() { return false; }
virtual bool SwapCache() { return false; }
void Abort();
void SetApplicationCache(ApplicationCache*);
......@@ -128,6 +128,8 @@ class CORE_EXPORT ApplicationCacheHost
virtual void Trace(blink::Visitor*);
protected:
DocumentLoader* GetDocumentLoader() const { return document_loader_; }
mojom::blink::AppCacheHostPtr backend_host_;
mojom::blink::AppCacheStatus status_ =
mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
......@@ -143,7 +145,6 @@ class CORE_EXPORT ApplicationCacheHost
void GetAssociatedCacheInfo(CacheInfo* info);
bool IsApplicationCacheEnabled();
DocumentLoader* GetDocumentLoader() const { return document_loader_; }
bool BindBackend();
void DispatchDOMEvent(mojom::AppCacheEventID,
int progress_total,
......@@ -178,7 +179,10 @@ class CORE_EXPORT ApplicationCacheHost
};
WeakMember<ApplicationCache> dom_application_cache_ = nullptr;
// TODO(https://crbug.com/982996): Move this to ApplicationCacheHostForFrame.
Member<DocumentLoader> document_loader_;
bool defers_events_ =
true; // Events are deferred until after document onload.
Vector<DeferredEvent> deferred_events_;
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/platform/web_test_support.h"
namespace blink {
......@@ -44,6 +45,37 @@ ApplicationCacheHostForFrame::ApplicationCacheHostForFrame(
std::move(task_runner)),
local_frame_(document_loader->GetFrame()) {}
bool ApplicationCacheHostForFrame::Update() {
if (!backend_host_.is_bound())
return false;
bool result = false;
backend_host_->StartUpdate(&result);
if (!result)
return false;
if (status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE ||
status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY) {
status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
} else {
status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
backend_host_->GetStatus(&status_);
}
return true;
}
bool ApplicationCacheHostForFrame::SwapCache() {
if (!backend_host_.is_bound())
return false;
bool success = false;
backend_host_->SwapCache(&success);
if (!success)
return false;
backend_host_->GetStatus(&status_);
probe::UpdateApplicationCacheStatus(GetDocumentLoader()->GetFrame());
return true;
}
void ApplicationCacheHostForFrame::LogMessage(
mojom::blink::ConsoleMessageLevel log_level,
const String& message) {
......
......@@ -19,6 +19,8 @@ class ApplicationCacheHostForFrame final : public ApplicationCacheHost {
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// ApplicationCacheHost:
bool Update() override;
bool SwapCache() override;
void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
const String& message) override;
......
......@@ -16,6 +16,22 @@ ApplicationCacheHostForSharedWorker::ApplicationCacheHostForSharedWorker(
ApplicationCacheHostForSharedWorker::~ApplicationCacheHostForSharedWorker() =
default;
bool ApplicationCacheHostForSharedWorker::Update() {
// ApplicationCacheHost::Update() is called from JavaScript's
// applicationCache.update() that is not exposed to workers.
// https://html.spec.whatwg.org/C/#application-cache-api
NOTREACHED();
return false;
}
bool ApplicationCacheHostForSharedWorker::SwapCache() {
// ApplicationCacheHost::SwapCache() is called from JavaScript's
// applicationCache.swapCache() that is not exposed to workers.
// https://html.spec.whatwg.org/C/#application-cache-api
NOTREACHED();
return false;
}
void ApplicationCacheHostForSharedWorker::LogMessage(
mojom::blink::ConsoleMessageLevel log_level,
const String& message) {}
......
......@@ -17,6 +17,8 @@ class ApplicationCacheHostForSharedWorker final : public ApplicationCacheHost {
~ApplicationCacheHostForSharedWorker() override;
// ApplicationCacheHost:
bool Update() override;
bool SwapCache() override;
void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
const String& message) override;
void SetSubresourceFactory(
......
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