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 @@ ...@@ -21,25 +21,6 @@
namespace blink { 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( ServiceWorkerClient* ServiceWorkerClient::Create(
const WebServiceWorkerClientInfo& info) { const WebServiceWorkerClientInfo& info) {
return new ServiceWorkerClient(info); return new ServiceWorkerClient(info);
......
...@@ -17,18 +17,12 @@ ...@@ -17,18 +17,12 @@
namespace blink { namespace blink {
class PostMessageOptions; class PostMessageOptions;
class ScriptPromiseResolver;
class ScriptState; class ScriptState;
class MODULES_EXPORT ServiceWorkerClient : public ScriptWrappable { class MODULES_EXPORT ServiceWorkerClient : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: 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 WebServiceWorkerClientInfo&);
static ServiceWorkerClient* Create( static ServiceWorkerClient* Create(
const mojom::blink::ServiceWorkerClientInfo&); const mojom::blink::ServiceWorkerClientInfo&);
......
...@@ -40,44 +40,41 @@ mojom::ServiceWorkerClientType GetClientType(const String& type) { ...@@ -40,44 +40,41 @@ mojom::ServiceWorkerClientType GetClientType(const String& type) {
return mojom::ServiceWorkerClientType::kWindow; return mojom::ServiceWorkerClientType::kWindow;
} }
class GetCallback : public WebServiceWorkerClientCallbacks { void DidGetClient(ScriptPromiseResolver* resolver,
public: mojom::blink::ServiceWorkerClientInfoPtr info) {
explicit GetCallback(ScriptPromiseResolver* resolver) : resolver_(resolver) {} if (!resolver->GetExecutionContext() ||
~GetCallback() override = default; resolver->GetExecutionContext()->IsContextDestroyed()) {
return;
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 OnError(const WebServiceWorkerError& error) override { if (!info) {
if (!resolver_->GetExecutionContext() || // Resolve the promise with undefined.
resolver_->GetExecutionContext()->IsContextDestroyed()) 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; return;
resolver_->Reject(ServiceWorkerError::Take(resolver_.Get(), error));
} }
resolver->Resolve(client);
private: }
Persistent<ScriptPromiseResolver> resolver_;
DISALLOW_COPY_AND_ASSIGN(GetCallback);
};
void DidClaim(ScriptPromiseResolver* resolver, void DidClaim(ScriptPromiseResolver* resolver,
mojom::blink::ServiceWorkerErrorType error, mojom::blink::ServiceWorkerErrorType error,
const String& error_msg) { const String& error_msg) {
if (!resolver->GetExecutionContext() || if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed()) resolver->GetExecutionContext()->IsContextDestroyed()) {
return; return;
}
if (error != mojom::blink::ServiceWorkerErrorType::kNone) { if (error != mojom::blink::ServiceWorkerErrorType::kNone) {
DCHECK(!error_msg.IsNull()); DCHECK(!error_msg.IsNull());
resolver->Reject( resolver->Reject(
...@@ -91,8 +88,9 @@ void DidClaim(ScriptPromiseResolver* resolver, ...@@ -91,8 +88,9 @@ void DidClaim(ScriptPromiseResolver* resolver,
void DidGetClients(ScriptPromiseResolver* resolver, void DidGetClients(ScriptPromiseResolver* resolver,
Vector<mojom::blink::ServiceWorkerClientInfoPtr> infos) { Vector<mojom::blink::ServiceWorkerClientInfoPtr> infos) {
if (!resolver->GetExecutionContext() || if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed()) resolver->GetExecutionContext()->IsContextDestroyed()) {
return; return;
}
HeapVector<Member<ServiceWorkerClient>> clients; HeapVector<Member<ServiceWorkerClient>> clients;
for (const auto& info : infos) { for (const auto& info : infos) {
...@@ -121,11 +119,9 @@ ScriptPromise ServiceWorkerClients::get(ScriptState* script_state, ...@@ -121,11 +119,9 @@ ScriptPromise ServiceWorkerClients::get(ScriptState* script_state,
return ScriptPromise(); return ScriptPromise();
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
ScriptPromise promise = resolver->Promise();
ServiceWorkerGlobalScopeClient::From(execution_context) ServiceWorkerGlobalScopeClient::From(execution_context)
->GetClient(id, std::make_unique<GetCallback>(resolver)); ->GetClient(id, WTF::Bind(&DidGetClient, WrapPersistent(resolver)));
return promise; return resolver->Promise();
} }
ScriptPromise ServiceWorkerClients::matchAll( ScriptPromise ServiceWorkerClients::matchAll(
......
...@@ -63,17 +63,6 @@ blink::WebServiceWorkerClientInfo ToWebServiceWorkerClientInfo( ...@@ -63,17 +63,6 @@ blink::WebServiceWorkerClientInfo ToWebServiceWorkerClientInfo(
return web_client_info; 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( void DidOpenWindow(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks, std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success, bool success,
...@@ -136,12 +125,9 @@ ServiceWorkerGlobalScopeClient::ServiceWorkerGlobalScopeClient( ...@@ -136,12 +125,9 @@ ServiceWorkerGlobalScopeClient::ServiceWorkerGlobalScopeClient(
WebServiceWorkerContextClient& client) WebServiceWorkerContextClient& client)
: client_(client) {} : client_(client) {}
void ServiceWorkerGlobalScopeClient::GetClient( void ServiceWorkerGlobalScopeClient::GetClient(const String& id,
const String& id, GetClientCallback callback) {
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) { service_worker_host_->GetClient(id, std::move(callback));
DCHECK(callbacks);
service_worker_host_->GetClient(
id, WTF::Bind(&DidGetClient, std::move(callbacks)));
} }
void ServiceWorkerGlobalScopeClient::GetClients( void ServiceWorkerGlobalScopeClient::GetClients(
......
...@@ -64,6 +64,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final ...@@ -64,6 +64,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
using ClaimCallback = mojom::blink::ServiceWorkerHost::ClaimClientsCallback; using ClaimCallback = mojom::blink::ServiceWorkerHost::ClaimClientsCallback;
using SkipWaitingCallback = using SkipWaitingCallback =
mojom::blink::ServiceWorkerHost::SkipWaitingCallback; mojom::blink::ServiceWorkerHost::SkipWaitingCallback;
using GetClientCallback = mojom::blink::ServiceWorkerHost::GetClientCallback;
using GetClientsCallback = using GetClientsCallback =
mojom::blink::ServiceWorkerHost::GetClientsCallback; mojom::blink::ServiceWorkerHost::GetClientsCallback;
...@@ -72,8 +73,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final ...@@ -72,8 +73,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
explicit ServiceWorkerGlobalScopeClient(WebServiceWorkerContextClient&); explicit ServiceWorkerGlobalScopeClient(WebServiceWorkerContextClient&);
// Called from ServiceWorkerClients. // Called from ServiceWorkerClients.
void GetClient(const String&, void GetClient(const String&, GetClientCallback);
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void GetClients(mojom::blink::ServiceWorkerClientQueryOptionsPtr, void GetClients(mojom::blink::ServiceWorkerClientQueryOptionsPtr,
GetClientsCallback); GetClientsCallback);
void OpenWindowForClients(const KURL&, 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