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

[ServiceWorker] Move ServiceWorkerClientInfoPtr through impl of service_worker_client_utils

This CL starts to move ServiceWorkerClientInfoPtr through impl of
service_worker_client_utils rather than passing value of
ServiceWorkerClientInfo struct.

BUG=772793

Change-Id: I852efee05dfda6f86b0486912827c29b00071a9d
Reviewed-on: https://chromium-review.googlesource.com/886141
Commit-Queue: Han Leon <leon.han@intel.com>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531875}
parent ff0799d2
...@@ -105,7 +105,7 @@ class OpenURLObserver : public WebContentsObserver { ...@@ -105,7 +105,7 @@ class OpenURLObserver : public WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); DISALLOW_COPY_AND_ASSIGN(OpenURLObserver);
}; };
blink::mojom::ServiceWorkerClientInfo GetWindowClientInfoOnUI( blink::mojom::ServiceWorkerClientInfoPtr GetWindowClientInfoOnUI(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
base::TimeTicks create_time, base::TimeTicks create_time,
...@@ -114,12 +114,12 @@ blink::mojom::ServiceWorkerClientInfo GetWindowClientInfoOnUI( ...@@ -114,12 +114,12 @@ blink::mojom::ServiceWorkerClientInfo GetWindowClientInfoOnUI(
RenderFrameHostImpl* render_frame_host = RenderFrameHostImpl* render_frame_host =
RenderFrameHostImpl::FromID(render_process_id, render_frame_id); RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
if (!render_frame_host) if (!render_frame_host)
return blink::mojom::ServiceWorkerClientInfo(); return blink::mojom::ServiceWorkerClientInfo::New();
// TODO(mlamouri,michaeln): it is possible to end up collecting information // TODO(mlamouri,michaeln): it is possible to end up collecting information
// for a frame that is actually being navigated and isn't exactly what we are // for a frame that is actually being navigated and isn't exactly what we are
// expecting. // expecting.
return blink::mojom::ServiceWorkerClientInfo( return blink::mojom::ServiceWorkerClientInfo::New(
render_frame_host->GetLastCommittedURL(), client_uuid, render_frame_host->GetLastCommittedURL(), client_uuid,
blink::mojom::ServiceWorkerClientType::kWindow, blink::mojom::ServiceWorkerClientType::kWindow,
render_frame_host->GetVisibilityState(), render_frame_host->IsFocused(), render_frame_host->GetVisibilityState(), render_frame_host->IsFocused(),
...@@ -129,7 +129,7 @@ blink::mojom::ServiceWorkerClientInfo GetWindowClientInfoOnUI( ...@@ -129,7 +129,7 @@ blink::mojom::ServiceWorkerClientInfo GetWindowClientInfoOnUI(
render_frame_host->frame_tree_node()->last_focus_time(), create_time); render_frame_host->frame_tree_node()->last_focus_time(), create_time);
} }
blink::mojom::ServiceWorkerClientInfo FocusOnUI( blink::mojom::ServiceWorkerClientInfoPtr FocusOnUI(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
base::TimeTicks create_time, base::TimeTicks create_time,
...@@ -141,7 +141,7 @@ blink::mojom::ServiceWorkerClientInfo FocusOnUI( ...@@ -141,7 +141,7 @@ blink::mojom::ServiceWorkerClientInfo FocusOnUI(
WebContents::FromRenderFrameHost(render_frame_host)); WebContents::FromRenderFrameHost(render_frame_host));
if (!render_frame_host || !web_contents) if (!render_frame_host || !web_contents)
return blink::mojom::ServiceWorkerClientInfo(); return blink::mojom::ServiceWorkerClientInfo::New();
FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node();
...@@ -301,23 +301,23 @@ void OnGetWindowClientsOnUI( ...@@ -301,23 +301,23 @@ void OnGetWindowClientsOnUI(
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
for (const auto& it : clients_info) { for (const auto& it : clients_info) {
blink::mojom::ServiceWorkerClientInfo info = GetWindowClientInfoOnUI( blink::mojom::ServiceWorkerClientInfoPtr info = GetWindowClientInfoOnUI(
std::get<0>(it), std::get<1>(it), std::get<2>(it), std::get<3>(it)); std::get<0>(it), std::get<1>(it), std::get<2>(it), std::get<3>(it));
// If the request to the provider_host returned an invalid // If the request to the provider_host returned an invalid
// ServiceWorkerClientInfo, that means that it wasn't possible to associate // ServiceWorkerClientInfo, that means that it wasn't possible to associate
// it with a valid RenderFrameHost. It might be because the frame was killed // it with a valid RenderFrameHost. It might be because the frame was killed
// or navigated in between. // or navigated in between.
if (info.client_uuid.empty()) if (info->client_uuid.empty())
continue; continue;
// We can get info for a frame that was navigating end ended up with a // We can get info for a frame that was navigating end ended up with a
// different URL than expected. In such case, we should make sure to not // different URL than expected. In such case, we should make sure to not
// expose cross-origin WindowClient. // expose cross-origin WindowClient.
if (info.url.GetOrigin() != script_url.GetOrigin()) if (info->url.GetOrigin() != script_url.GetOrigin())
continue; continue;
out_clients->push_back(info.Clone()); out_clients->push_back(std::move(info));
} }
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -473,7 +473,7 @@ void NavigateClient(const GURL& url, ...@@ -473,7 +473,7 @@ void NavigateClient(const GURL& url,
} }
void GetClient(const ServiceWorkerProviderHost* provider_host, void GetClient(const ServiceWorkerProviderHost* provider_host,
GetClientCallback callback) { ClientCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
blink::mojom::ServiceWorkerClientType client_type = blink::mojom::ServiceWorkerClientType client_type =
...@@ -488,12 +488,7 @@ void GetClient(const ServiceWorkerProviderHost* provider_host, ...@@ -488,12 +488,7 @@ void GetClient(const ServiceWorkerProviderHost* provider_host,
base::BindOnce(&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::BindOnce( std::move(callback));
[](GetClientCallback callback,
const blink::mojom::ServiceWorkerClientInfo& client_info) {
std::move(callback).Run(client_info.Clone());
},
std::move(callback)));
return; return;
} }
...@@ -540,14 +535,14 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context, ...@@ -540,14 +535,14 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
if (!context) { if (!context) {
std::move(callback).Run(SERVICE_WORKER_ERROR_ABORT, std::move(callback).Run(SERVICE_WORKER_ERROR_ABORT,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo::New());
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) {
std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED, std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo::New());
return; return;
} }
...@@ -571,7 +566,7 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context, ...@@ -571,7 +566,7 @@ void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
// 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.
std::move(callback).Run(SERVICE_WORKER_OK, std::move(callback).Run(SERVICE_WORKER_OK,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo::New());
} }
} // namespace service_worker_client_utils } // namespace service_worker_client_utils
......
...@@ -26,10 +26,8 @@ namespace service_worker_client_utils { ...@@ -26,10 +26,8 @@ namespace service_worker_client_utils {
using NavigationCallback = base::OnceCallback<void( using NavigationCallback = base::OnceCallback<void(
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info)>; blink::mojom::ServiceWorkerClientInfoPtr client_info)>;
using ClientCallback = base::OnceCallback<void( using ClientCallback = base::OnceCallback<void(
const blink::mojom::ServiceWorkerClientInfo& client_info)>;
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>;
...@@ -62,7 +60,7 @@ void NavigateClient(const GURL& url, ...@@ -62,7 +60,7 @@ void NavigateClient(const GURL& url,
// 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.
void GetClient(const ServiceWorkerProviderHost* provider_host, void GetClient(const ServiceWorkerProviderHost* provider_host,
GetClientCallback callback); ClientCallback callback);
// Collects clients matched with |options|. |callback| is called with the client // Collects clients matched with |options|. |callback| is called with the client
// information sorted in MRU order (most recently focused order) on completion. // information sorted in MRU order (most recently focused order) on completion.
......
...@@ -210,7 +210,7 @@ void DidNavigateInPaymentHandlerWindow( ...@@ -210,7 +210,7 @@ void DidNavigateInPaymentHandlerWindow(
render_frame_id); render_frame_id);
} else { } else {
std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED, std::move(callback).Run(SERVICE_WORKER_ERROR_FAILED,
blink::mojom::ServiceWorkerClientInfo()); blink::mojom::ServiceWorkerClientInfo::New());
} }
} }
...@@ -1296,7 +1296,7 @@ void ServiceWorkerVersion::OnOpenWindow(int request_id, ...@@ -1296,7 +1296,7 @@ void ServiceWorkerVersion::OnOpenWindow(int request_id,
void ServiceWorkerVersion::OnOpenWindowFinished( void ServiceWorkerVersion::OnOpenWindowFinished(
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info) { blink::mojom::ServiceWorkerClientInfoPtr client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (running_status() != EmbeddedWorkerStatus::RUNNING) if (running_status() != EmbeddedWorkerStatus::RUNNING)
...@@ -1308,8 +1308,9 @@ void ServiceWorkerVersion::OnOpenWindowFinished( ...@@ -1308,8 +1308,9 @@ void ServiceWorkerVersion::OnOpenWindowFinished(
return; return;
} }
DCHECK(client_info);
embedded_worker_->SendIpcMessage( embedded_worker_->SendIpcMessage(
ServiceWorkerMsg_OpenWindowResponse(request_id, client_info)); ServiceWorkerMsg_OpenWindowResponse(request_id, *client_info));
} }
void ServiceWorkerVersion::OnPostMessageToClient( void ServiceWorkerVersion::OnPostMessageToClient(
...@@ -1369,14 +1370,15 @@ void ServiceWorkerVersion::OnFocusClient(int request_id, ...@@ -1369,14 +1370,15 @@ void ServiceWorkerVersion::OnFocusClient(int request_id,
void ServiceWorkerVersion::OnFocusClientFinished( void ServiceWorkerVersion::OnFocusClientFinished(
int request_id, int request_id,
const blink::mojom::ServiceWorkerClientInfo& client_info) { blink::mojom::ServiceWorkerClientInfoPtr client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (running_status() != EmbeddedWorkerStatus::RUNNING) if (running_status() != EmbeddedWorkerStatus::RUNNING)
return; return;
DCHECK(client_info);
embedded_worker_->SendIpcMessage( embedded_worker_->SendIpcMessage(
ServiceWorkerMsg_FocusClientResponse(request_id, client_info)); ServiceWorkerMsg_FocusClientResponse(request_id, *client_info));
} }
void ServiceWorkerVersion::OnNavigateClient(int request_id, void ServiceWorkerVersion::OnNavigateClient(int request_id,
...@@ -1425,7 +1427,7 @@ void ServiceWorkerVersion::OnNavigateClient(int request_id, ...@@ -1425,7 +1427,7 @@ void ServiceWorkerVersion::OnNavigateClient(int request_id,
void ServiceWorkerVersion::OnNavigateClientFinished( void ServiceWorkerVersion::OnNavigateClientFinished(
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info) { blink::mojom::ServiceWorkerClientInfoPtr client_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (running_status() != EmbeddedWorkerStatus::RUNNING) if (running_status() != EmbeddedWorkerStatus::RUNNING)
...@@ -1437,8 +1439,9 @@ void ServiceWorkerVersion::OnNavigateClientFinished( ...@@ -1437,8 +1439,9 @@ void ServiceWorkerVersion::OnNavigateClientFinished(
return; return;
} }
DCHECK(client_info);
embedded_worker_->SendIpcMessage( embedded_worker_->SendIpcMessage(
ServiceWorkerMsg_NavigateClientResponse(request_id, client_info)); ServiceWorkerMsg_NavigateClientResponse(request_id, *client_info));
} }
void ServiceWorkerVersion::OnSkipWaiting(int request_id) { void ServiceWorkerVersion::OnSkipWaiting(int request_id) {
......
...@@ -653,7 +653,7 @@ class CONTENT_EXPORT ServiceWorkerVersion ...@@ -653,7 +653,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnOpenWindowFinished( void OnOpenWindowFinished(
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info); blink::mojom::ServiceWorkerClientInfoPtr client_info);
void OnPostMessageToClient( void OnPostMessageToClient(
const std::string& client_uuid, const std::string& client_uuid,
...@@ -666,13 +666,13 @@ class CONTENT_EXPORT ServiceWorkerVersion ...@@ -666,13 +666,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnNavigateClientFinished( void OnNavigateClientFinished(
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
const blink::mojom::ServiceWorkerClientInfo& client_info); blink::mojom::ServiceWorkerClientInfoPtr client_info);
void OnSkipWaiting(int request_id); void OnSkipWaiting(int request_id);
void OnPongFromWorker(); void OnPongFromWorker();
void OnFocusClientFinished( void OnFocusClientFinished(
int request_id, int request_id,
const blink::mojom::ServiceWorkerClientInfo& client_info); blink::mojom::ServiceWorkerClientInfoPtr client_info);
void DidEnsureLiveRegistrationForStartWorker( void DidEnsureLiveRegistrationForStartWorker(
ServiceWorkerMetrics::EventType purpose, ServiceWorkerMetrics::EventType purpose,
......
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