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

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

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove assignment within conditional expression Created 5 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
« no previous file with comments | « content/renderer/service_worker/service_worker_script_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_script_context.h" 5 #include "content/renderer/service_worker/service_worker_script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/child/notifications/notification_data_conversions.h" 10 #include "content/child/notifications/notification_data_conversions.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, 99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent,
100 OnCrossOriginConnectEvent) 100 OnCrossOriginConnectEvent)
101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) 101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, 102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker,
103 OnCrossOriginMessageToWorker) 103 OnCrossOriginMessageToWorker)
104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, 104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments,
105 OnDidGetClientDocuments) 105 OnDidGetClientDocuments)
106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
107 OnFocusClientResponse) 107 OnFocusClientResponse)
108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting)
109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients)
110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError)
109 IPC_MESSAGE_UNHANDLED(handled = false) 111 IPC_MESSAGE_UNHANDLED(handled = false)
110 IPC_END_MESSAGE_MAP() 112 IPC_END_MESSAGE_MAP()
111 113
112 // TODO(gavinp): Would it be preferable to put an AddListener() method to 114 // TODO(gavinp): Would it be preferable to put an AddListener() method to
113 // EmbeddedWorkerContextClient? 115 // EmbeddedWorkerContextClient?
114 if (!handled) 116 if (!handled)
115 handled = cache_storage_dispatcher_->OnMessageReceived(message); 117 handled = cache_storage_dispatcher_->OnMessageReceived(message);
116 118
117 DCHECK(handled); 119 DCHECK(handled);
118 } 120 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 238 }
237 239
238 void ServiceWorkerScriptContext::FocusClient( 240 void ServiceWorkerScriptContext::FocusClient(
239 int client_id, blink::WebServiceWorkerClientFocusCallback* callback) { 241 int client_id, blink::WebServiceWorkerClientFocusCallback* callback) {
240 DCHECK(callback); 242 DCHECK(callback);
241 int request_id = pending_focus_client_callbacks_.Add(callback); 243 int request_id = pending_focus_client_callbacks_.Add(callback);
242 Send(new ServiceWorkerHostMsg_FocusClient( 244 Send(new ServiceWorkerHostMsg_FocusClient(
243 GetRoutingID(), request_id, client_id)); 245 GetRoutingID(), request_id, client_id));
244 } 246 }
245 247
248 void ServiceWorkerScriptContext::ClaimClients(
249 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) {
250 DCHECK(callbacks);
251 int request_id = pending_claim_clients_callbacks_.Add(callbacks);
252 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id));
253 }
254
246 void ServiceWorkerScriptContext::SkipWaiting( 255 void ServiceWorkerScriptContext::SkipWaiting(
247 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { 256 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) {
248 DCHECK(callbacks); 257 DCHECK(callbacks);
249 int request_id = pending_skip_waiting_callbacks_.Add(callbacks); 258 int request_id = pending_skip_waiting_callbacks_.Add(callbacks);
250 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); 259 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id));
251 } 260 }
252 261
253 void ServiceWorkerScriptContext::Send(IPC::Message* message) { 262 void ServiceWorkerScriptContext::Send(IPC::Message* message) {
254 embedded_context_->Send(message); 263 embedded_context_->Send(message);
255 } 264 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = 462 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks =
454 pending_skip_waiting_callbacks_.Lookup(request_id); 463 pending_skip_waiting_callbacks_.Lookup(request_id);
455 if (!callbacks) { 464 if (!callbacks) {
456 NOTREACHED() << "Got stray response: " << request_id; 465 NOTREACHED() << "Got stray response: " << request_id;
457 return; 466 return;
458 } 467 }
459 callbacks->onSuccess(); 468 callbacks->onSuccess();
460 pending_skip_waiting_callbacks_.Remove(request_id); 469 pending_skip_waiting_callbacks_.Remove(request_id);
461 } 470 }
462 471
472 void ServiceWorkerScriptContext::OnDidClaimClients(int request_id) {
473 TRACE_EVENT0("ServiceWorker",
474 "ServiceWorkerScriptContext::OnDidClaimClients");
475 blink::WebServiceWorkerClientsClaimCallbacks* callbacks =
476 pending_claim_clients_callbacks_.Lookup(request_id);
477 if (!callbacks) {
478 NOTREACHED() << "Got stray response: " << request_id;
479 return;
480 }
481 callbacks->onSuccess();
482 pending_claim_clients_callbacks_.Remove(request_id);
483 }
484
485 void ServiceWorkerScriptContext::OnClaimClientsError(
486 int request_id,
487 blink::WebServiceWorkerError::ErrorType error_type,
488 const base::string16& message) {
489 TRACE_EVENT0("ServiceWorker",
490 "ServiceWorkerScriptContext::OnClaimClientsError");
491 blink::WebServiceWorkerClientsClaimCallbacks* callbacks =
492 pending_claim_clients_callbacks_.Lookup(request_id);
493 if (!callbacks) {
494 NOTREACHED() << "Got stray response: " << request_id;
495 return;
496 }
497 scoped_ptr<blink::WebServiceWorkerError> error(
498 new blink::WebServiceWorkerError(error_type, message));
499 callbacks->onError(error.release());
500 pending_claim_clients_callbacks_.Remove(request_id);
501 }
502
463 } // namespace content 503 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_script_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698