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

Side by Side Diff: content/browser/push_messaging/push_messaging_message_filter.cc

Issue 1079923002: ServiceWorker: Stop exposing ServiceWorkerContextCore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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 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/browser/push_messaging/push_messaging_message_filter.h" 5 #include "content/browser/push_messaging/push_messaging_message_filter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DCHECK_CURRENTLY_ON(BrowserThread::IO); 218 DCHECK_CURRENTLY_ON(BrowserThread::IO);
219 // TODO(mvanouwerkerk): Validate arguments? 219 // TODO(mvanouwerkerk): Validate arguments?
220 // TODO(peter): Persist |user_visible| in Service Worker storage. 220 // TODO(peter): Persist |user_visible| in Service Worker storage.
221 RegisterData data; 221 RegisterData data;
222 data.request_id = request_id; 222 data.request_id = request_id;
223 data.service_worker_registration_id = service_worker_registration_id; 223 data.service_worker_registration_id = service_worker_registration_id;
224 data.render_frame_id = render_frame_id; 224 data.render_frame_id = render_frame_id;
225 data.user_visible = user_visible; 225 data.user_visible = user_visible;
226 226
227 ServiceWorkerRegistration* service_worker_registration = 227 ServiceWorkerRegistration* service_worker_registration =
228 service_worker_context_->context()->GetLiveRegistration( 228 service_worker_context_->GetLiveRegistration(
229 service_worker_registration_id); 229 service_worker_registration_id);
230 if (!service_worker_registration || 230 if (!service_worker_registration ||
231 !service_worker_registration->active_version()) { 231 !service_worker_registration->active_version()) {
232 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER); 232 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER);
233 return; 233 return;
234 } 234 }
235 data.requesting_origin = service_worker_registration->pattern().GetOrigin(); 235 data.requesting_origin = service_worker_registration->pattern().GetOrigin();
236 236
237 service_worker_context_->context()->storage()->StoreUserData( 237 service_worker_context_->StoreRegistrationUserData(
238 service_worker_registration_id, 238 service_worker_registration_id,
239 data.requesting_origin, 239 data.requesting_origin,
240 kPushSenderIdServiceWorkerKey, 240 kPushSenderIdServiceWorkerKey,
241 sender_id, 241 sender_id,
242 base::Bind(&PushMessagingMessageFilter::DidPersistSenderId, 242 base::Bind(&PushMessagingMessageFilter::DidPersistSenderId,
243 weak_factory_io_to_io_.GetWeakPtr(), 243 weak_factory_io_to_io_.GetWeakPtr(),
244 data, sender_id)); 244 data, sender_id));
245 } 245 }
246 246
247 void PushMessagingMessageFilter::OnRegisterFromWorker( 247 void PushMessagingMessageFilter::OnRegisterFromWorker(
248 int request_id, 248 int request_id,
249 int64_t service_worker_registration_id, 249 int64_t service_worker_registration_id,
250 bool user_visible) { 250 bool user_visible) {
251 DCHECK_CURRENTLY_ON(BrowserThread::IO); 251 DCHECK_CURRENTLY_ON(BrowserThread::IO);
252 RegisterData data; 252 RegisterData data;
253 data.request_id = request_id; 253 data.request_id = request_id;
254 data.service_worker_registration_id = service_worker_registration_id; 254 data.service_worker_registration_id = service_worker_registration_id;
255 data.user_visible = user_visible; 255 data.user_visible = user_visible;
256 256
257 ServiceWorkerRegistration* service_worker_registration = 257 ServiceWorkerRegistration* service_worker_registration =
258 service_worker_context_->context()->GetLiveRegistration( 258 service_worker_context_->GetLiveRegistration(
259 service_worker_registration_id); 259 service_worker_registration_id);
260 if (!service_worker_registration) { 260 if (!service_worker_registration) {
261 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER); 261 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER);
262 return; 262 return;
263 } 263 }
264 data.requesting_origin = service_worker_registration->pattern().GetOrigin(); 264 data.requesting_origin = service_worker_registration->pattern().GetOrigin();
265 265
266 // This sender_id will be ignored; instead it will be fetched from storage. 266 // This sender_id will be ignored; instead it will be fetched from storage.
267 CheckForExistingRegistration(data, std::string() /* sender_id */); 267 CheckForExistingRegistration(data, std::string() /* sender_id */);
268 } 268 }
269 269
270 void PushMessagingMessageFilter::DidPersistSenderId( 270 void PushMessagingMessageFilter::DidPersistSenderId(
271 const RegisterData& data, 271 const RegisterData& data,
272 const std::string& sender_id, 272 const std::string& sender_id,
273 ServiceWorkerStatusCode service_worker_status) { 273 ServiceWorkerStatusCode service_worker_status) {
274 DCHECK_CURRENTLY_ON(BrowserThread::IO); 274 DCHECK_CURRENTLY_ON(BrowserThread::IO);
275 if (service_worker_status != SERVICE_WORKER_OK) 275 if (service_worker_status != SERVICE_WORKER_OK)
276 SendRegisterError(data, PUSH_REGISTRATION_STATUS_STORAGE_ERROR); 276 SendRegisterError(data, PUSH_REGISTRATION_STATUS_STORAGE_ERROR);
277 else 277 else
278 CheckForExistingRegistration(data, sender_id); 278 CheckForExistingRegistration(data, sender_id);
279 } 279 }
280 280
281 void PushMessagingMessageFilter::CheckForExistingRegistration( 281 void PushMessagingMessageFilter::CheckForExistingRegistration(
282 const RegisterData& data, 282 const RegisterData& data,
283 const std::string& sender_id) { 283 const std::string& sender_id) {
284 DCHECK_CURRENTLY_ON(BrowserThread::IO); 284 DCHECK_CURRENTLY_ON(BrowserThread::IO);
285 service_worker_context_->context()->storage()->GetUserData( 285 service_worker_context_->GetRegistrationUserData(
286 data.service_worker_registration_id, 286 data.service_worker_registration_id,
287 kPushRegistrationIdServiceWorkerKey, 287 kPushRegistrationIdServiceWorkerKey,
288 base::Bind(&PushMessagingMessageFilter::DidCheckForExistingRegistration, 288 base::Bind(&PushMessagingMessageFilter::DidCheckForExistingRegistration,
289 weak_factory_io_to_io_.GetWeakPtr(), data, sender_id)); 289 weak_factory_io_to_io_.GetWeakPtr(), data, sender_id));
290 } 290 }
291 291
292 void PushMessagingMessageFilter::DidCheckForExistingRegistration( 292 void PushMessagingMessageFilter::DidCheckForExistingRegistration(
293 const RegisterData& data, 293 const RegisterData& data,
294 const std::string& sender_id, 294 const std::string& sender_id,
295 const std::string& push_registration_id, 295 const std::string& push_registration_id,
296 ServiceWorkerStatusCode service_worker_status) { 296 ServiceWorkerStatusCode service_worker_status) {
297 DCHECK_CURRENTLY_ON(BrowserThread::IO); 297 DCHECK_CURRENTLY_ON(BrowserThread::IO);
298 if (service_worker_status == SERVICE_WORKER_OK) { 298 if (service_worker_status == SERVICE_WORKER_OK) {
299 SendRegisterSuccess(data, PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE, 299 SendRegisterSuccess(data, PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE,
300 push_registration_id); 300 push_registration_id);
301 return; 301 return;
302 } 302 }
303 // TODO(johnme): The spec allows the register algorithm to reject with an 303 // TODO(johnme): The spec allows the register algorithm to reject with an
304 // AbortError when accessing storage fails. Perhaps we should do that if 304 // AbortError when accessing storage fails. Perhaps we should do that if
305 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of 305 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of
306 // attempting to do a fresh registration? 306 // attempting to do a fresh registration?
307 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration 307 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration
308 if (data.FromDocument()) { 308 if (data.FromDocument()) {
309 BrowserThread::PostTask( 309 BrowserThread::PostTask(
310 BrowserThread::UI, FROM_HERE, 310 BrowserThread::UI, FROM_HERE,
311 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), 311 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()),
312 data, sender_id)); 312 data, sender_id));
313 } else { 313 } else {
314 service_worker_context_->context()->storage()->GetUserData( 314 service_worker_context_->GetRegistrationUserData(
315 data.service_worker_registration_id, 315 data.service_worker_registration_id,
316 kPushSenderIdServiceWorkerKey, 316 kPushSenderIdServiceWorkerKey,
317 base::Bind(&PushMessagingMessageFilter::DidGetSenderIdFromStorage, 317 base::Bind(&PushMessagingMessageFilter::DidGetSenderIdFromStorage,
318 weak_factory_io_to_io_.GetWeakPtr(), data)); 318 weak_factory_io_to_io_.GetWeakPtr(), data));
319 } 319 }
320 } 320 }
321 321
322 void PushMessagingMessageFilter::DidGetSenderIdFromStorage( 322 void PushMessagingMessageFilter::DidGetSenderIdFromStorage(
323 const RegisterData& data, 323 const RegisterData& data,
324 const std::string& sender_id, 324 const std::string& sender_id,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 BrowserThread::IO, FROM_HERE, 396 BrowserThread::IO, FROM_HERE,
397 base::Bind(&PushMessagingMessageFilter::SendRegisterError, io_parent_, 397 base::Bind(&PushMessagingMessageFilter::SendRegisterError, io_parent_,
398 data, status)); 398 data, status));
399 } 399 }
400 } 400 }
401 401
402 void PushMessagingMessageFilter::PersistRegistrationOnIO( 402 void PushMessagingMessageFilter::PersistRegistrationOnIO(
403 const RegisterData& data, 403 const RegisterData& data,
404 const std::string& push_registration_id) { 404 const std::string& push_registration_id) {
405 DCHECK_CURRENTLY_ON(BrowserThread::IO); 405 DCHECK_CURRENTLY_ON(BrowserThread::IO);
406 service_worker_context_->context()->storage()->StoreUserData( 406 service_worker_context_->StoreRegistrationUserData(
407 data.service_worker_registration_id, 407 data.service_worker_registration_id,
408 data.requesting_origin, 408 data.requesting_origin,
409 kPushRegistrationIdServiceWorkerKey, 409 kPushRegistrationIdServiceWorkerKey,
410 push_registration_id, 410 push_registration_id,
411 base::Bind(&PushMessagingMessageFilter::DidPersistRegistrationOnIO, 411 base::Bind(&PushMessagingMessageFilter::DidPersistRegistrationOnIO,
412 weak_factory_io_to_io_.GetWeakPtr(), 412 weak_factory_io_to_io_.GetWeakPtr(),
413 data, push_registration_id)); 413 data, push_registration_id));
414 } 414 }
415 415
416 void PushMessagingMessageFilter::DidPersistRegistrationOnIO( 416 void PushMessagingMessageFilter::DidPersistRegistrationOnIO(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 467 }
468 468
469 // Unregister methods on both IO and UI threads, merged in order of use from 469 // Unregister methods on both IO and UI threads, merged in order of use from
470 // PushMessagingMessageFilter and Core. 470 // PushMessagingMessageFilter and Core.
471 // ----------------------------------------------------------------------------- 471 // -----------------------------------------------------------------------------
472 472
473 void PushMessagingMessageFilter::OnUnregister( 473 void PushMessagingMessageFilter::OnUnregister(
474 int request_id, int64_t service_worker_registration_id) { 474 int request_id, int64_t service_worker_registration_id) {
475 DCHECK_CURRENTLY_ON(BrowserThread::IO); 475 DCHECK_CURRENTLY_ON(BrowserThread::IO);
476 ServiceWorkerRegistration* service_worker_registration = 476 ServiceWorkerRegistration* service_worker_registration =
477 service_worker_context_->context()->GetLiveRegistration( 477 service_worker_context_->GetLiveRegistration(
478 service_worker_registration_id); 478 service_worker_registration_id);
479 if (!service_worker_registration) { 479 if (!service_worker_registration) {
480 DidUnregister(request_id, PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER); 480 DidUnregister(request_id, PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER);
481 return; 481 return;
482 } 482 }
483 483
484 service_worker_context_->context()->storage()->GetUserData( 484 service_worker_context_->GetRegistrationUserData(
485 service_worker_registration_id, 485 service_worker_registration_id,
486 kPushRegistrationIdServiceWorkerKey, 486 kPushRegistrationIdServiceWorkerKey,
487 base::Bind( 487 base::Bind(
488 &PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId, 488 &PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId,
489 weak_factory_io_to_io_.GetWeakPtr(), request_id, 489 weak_factory_io_to_io_.GetWeakPtr(), request_id,
490 service_worker_registration_id, 490 service_worker_registration_id,
491 service_worker_registration->pattern().GetOrigin())); 491 service_worker_registration->pattern().GetOrigin()));
492 } 492 }
493 493
494 void PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId( 494 void PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId(
495 int request_id, 495 int request_id,
496 int64_t service_worker_registration_id, 496 int64_t service_worker_registration_id,
497 const GURL& requesting_origin, 497 const GURL& requesting_origin,
498 const std::string& push_registration_id, // Unused, we just want the status 498 const std::string& push_registration_id, // Unused, we just want the status
499 ServiceWorkerStatusCode service_worker_status) { 499 ServiceWorkerStatusCode service_worker_status) {
500 DCHECK_CURRENTLY_ON(BrowserThread::IO); 500 DCHECK_CURRENTLY_ON(BrowserThread::IO);
501 501
502 if (service_worker_status == SERVICE_WORKER_OK) { 502 if (service_worker_status == SERVICE_WORKER_OK) {
503 service_worker_context_->context()->storage()->GetUserData( 503 service_worker_context_->GetRegistrationUserData(
504 service_worker_registration_id, 504 service_worker_registration_id,
505 kPushSenderIdServiceWorkerKey, 505 kPushSenderIdServiceWorkerKey,
506 base::Bind( 506 base::Bind(
507 &PushMessagingMessageFilter::UnregisterHavingGottenSenderId, 507 &PushMessagingMessageFilter::UnregisterHavingGottenSenderId,
508 weak_factory_io_to_io_.GetWeakPtr(), 508 weak_factory_io_to_io_.GetWeakPtr(),
509 request_id, 509 request_id,
510 service_worker_registration_id, 510 service_worker_registration_id,
511 requesting_origin)); 511 requesting_origin));
512 } else { 512 } else {
513 // Errors are handled the same, whether we were trying to get the 513 // Errors are handled the same, whether we were trying to get the
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 break; 618 break;
619 } 619 }
620 } 620 }
621 621
622 void PushMessagingMessageFilter::ClearRegistrationData( 622 void PushMessagingMessageFilter::ClearRegistrationData(
623 int request_id, 623 int request_id,
624 int64_t service_worker_registration_id, 624 int64_t service_worker_registration_id,
625 PushUnregistrationStatus unregistration_status) { 625 PushUnregistrationStatus unregistration_status) {
626 DCHECK_CURRENTLY_ON(BrowserThread::IO); 626 DCHECK_CURRENTLY_ON(BrowserThread::IO);
627 627
628 service_worker_context_->context()->storage()->ClearUserData( 628 service_worker_context_->ClearRegistrationUserData(
629 service_worker_registration_id, 629 service_worker_registration_id,
630 kPushRegistrationIdServiceWorkerKey, 630 kPushRegistrationIdServiceWorkerKey,
631 base::Bind(&PushMessagingMessageFilter::DidClearRegistrationData, 631 base::Bind(&PushMessagingMessageFilter::DidClearRegistrationData,
632 weak_factory_io_to_io_.GetWeakPtr(), 632 weak_factory_io_to_io_.GetWeakPtr(),
633 request_id, unregistration_status)); 633 request_id, unregistration_status));
634 } 634 }
635 635
636 void PushMessagingMessageFilter::DidClearRegistrationData( 636 void PushMessagingMessageFilter::DidClearRegistrationData(
637 int request_id, 637 int request_id,
638 PushUnregistrationStatus unregistration_status, 638 PushUnregistrationStatus unregistration_status,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 679
680 // GetRegistration methods on both IO and UI threads, merged in order of use 680 // GetRegistration methods on both IO and UI threads, merged in order of use
681 // from PushMessagingMessageFilter and Core. 681 // from PushMessagingMessageFilter and Core.
682 // ----------------------------------------------------------------------------- 682 // -----------------------------------------------------------------------------
683 683
684 void PushMessagingMessageFilter::OnGetRegistration( 684 void PushMessagingMessageFilter::OnGetRegistration(
685 int request_id, 685 int request_id,
686 int64_t service_worker_registration_id) { 686 int64_t service_worker_registration_id) {
687 DCHECK_CURRENTLY_ON(BrowserThread::IO); 687 DCHECK_CURRENTLY_ON(BrowserThread::IO);
688 // TODO(johnme): Validate arguments? 688 // TODO(johnme): Validate arguments?
689 service_worker_context_->context()->storage()->GetUserData( 689 service_worker_context_->GetRegistrationUserData(
690 service_worker_registration_id, 690 service_worker_registration_id,
691 kPushRegistrationIdServiceWorkerKey, 691 kPushRegistrationIdServiceWorkerKey,
692 base::Bind(&PushMessagingMessageFilter::DidGetRegistration, 692 base::Bind(&PushMessagingMessageFilter::DidGetRegistration,
693 weak_factory_io_to_io_.GetWeakPtr(), request_id)); 693 weak_factory_io_to_io_.GetWeakPtr(), request_id));
694 } 694 }
695 695
696 void PushMessagingMessageFilter::DidGetRegistration( 696 void PushMessagingMessageFilter::DidGetRegistration(
697 int request_id, 697 int request_id,
698 const std::string& push_registration_id, 698 const std::string& push_registration_id,
699 ServiceWorkerStatusCode service_worker_status) { 699 ServiceWorkerStatusCode service_worker_status) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // GetPermission methods on both IO and UI threads, merged in order of use from 747 // GetPermission methods on both IO and UI threads, merged in order of use from
748 // PushMessagingMessageFilter and Core. 748 // PushMessagingMessageFilter and Core.
749 // ----------------------------------------------------------------------------- 749 // -----------------------------------------------------------------------------
750 750
751 void PushMessagingMessageFilter::OnGetPermissionStatus( 751 void PushMessagingMessageFilter::OnGetPermissionStatus(
752 int request_id, 752 int request_id,
753 int64_t service_worker_registration_id, 753 int64_t service_worker_registration_id,
754 bool user_visible) { 754 bool user_visible) {
755 DCHECK_CURRENTLY_ON(BrowserThread::IO); 755 DCHECK_CURRENTLY_ON(BrowserThread::IO);
756 ServiceWorkerRegistration* service_worker_registration = 756 ServiceWorkerRegistration* service_worker_registration =
757 service_worker_context_->context()->GetLiveRegistration( 757 service_worker_context_->GetLiveRegistration(
758 service_worker_registration_id); 758 service_worker_registration_id);
759 if (!service_worker_registration) { 759 if (!service_worker_registration) {
760 Send(new PushMessagingMsg_GetPermissionStatusError(request_id)); 760 Send(new PushMessagingMsg_GetPermissionStatusError(request_id));
761 return; 761 return;
762 } 762 }
763 763
764 BrowserThread::PostTask( 764 BrowserThread::PostTask(
765 BrowserThread::UI, FROM_HERE, 765 BrowserThread::UI, FROM_HERE,
766 base::Bind(&Core::GetPermissionStatusOnUI, 766 base::Bind(&Core::GetPermissionStatusOnUI,
767 base::Unretained(ui_core_.get()), 767 base::Unretained(ui_core_.get()),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 PushMessagingService* PushMessagingMessageFilter::Core::service() { 808 PushMessagingService* PushMessagingMessageFilter::Core::service() {
809 DCHECK_CURRENTLY_ON(BrowserThread::UI); 809 DCHECK_CURRENTLY_ON(BrowserThread::UI);
810 RenderProcessHost* process_host = 810 RenderProcessHost* process_host =
811 RenderProcessHost::FromID(render_process_id_); 811 RenderProcessHost::FromID(render_process_id_);
812 return process_host 812 return process_host
813 ? process_host->GetBrowserContext()->GetPushMessagingService() 813 ? process_host->GetBrowserContext()->GetPushMessagingService()
814 : nullptr; 814 : nullptr;
815 } 815 }
816 816
817 } // namespace content 817 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698