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
...@@ -39,9 +39,7 @@ namespace service_worker_client_utils { ...@@ -39,9 +39,7 @@ namespace service_worker_client_utils {
namespace { namespace {
using OpenURLCallback = base::Callback<void(int, int)>; using OpenURLCallback = base::OnceCallback<void(int, int)>;
using GetWindowClientsCallback =
base::Callback<void(std::unique_ptr<ServiceWorkerClientPtrs>)>;
// The OpenURLObserver class is a WebContentsObserver that will wait for a // The OpenURLObserver class is a WebContentsObserver that will wait for a
// WebContents to be initialized, run the |callback| passed to its constructor // WebContents to be initialized, run the |callback| passed to its constructor
...@@ -53,10 +51,10 @@ class OpenURLObserver : public WebContentsObserver { ...@@ -53,10 +51,10 @@ class OpenURLObserver : public WebContentsObserver {
public: public:
OpenURLObserver(WebContents* web_contents, OpenURLObserver(WebContents* web_contents,
int frame_tree_node_id, int frame_tree_node_id,
const OpenURLCallback& callback) OpenURLCallback callback)
: WebContentsObserver(web_contents), : WebContentsObserver(web_contents),
frame_tree_node_id_(frame_tree_node_id), frame_tree_node_id_(frame_tree_node_id),
callback_(callback) {} callback_(std::move(callback)) {}
void DidFinishNavigation(NavigationHandle* navigation_handle) override { void DidFinishNavigation(NavigationHandle* navigation_handle) override {
DCHECK(web_contents()); DCHECK(web_contents());
...@@ -92,16 +90,17 @@ class OpenURLObserver : public WebContentsObserver { ...@@ -92,16 +90,17 @@ class OpenURLObserver : public WebContentsObserver {
// web_contents() should return nullptr and |RunCallback| should no longer // web_contents() should return nullptr and |RunCallback| should no longer
// be called. Then, |this| will self destroy. // be called. Then, |this| will self destroy.
DCHECK(web_contents()); DCHECK(web_contents());
DCHECK(callback_);
BrowserThread::PostTask( BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
BrowserThread::IO, FROM_HERE, base::BindOnce(std::move(callback_),
base::BindOnce(callback_, render_process_id, render_frame_id)); render_process_id, render_frame_id));
Observe(nullptr); Observe(nullptr);
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
} }
int frame_tree_node_id_; int frame_tree_node_id_;
const OpenURLCallback callback_; OpenURLCallback callback_;
DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); DISALLOW_COPY_AND_ASSIGN(OpenURLObserver);
}; };
...@@ -161,14 +160,13 @@ blink::mojom::ServiceWorkerClientInfo FocusOnUI( ...@@ -161,14 +160,13 @@ blink::mojom::ServiceWorkerClientInfo FocusOnUI(
} }
// This is only called for main frame navigations in OpenWindowOnUI(). // This is only called for main frame navigations in OpenWindowOnUI().
void DidOpenURLOnUI(const OpenURLCallback& callback, void DidOpenURLOnUI(OpenURLCallback callback, WebContents* web_contents) {
WebContents* web_contents) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!web_contents) { if (!web_contents) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, ChildProcessHost::kInvalidUniqueID, base::BindOnce(std::move(callback), ChildProcessHost::kInvalidUniqueID,
MSG_ROUTING_NONE)); MSG_ROUTING_NONE));
return; return;
} }
...@@ -183,7 +181,8 @@ void DidOpenURLOnUI(const OpenURLCallback& callback, ...@@ -183,7 +181,8 @@ void DidOpenURLOnUI(const OpenURLCallback& callback,
RenderFrameHostImpl* rfhi = RenderFrameHostImpl* rfhi =
static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame()); static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame());
new OpenURLObserver(web_contents, new OpenURLObserver(web_contents,
rfhi->frame_tree_node()->frame_tree_node_id(), callback); rfhi->frame_tree_node()->frame_tree_node_id(),
std::move(callback));
} }
void OpenWindowOnUI( void OpenWindowOnUI(
...@@ -192,7 +191,7 @@ void OpenWindowOnUI( ...@@ -192,7 +191,7 @@ void OpenWindowOnUI(
int worker_process_id, int worker_process_id,
const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper, const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
const OpenURLCallback& callback) { OpenURLCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserContext* browser_context = BrowserContext* browser_context =
...@@ -208,7 +207,7 @@ void OpenWindowOnUI( ...@@ -208,7 +207,7 @@ void OpenWindowOnUI(
if (render_process_host->IsForGuestsOnly()) { if (render_process_host->IsForGuestsOnly()) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, ChildProcessHost::kInvalidUniqueID, base::BindOnce(std::move(callback), ChildProcessHost::kInvalidUniqueID,
MSG_ROUTING_NONE)); MSG_ROUTING_NONE));
return; return;
} }
...@@ -220,15 +219,17 @@ void OpenWindowOnUI( ...@@ -220,15 +219,17 @@ void OpenWindowOnUI(
disposition, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, disposition, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
true /* is_renderer_initiated */); true /* is_renderer_initiated */);
GetContentClient()->browser()->OpenURL(browser_context, params, GetContentClient()->browser()->OpenURL(
base::Bind(&DidOpenURLOnUI, callback)); browser_context, params,
base::AdaptCallbackForRepeating(
base::BindOnce(&DidOpenURLOnUI, std::move(callback))));
} }
void NavigateClientOnUI(const GURL& url, void NavigateClientOnUI(const GURL& url,
const GURL& script_url, const GURL& script_url,
int process_id, int process_id,
int frame_id, int frame_id,
const OpenURLCallback& callback) { OpenURLCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHostImpl* rfhi = RenderFrameHostImpl::FromID(process_id, frame_id); RenderFrameHostImpl* rfhi = RenderFrameHostImpl::FromID(process_id, frame_id);
...@@ -237,7 +238,7 @@ void NavigateClientOnUI(const GURL& url, ...@@ -237,7 +238,7 @@ void NavigateClientOnUI(const GURL& url,
if (!rfhi || !web_contents) { if (!rfhi || !web_contents) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(callback, ChildProcessHost::kInvalidUniqueID, base::BindOnce(std::move(callback), ChildProcessHost::kInvalidUniqueID,
MSG_ROUTING_NONE)); MSG_ROUTING_NONE));
return; return;
} }
...@@ -254,7 +255,7 @@ void NavigateClientOnUI(const GURL& url, ...@@ -254,7 +255,7 @@ void NavigateClientOnUI(const GURL& url,
frame_tree_node_id, WindowOpenDisposition::CURRENT_TAB, transition, frame_tree_node_id, WindowOpenDisposition::CURRENT_TAB, transition,
true /* is_renderer_initiated */); true /* is_renderer_initiated */);
web_contents->OpenURL(params); web_contents->OpenURL(params);
new OpenURLObserver(web_contents, frame_tree_node_id, callback); new OpenURLObserver(web_contents, frame_tree_node_id, std::move(callback));
} }
void AddWindowClient( void AddWindowClient(
...@@ -295,7 +296,7 @@ void OnGetWindowClientsOnUI( ...@@ -295,7 +296,7 @@ void OnGetWindowClientsOnUI(
const std::vector<std::tuple<int, int, base::TimeTicks, std::string>>& const std::vector<std::tuple<int, int, base::TimeTicks, std::string>>&
clients_info, clients_info,
const GURL& script_url, const GURL& script_url,
const GetWindowClientsCallback& callback, ClientsCallback callback,
std::unique_ptr<ServiceWorkerClientPtrs> out_clients) { std::unique_ptr<ServiceWorkerClientPtrs> out_clients) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -319,8 +320,9 @@ void OnGetWindowClientsOnUI( ...@@ -319,8 +320,9 @@ void OnGetWindowClientsOnUI(
out_clients->push_back(info.Clone()); out_clients->push_back(info.Clone());
} }
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(
base::BindOnce(callback, base::Passed(&out_clients))); BrowserThread::IO, FROM_HERE,
base::BindOnce(std::move(callback), std::move(out_clients)));
} }
struct ServiceWorkerClientInfoSort { struct ServiceWorkerClientInfoSort {
...@@ -345,19 +347,19 @@ struct ServiceWorkerClientInfoSort { ...@@ -345,19 +347,19 @@ struct ServiceWorkerClientInfoSort {
} }
}; };
void DidGetClients(const ClientsCallback& callback, void DidGetClients(ClientsCallback callback,
std::unique_ptr<ServiceWorkerClientPtrs> clients) { std::unique_ptr<ServiceWorkerClientPtrs> clients) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort()); std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort());
callback.Run(std::move(clients)); std::move(callback).Run(std::move(clients));
} }
void GetNonWindowClients( void GetNonWindowClients(
const base::WeakPtr<ServiceWorkerVersion>& controller, const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options, blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
const ClientsCallback& callback, ClientsCallback callback,
std::unique_ptr<ServiceWorkerClientPtrs> clients) { std::unique_ptr<ServiceWorkerClientPtrs> clients) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!options->include_uncontrolled) { if (!options->include_uncontrolled) {
...@@ -371,26 +373,26 @@ void GetNonWindowClients( ...@@ -371,26 +373,26 @@ void GetNonWindowClients(
clients.get()); clients.get());
} }
} }
DidGetClients(callback, std::move(clients)); DidGetClients(std::move(callback), std::move(clients));
} }
void DidGetWindowClients( void DidGetWindowClients(
const base::WeakPtr<ServiceWorkerVersion>& controller, const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options, blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
const ClientsCallback& callback, ClientsCallback callback,
std::unique_ptr<ServiceWorkerClientPtrs> clients) { std::unique_ptr<ServiceWorkerClientPtrs> clients) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (options->client_type == blink::mojom::ServiceWorkerClientType::kAll) { if (options->client_type == blink::mojom::ServiceWorkerClientType::kAll) {
GetNonWindowClients(controller, std::move(options), callback, GetNonWindowClients(controller, std::move(options), std::move(callback),
std::move(clients)); std::move(clients));
return; return;
} }
DidGetClients(callback, std::move(clients)); DidGetClients(std::move(callback), std::move(clients));
} }
void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options, blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
const ClientsCallback& callback, ClientsCallback callback,
std::unique_ptr<ServiceWorkerClientPtrs> clients) { std::unique_ptr<ServiceWorkerClientPtrs> clients) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(options->client_type == DCHECK(options->client_type ==
...@@ -410,7 +412,7 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, ...@@ -410,7 +412,7 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
} }
if (clients_info.empty()) { if (clients_info.empty()) {
DidGetWindowClients(controller, std::move(options), callback, DidGetWindowClients(controller, std::move(options), std::move(callback),
std::move(clients)); std::move(clients));
return; return;
} }
...@@ -419,24 +421,24 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, ...@@ -419,24 +421,24 @@ void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&OnGetWindowClientsOnUI, clients_info, base::BindOnce(&OnGetWindowClientsOnUI, clients_info,
controller->script_url(), controller->script_url(),
base::Bind(&DidGetWindowClients, controller, base::BindOnce(&DidGetWindowClients, controller,
base::Passed(std::move(options)), callback), std::move(options), std::move(callback)),
base::Passed(&clients))); std::move(clients)));
} }
} // namespace } // namespace
void FocusWindowClient(ServiceWorkerProviderHost* provider_host, void FocusWindowClient(ServiceWorkerProviderHost* provider_host,
const ClientCallback& callback) { ClientCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(blink::mojom::ServiceWorkerClientType::kWindow, DCHECK_EQ(blink::mojom::ServiceWorkerClientType::kWindow,
provider_host->client_type()); provider_host->client_type());
BrowserThread::PostTaskAndReplyWithResult( BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&FocusOnUI, provider_host->process_id(), base::BindOnce(&FocusOnUI, provider_host->process_id(),
provider_host->frame_id(), provider_host->create_time(), provider_host->frame_id(), provider_host->create_time(),
provider_host->client_uuid()), provider_host->client_uuid()),
callback); std::move(callback));
} }
void OpenWindow(const GURL& url, void OpenWindow(const GURL& url,
...@@ -444,14 +446,15 @@ void OpenWindow(const GURL& url, ...@@ -444,14 +446,15 @@ 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) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce( base::BindOnce(
&OpenWindowOnUI, url, script_url, worker_process_id, &OpenWindowOnUI, url, script_url, worker_process_id,
base::WrapRefCounted(context->wrapper()), disposition, base::WrapRefCounted(context->wrapper()), disposition,
base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); base::BindOnce(&DidNavigate, context, script_url.GetOrigin(),
std::move(callback))));
} }
void NavigateClient(const GURL& url, void NavigateClient(const GURL& url,
...@@ -459,13 +462,14 @@ void NavigateClient(const GURL& url, ...@@ -459,13 +462,14 @@ 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) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce( base::BindOnce(
&NavigateClientOnUI, url, script_url, process_id, frame_id, &NavigateClientOnUI, url, script_url, process_id, frame_id,
base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); base::BindOnce(&DidNavigate, context, script_url.GetOrigin(),
std::move(callback))));
} }
void GetClient(const ServiceWorkerProviderHost* provider_host, void GetClient(const ServiceWorkerProviderHost* provider_host,
...@@ -506,44 +510,44 @@ void GetClient(const ServiceWorkerProviderHost* provider_host, ...@@ -506,44 +510,44 @@ void GetClient(const ServiceWorkerProviderHost* provider_host,
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) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
auto clients = std::make_unique<ServiceWorkerClientPtrs>(); auto clients = std::make_unique<ServiceWorkerClientPtrs>();
if (!controller->HasControllee() && !options->include_uncontrolled) { if (!controller->HasControllee() && !options->include_uncontrolled) {
DidGetClients(callback, std::move(clients)); DidGetClients(std::move(callback), std::move(clients));
return; return;
} }
// For Window clients we want to query the info on the UI thread first. // For Window clients we want to query the info on the UI thread first.
if (options->client_type == blink::mojom::ServiceWorkerClientType::kWindow || if (options->client_type == blink::mojom::ServiceWorkerClientType::kWindow ||
options->client_type == blink::mojom::ServiceWorkerClientType::kAll) { options->client_type == blink::mojom::ServiceWorkerClientType::kAll) {
GetWindowClients(controller, std::move(options), callback, GetWindowClients(controller, std::move(options), std::move(callback),
std::move(clients)); std::move(clients));
return; return;
} }
GetNonWindowClients(controller, std::move(options), callback, GetNonWindowClients(controller, std::move(options), std::move(callback),
std::move(clients)); std::move(clients));
} }
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) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!context) { if (!context) {
callback.Run(SERVICE_WORKER_ERROR_ABORT, std::move(callback).Run(SERVICE_WORKER_ERROR_ABORT,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo());
return; return;
} }
if (render_process_id == ChildProcessHost::kInvalidUniqueID && if (render_process_id == ChildProcessHost::kInvalidUniqueID &&
render_frame_id == MSG_ROUTING_NONE) { render_frame_id == MSG_ROUTING_NONE) {
callback.Run(SERVICE_WORKER_ERROR_FAILED, std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo());
return; return;
} }
...@@ -557,16 +561,17 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context, ...@@ -557,16 +561,17 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
} }
BrowserThread::PostTaskAndReplyWithResult( BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), base::BindOnce(&GetWindowClientInfoOnUI, provider_host->process_id(),
provider_host->route_id(), provider_host->create_time(), provider_host->route_id(), provider_host->create_time(),
provider_host->client_uuid()), provider_host->client_uuid()),
base::Bind(callback, SERVICE_WORKER_OK)); base::BindOnce(std::move(callback), SERVICE_WORKER_OK));
return; return;
} }
// If here, it means that no provider_host was found, in which case, the // If here, it means that no provider_host was found, in which case, the
// renderer should still be informed that the window was opened. // renderer should still be informed that the window was opened.
callback.Run(SERVICE_WORKER_OK, blink::mojom::ServiceWorkerClientInfo()); std::move(callback).Run(SERVICE_WORKER_OK,
blink::mojom::ServiceWorkerClientInfo());
} }
} // namespace service_worker_client_utils } // namespace service_worker_client_utils
......
...@@ -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