Commit 4b9e63a7 authored by Han Leon's avatar Han Leon Committed by Commit Bot

[ServiceWorker] Apply OnceCallback through impl of service_worker_client_utils

BUG=

Change-Id: I6b5b28230390de1f3b8a105c1f750fc394dfe923
Reviewed-on: https://chromium-review.googlesource.com/886004Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Han Leon <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#531842}
parent a7634160
...@@ -24,22 +24,22 @@ class ServiceWorkerVersion; ...@@ -24,22 +24,22 @@ class ServiceWorkerVersion;
namespace service_worker_client_utils { namespace service_worker_client_utils {
using NavigationCallback = base::Callback<void( using NavigationCallback = base::OnceCallback<void(
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info)>; const blink::mojom::ServiceWorkerClientInfo& client_info)>;
using ClientCallback = base::Callback<void( using ClientCallback = base::OnceCallback<void(
const blink::mojom::ServiceWorkerClientInfo& client_info)>; const blink::mojom::ServiceWorkerClientInfo& client_info)>;
using GetClientCallback = base::OnceCallback<void( using GetClientCallback = base::OnceCallback<void(
blink::mojom::ServiceWorkerClientInfoPtr client_info)>; blink::mojom::ServiceWorkerClientInfoPtr client_info)>;
using ServiceWorkerClientPtrs = using ServiceWorkerClientPtrs =
std::vector<blink::mojom::ServiceWorkerClientInfoPtr>; std::vector<blink::mojom::ServiceWorkerClientInfoPtr>;
using ClientsCallback = using ClientsCallback =
base::Callback<void(std::unique_ptr<ServiceWorkerClientPtrs> clients)>; base::OnceCallback<void(std::unique_ptr<ServiceWorkerClientPtrs> clients)>;
// Focuses the window client associated with |provider_host|. |callback| is // Focuses the window client associated with |provider_host|. |callback| is
// called with the client information on completion. // called with the client information on completion.
void FocusWindowClient(ServiceWorkerProviderHost* provider_host, void FocusWindowClient(ServiceWorkerProviderHost* provider_host,
const ClientCallback& callback); ClientCallback callback);
// Opens a new window and navigates it to |url|. |callback| is called with the // Opens a new window and navigates it to |url|. |callback| is called with the
// window's client information on completion. // window's client information on completion.
...@@ -48,7 +48,7 @@ void OpenWindow(const GURL& url, ...@@ -48,7 +48,7 @@ void OpenWindow(const GURL& url,
int worker_process_id, int worker_process_id,
const base::WeakPtr<ServiceWorkerContextCore>& context, const base::WeakPtr<ServiceWorkerContextCore>& context,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
const NavigationCallback& callback); NavigationCallback callback);
// Navigates the client specified by |process_id| and |frame_id| to |url|. // Navigates the client specified by |process_id| and |frame_id| to |url|.
// |callback| is called with the client information on completion. // |callback| is called with the client information on completion.
...@@ -57,7 +57,7 @@ void NavigateClient(const GURL& url, ...@@ -57,7 +57,7 @@ void NavigateClient(const GURL& url,
int process_id, int process_id,
int frame_id, int frame_id,
const base::WeakPtr<ServiceWorkerContextCore>& context, const base::WeakPtr<ServiceWorkerContextCore>& context,
const NavigationCallback& callback); NavigationCallback callback);
// Gets the client specified by |provider_host|. |callback| is called with the // Gets the client specified by |provider_host|. |callback| is called with the
// client information on completion. // client information on completion.
...@@ -68,7 +68,7 @@ void GetClient(const ServiceWorkerProviderHost* provider_host, ...@@ -68,7 +68,7 @@ void GetClient(const ServiceWorkerProviderHost* provider_host,
// information sorted in MRU order (most recently focused order) on completion. // information sorted in MRU order (most recently focused order) on completion.
void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options, blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
const ClientsCallback& callback); ClientsCallback callback);
// Finds the provider host for |origin| in |context| then uses // Finds the provider host for |origin| in |context| then uses
// |render_process_id| and |render_process_host| to create a relevant // |render_process_id| and |render_process_host| to create a relevant
...@@ -76,7 +76,7 @@ void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, ...@@ -76,7 +76,7 @@ void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
// Must be called on the IO thread. // Must be called on the IO thread.
void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context, void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
const GURL& origin, const GURL& origin,
const NavigationCallback& callback, NavigationCallback callback,
int render_process_id, int render_process_id,
int render_frame_id); int render_frame_id);
......
...@@ -200,16 +200,17 @@ CompleteProviderHostPreparation( ...@@ -200,16 +200,17 @@ CompleteProviderHostPreparation(
void DidNavigateInPaymentHandlerWindow( void DidNavigateInPaymentHandlerWindow(
const GURL& url, const GURL& url,
const base::WeakPtr<ServiceWorkerContextCore>& context, const base::WeakPtr<ServiceWorkerContextCore>& context,
const service_worker_client_utils::NavigationCallback& callback, service_worker_client_utils::NavigationCallback callback,
bool success, bool success,
int render_process_id, int render_process_id,
int render_frame_id) { int render_frame_id) {
if (success) { if (success) {
service_worker_client_utils::DidNavigate( service_worker_client_utils::DidNavigate(
context, url.GetOrigin(), callback, render_process_id, render_frame_id); context, url.GetOrigin(), std::move(callback), render_process_id,
render_frame_id);
} else { } else {
callback.Run(SERVICE_WORKER_ERROR_FAILED, std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo());
} }
} }
...@@ -1133,8 +1134,7 @@ void ServiceWorkerVersion::GetClients( ...@@ -1133,8 +1134,7 @@ void ServiceWorkerVersion::GetClients(
GetClientsCallback callback) { GetClientsCallback callback) {
service_worker_client_utils::GetClients( service_worker_client_utils::GetClients(
weak_factory_.GetWeakPtr(), std::move(options), weak_factory_.GetWeakPtr(), std::move(options),
base::AdaptCallbackForRepeating( base::BindOnce(&DidGetClients, std::move(callback)));
base::BindOnce(&DidGetClients, std::move(callback))));
} }
void ServiceWorkerVersion::OnSetCachedMetadataFinished(int64_t callback_id, void ServiceWorkerVersion::OnSetCachedMetadataFinished(int64_t callback_id,
...@@ -1247,9 +1247,10 @@ void ServiceWorkerVersion::OnOpenPaymentHandlerWindow(int request_id, ...@@ -1247,9 +1247,10 @@ void ServiceWorkerVersion::OnOpenPaymentHandlerWindow(int request_id,
base::BindOnce( base::BindOnce(
&ShowPaymentHandlerWindowOnUI, GetContentClient()->browser(), &ShowPaymentHandlerWindowOnUI, GetContentClient()->browser(),
base::WrapRefCounted(context_->wrapper()), url, base::WrapRefCounted(context_->wrapper()), url,
base::BindOnce(&DidNavigateInPaymentHandlerWindow, url, context_, base::BindOnce(
base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished, &DidNavigateInPaymentHandlerWindow, url, context_,
weak_factory_.GetWeakPtr(), request_id)), base::BindOnce(&ServiceWorkerVersion::OnOpenWindowFinished,
weak_factory_.GetWeakPtr(), request_id)),
base::BindOnce(&ServiceWorkerVersion::OnOpenWindow, base::BindOnce(&ServiceWorkerVersion::OnOpenWindow,
weak_factory_.GetWeakPtr(), request_id, url, weak_factory_.GetWeakPtr(), request_id, url,
WindowOpenDisposition::NEW_POPUP))); WindowOpenDisposition::NEW_POPUP)));
...@@ -1288,8 +1289,8 @@ void ServiceWorkerVersion::OnOpenWindow(int request_id, ...@@ -1288,8 +1289,8 @@ void ServiceWorkerVersion::OnOpenWindow(int request_id,
service_worker_client_utils::OpenWindow( service_worker_client_utils::OpenWindow(
url, script_url_, embedded_worker_->process_id(), context_, disposition, url, script_url_, embedded_worker_->process_id(), context_, disposition,
base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished, base::BindOnce(&ServiceWorkerVersion::OnOpenWindowFinished,
weak_factory_.GetWeakPtr(), request_id)); weak_factory_.GetWeakPtr(), request_id));
} }
void ServiceWorkerVersion::OnOpenWindowFinished( void ServiceWorkerVersion::OnOpenWindowFinished(
...@@ -1361,8 +1362,9 @@ void ServiceWorkerVersion::OnFocusClient(int request_id, ...@@ -1361,8 +1362,9 @@ void ServiceWorkerVersion::OnFocusClient(int request_id,
} }
service_worker_client_utils::FocusWindowClient( service_worker_client_utils::FocusWindowClient(
provider_host, base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, provider_host,
weak_factory_.GetWeakPtr(), request_id)); base::BindOnce(&ServiceWorkerVersion::OnFocusClientFinished,
weak_factory_.GetWeakPtr(), request_id));
} }
void ServiceWorkerVersion::OnFocusClientFinished( void ServiceWorkerVersion::OnFocusClientFinished(
...@@ -1415,8 +1417,9 @@ void ServiceWorkerVersion::OnNavigateClient(int request_id, ...@@ -1415,8 +1417,9 @@ void ServiceWorkerVersion::OnNavigateClient(int request_id,
service_worker_client_utils::NavigateClient( service_worker_client_utils::NavigateClient(
url, script_url_, provider_host->process_id(), provider_host->frame_id(), url, script_url_, provider_host->process_id(), provider_host->frame_id(),
context_, base::Bind(&ServiceWorkerVersion::OnNavigateClientFinished, context_,
weak_factory_.GetWeakPtr(), request_id)); base::BindOnce(&ServiceWorkerVersion::OnNavigateClientFinished,
weak_factory_.GetWeakPtr(), request_id));
} }
void ServiceWorkerVersion::OnNavigateClientFinished( void ServiceWorkerVersion::OnNavigateClientFinished(
......
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