Commit bb11bdef authored by Han Leon's avatar Han Leon Committed by Commit Bot

[OnionSoup] Remove WebServiceWorkerClientCallbacks - part 1

After https://chromium-review.googlesource.com/c/chromium/src/+/1214709,
now we send GetClient Mojo message from within Blink, no longer need
the GetCallback (one subclass of WebServiceWorkerClientCallbacks) to
help cross the boundary of Content and Blink.

The follow-up CL (part 2) will remove blink::NavigateClientCallback
(another subclass of WebServiceWorkerClientCallbacks), then remove
WebServiceWorkerClientCallbacks completely.

BUG=879019

Change-Id: Ib2c469fc7f7476bd734e14c42850bb16266e37b6
Reviewed-on: https://chromium-review.googlesource.com/1227618
Commit-Queue: Leon Han <leon.han@intel.com>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592361}
parent 39632f92
......@@ -21,25 +21,6 @@
namespace blink {
ServiceWorkerClient* ServiceWorkerClient::Take(
ScriptPromiseResolver*,
std::unique_ptr<WebServiceWorkerClientInfo> web_client) {
if (!web_client)
return nullptr;
switch (web_client->client_type) {
case mojom::ServiceWorkerClientType::kWindow:
return ServiceWorkerWindowClient::Create(*web_client);
case mojom::ServiceWorkerClientType::kSharedWorker:
return ServiceWorkerClient::Create(*web_client);
case mojom::ServiceWorkerClientType::kAll:
NOTREACHED();
return nullptr;
}
NOTREACHED();
return nullptr;
}
ServiceWorkerClient* ServiceWorkerClient::Create(
const WebServiceWorkerClientInfo& info) {
return new ServiceWorkerClient(info);
......
......@@ -17,18 +17,12 @@
namespace blink {
class PostMessageOptions;
class ScriptPromiseResolver;
class ScriptState;
class MODULES_EXPORT ServiceWorkerClient : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
// To be used by CallbackPromiseAdapter.
using WebType = std::unique_ptr<WebServiceWorkerClientInfo>;
static ServiceWorkerClient* Take(ScriptPromiseResolver*,
std::unique_ptr<WebServiceWorkerClientInfo>);
static ServiceWorkerClient* Create(const WebServiceWorkerClientInfo&);
static ServiceWorkerClient* Create(
const mojom::blink::ServiceWorkerClientInfo&);
......
......@@ -40,44 +40,41 @@ mojom::ServiceWorkerClientType GetClientType(const String& type) {
return mojom::ServiceWorkerClientType::kWindow;
}
class GetCallback : public WebServiceWorkerClientCallbacks {
public:
explicit GetCallback(ScriptPromiseResolver* resolver) : resolver_(resolver) {}
~GetCallback() override = default;
void OnSuccess(
std::unique_ptr<WebServiceWorkerClientInfo> web_client) override {
std::unique_ptr<WebServiceWorkerClientInfo> client =
base::WrapUnique(web_client.release());
if (!resolver_->GetExecutionContext() ||
resolver_->GetExecutionContext()->IsContextDestroyed())
return;
if (!client) {
// Resolve the promise with undefined.
resolver_->Resolve();
return;
}
resolver_->Resolve(ServiceWorkerClient::Take(resolver_, std::move(client)));
void DidGetClient(ScriptPromiseResolver* resolver,
mojom::blink::ServiceWorkerClientInfoPtr info) {
if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed()) {
return;
}
void OnError(const WebServiceWorkerError& error) override {
if (!resolver_->GetExecutionContext() ||
resolver_->GetExecutionContext()->IsContextDestroyed())
if (!info) {
// Resolve the promise with undefined.
resolver->Resolve();
return;
}
ServiceWorkerClient* client;
switch (info->client_type) {
case mojom::ServiceWorkerClientType::kWindow:
client = ServiceWorkerWindowClient::Create(*info);
break;
case mojom::ServiceWorkerClientType::kSharedWorker:
client = ServiceWorkerClient::Create(*info);
break;
case mojom::ServiceWorkerClientType::kAll:
NOTREACHED();
return;
resolver_->Reject(ServiceWorkerError::Take(resolver_.Get(), error));
}
private:
Persistent<ScriptPromiseResolver> resolver_;
DISALLOW_COPY_AND_ASSIGN(GetCallback);
};
resolver->Resolve(client);
}
void DidClaim(ScriptPromiseResolver* resolver,
mojom::blink::ServiceWorkerErrorType error,
const String& error_msg) {
if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed())
resolver->GetExecutionContext()->IsContextDestroyed()) {
return;
}
if (error != mojom::blink::ServiceWorkerErrorType::kNone) {
DCHECK(!error_msg.IsNull());
resolver->Reject(
......@@ -91,8 +88,9 @@ void DidClaim(ScriptPromiseResolver* resolver,
void DidGetClients(ScriptPromiseResolver* resolver,
Vector<mojom::blink::ServiceWorkerClientInfoPtr> infos) {
if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed())
resolver->GetExecutionContext()->IsContextDestroyed()) {
return;
}
HeapVector<Member<ServiceWorkerClient>> clients;
for (const auto& info : infos) {
......@@ -121,11 +119,9 @@ ScriptPromise ServiceWorkerClients::get(ScriptState* script_state,
return ScriptPromise();
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
ScriptPromise promise = resolver->Promise();
ServiceWorkerGlobalScopeClient::From(execution_context)
->GetClient(id, std::make_unique<GetCallback>(resolver));
return promise;
->GetClient(id, WTF::Bind(&DidGetClient, WrapPersistent(resolver)));
return resolver->Promise();
}
ScriptPromise ServiceWorkerClients::matchAll(
......
......@@ -63,17 +63,6 @@ blink::WebServiceWorkerClientInfo ToWebServiceWorkerClientInfo(
return web_client_info;
}
void DidGetClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
mojom::blink::ServiceWorkerClientInfoPtr client) {
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client;
if (client) {
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
}
callbacks->OnSuccess(std::move(web_client));
}
void DidOpenWindow(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success,
......@@ -136,12 +125,9 @@ ServiceWorkerGlobalScopeClient::ServiceWorkerGlobalScopeClient(
WebServiceWorkerContextClient& client)
: client_(client) {}
void ServiceWorkerGlobalScopeClient::GetClient(
const String& id,
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
service_worker_host_->GetClient(
id, WTF::Bind(&DidGetClient, std::move(callbacks)));
void ServiceWorkerGlobalScopeClient::GetClient(const String& id,
GetClientCallback callback) {
service_worker_host_->GetClient(id, std::move(callback));
}
void ServiceWorkerGlobalScopeClient::GetClients(
......
......@@ -64,6 +64,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
using ClaimCallback = mojom::blink::ServiceWorkerHost::ClaimClientsCallback;
using SkipWaitingCallback =
mojom::blink::ServiceWorkerHost::SkipWaitingCallback;
using GetClientCallback = mojom::blink::ServiceWorkerHost::GetClientCallback;
using GetClientsCallback =
mojom::blink::ServiceWorkerHost::GetClientsCallback;
......@@ -72,8 +73,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
explicit ServiceWorkerGlobalScopeClient(WebServiceWorkerContextClient&);
// Called from ServiceWorkerClients.
void GetClient(const String&,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void GetClient(const String&, GetClientCallback);
void GetClients(mojom::blink::ServiceWorkerClientQueryOptionsPtr,
GetClientsCallback);
void OpenWindowForClients(const KURL&,
......
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