Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simlify call flow and remove redundant params Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, 260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent,
261 OnNotificationClickEvent) 261 OnNotificationClickEvent)
262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent, 262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent,
263 OnNotificationCloseEvent) 263 OnNotificationCloseEvent)
264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
268 OnCrossOriginMessageToWorker) 268 OnCrossOriginMessageToWorker)
269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, 271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
271 OnOpenWindowResponse) 272 OnOpenWindowResponse)
272 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, 273 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
273 OnOpenWindowError) 274 OnOpenWindowError)
274 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 275 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
275 OnFocusClientResponse) 276 OnFocusClientResponse)
276 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, 277 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse,
277 OnNavigateClientResponse) 278 OnNavigateClientResponse)
278 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, 279 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError,
(...skipping 12 matching lines...) Expand all
291 mojo::shell::mojom::InterfaceProviderPtr exposed_services) { 292 mojo::shell::mojom::InterfaceProviderPtr exposed_services) {
292 context_->service_registry.Bind(std::move(services)); 293 context_->service_registry.Bind(std::move(services));
293 context_->service_registry.BindRemoteServiceProvider( 294 context_->service_registry.BindRemoteServiceProvider(
294 std::move(exposed_services)); 295 std::move(exposed_services));
295 } 296 }
296 297
297 blink::WebURL ServiceWorkerContextClient::scope() const { 298 blink::WebURL ServiceWorkerContextClient::scope() const {
298 return service_worker_scope_; 299 return service_worker_scope_;
299 } 300 }
300 301
302 void ServiceWorkerContextClient::getClient(
303 const blink::WebString& id,
304 blink::WebServiceWorkerClientCallbacks* callbacks) {
305 DCHECK(callbacks);
306 int request_id = context_->client_callbacks.Add(callbacks);
307 Send(new ServiceWorkerHostMsg_GetClient(
308 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id))));
309 }
310
301 void ServiceWorkerContextClient::getClients( 311 void ServiceWorkerContextClient::getClients(
302 const blink::WebServiceWorkerClientQueryOptions& weboptions, 312 const blink::WebServiceWorkerClientQueryOptions& weboptions,
303 blink::WebServiceWorkerClientsCallbacks* callbacks) { 313 blink::WebServiceWorkerClientsCallbacks* callbacks) {
304 DCHECK(callbacks); 314 DCHECK(callbacks);
305 int request_id = context_->clients_callbacks.Add(callbacks); 315 int request_id = context_->clients_callbacks.Add(callbacks);
306 ServiceWorkerClientQueryOptions options; 316 ServiceWorkerClientQueryOptions options;
307 options.client_type = weboptions.clientType; 317 options.client_type = weboptions.clientType;
308 options.include_uncontrolled = weboptions.includeUncontrolled; 318 options.include_uncontrolled = weboptions.includeUncontrolled;
309 Send(new ServiceWorkerHostMsg_GetClients( 319 Send(new ServiceWorkerHostMsg_GetClients(
310 GetRoutingID(), request_id, options)); 320 GetRoutingID(), request_id, options));
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 sent_message_ports, new_routing_ids, 875 sent_message_ports, new_routing_ids,
866 main_thread_task_runner_); 876 main_thread_task_runner_);
867 877
868 blink::WebCrossOriginServiceWorkerClient web_client; 878 blink::WebCrossOriginServiceWorkerClient web_client;
869 web_client.origin = client.origin; 879 web_client.origin = client.origin;
870 web_client.targetURL = client.target_url; 880 web_client.targetURL = client.target_url;
871 web_client.clientID = client.message_port_id; 881 web_client.clientID = client.message_port_id;
872 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); 882 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports);
873 } 883 }
874 884
885 void ServiceWorkerContextClient::OnDidGetClient(
886 int request_id,
887 const ServiceWorkerClientInfo& client) {
888 TRACE_EVENT0("ServiceWorker", "ServiceWorkerContextClient::OnDidGetClient");
889 blink::WebServiceWorkerClientCallbacks* callbacks =
890 context_->client_callbacks.Lookup(request_id);
891 if (!callbacks) {
892 NOTREACHED() << "Got stray response: " << request_id;
893 return;
894 }
895 callbacks->onSuccess(adoptWebPtr(new blink::WebServiceWorkerClientInfo(
nhiroki 2016/02/19 05:18:31 It looks like this fails compile steps on Win bot.
jungkees 2016/02/22 14:05:09 Addressed. Also, I changed this part of the code t
896 ToWebServiceWorkerClientInfo(client))));
897 context_->client_callbacks.Remove(request_id);
898 }
899
875 void ServiceWorkerContextClient::OnDidGetClients( 900 void ServiceWorkerContextClient::OnDidGetClients(
876 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { 901 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) {
877 TRACE_EVENT0("ServiceWorker", 902 TRACE_EVENT0("ServiceWorker",
878 "ServiceWorkerContextClient::OnDidGetClients"); 903 "ServiceWorkerContextClient::OnDidGetClients");
879 blink::WebServiceWorkerClientsCallbacks* callbacks = 904 blink::WebServiceWorkerClientsCallbacks* callbacks =
880 context_->clients_callbacks.Lookup(request_id); 905 context_->clients_callbacks.Lookup(request_id);
881 if (!callbacks) { 906 if (!callbacks) {
882 NOTREACHED() << "Got stray response: " << request_id; 907 NOTREACHED() << "Got stray response: " << request_id;
883 return; 908 return;
884 } 909 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } 1065 }
1041 1066
1042 base::WeakPtr<ServiceWorkerContextClient> 1067 base::WeakPtr<ServiceWorkerContextClient>
1043 ServiceWorkerContextClient::GetWeakPtr() { 1068 ServiceWorkerContextClient::GetWeakPtr() {
1044 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1069 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1045 DCHECK(context_); 1070 DCHECK(context_);
1046 return context_->weak_factory.GetWeakPtr(); 1071 return context_->weak_factory.GetWeakPtr();
1047 } 1072 }
1048 1073
1049 } // namespace content 1074 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698