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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_service_impl.cc

Issue 2697793004: Push API: Validate storage before returning cached subscriptions (Closed)
Patch Set: Comment out PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE Created 3 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 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 "chrome/browser/push_messaging/push_messaging_service_impl.h" 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/base64url.h" 10 #include "base/base64url.h"
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 app_identifier.PersistToPrefs(profile_); 621 app_identifier.PersistToPrefs(profile_);
622 622
623 IncreasePushSubscriptionCount(1, false /* is_pending */); 623 IncreasePushSubscriptionCount(1, false /* is_pending */);
624 624
625 SubscribeEnd(callback, subscription_id, 625 SubscribeEnd(callback, subscription_id,
626 std::vector<uint8_t>(p256dh.begin(), p256dh.end()), 626 std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
627 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()), 627 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()),
628 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE); 628 content::PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
629 } 629 }
630 630
631 // GetEncryptionInfo methods --------------------------------------------------- 631 // GetSubscriptionInfo methods
632 // ---------------------------------------------------
Peter Beverloo 2017/03/20 23:50:13 nit: dito
johnme 2017/03/30 18:36:38 Done.
632 633
633 void PushMessagingServiceImpl::GetEncryptionInfo( 634 void PushMessagingServiceImpl::GetSubscriptionInfo(
634 const GURL& origin, 635 const GURL& origin,
635 int64_t service_worker_registration_id, 636 int64_t service_worker_registration_id,
636 const std::string& sender_id, 637 const std::string& sender_id,
637 const PushMessagingService::EncryptionInfoCallback& callback) { 638 const std::string& subscription_id,
639 const SubscriptionInfoCallback& callback) {
638 PushMessagingAppIdentifier app_identifier = 640 PushMessagingAppIdentifier app_identifier =
639 PushMessagingAppIdentifier::FindByServiceWorker( 641 PushMessagingAppIdentifier::FindByServiceWorker(
640 profile_, origin, service_worker_registration_id); 642 profile_, origin, service_worker_registration_id);
641 643
642 DCHECK(!app_identifier.is_null()); 644 if (app_identifier.is_null()) {
645 callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
646 std::vector<uint8_t>() /* auth */);
647 return;
648 }
649
650 const std::string& app_id = app_identifier.app_id();
651 base::Callback<void(bool)> validate_cb =
652 base::Bind(&PushMessagingServiceImpl::DidValidateSubscription,
653 weak_factory_.GetWeakPtr(), app_id, sender_id, callback);
654
655 if (PushMessagingAppIdentifier::UseInstanceID(app_id)) {
656 GetInstanceIDDriver()->GetInstanceID(app_id)->ValidateToken(
657 NormalizeSenderInfo(sender_id), kGCMScope, subscription_id,
658 validate_cb);
659 } else {
660 GetGCMDriver()->ValidateRegistration(
661 app_id, {NormalizeSenderInfo(sender_id)}, subscription_id, validate_cb);
662 }
663 }
664
665 void PushMessagingServiceImpl::DidValidateSubscription(
666 const std::string& app_id,
667 const std::string& sender_id,
668 const SubscriptionInfoCallback& callback,
669 bool is_valid) {
670 if (!is_valid) {
671 callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
672 std::vector<uint8_t>() /* auth */);
673 return;
674 }
643 675
644 GetEncryptionInfoForAppId( 676 GetEncryptionInfoForAppId(
645 app_identifier.app_id(), sender_id, 677 app_id, sender_id,
646 base::Bind(&PushMessagingServiceImpl::DidGetEncryptionInfo, 678 base::Bind(&PushMessagingServiceImpl::DidGetEncryptionInfo,
647 weak_factory_.GetWeakPtr(), callback)); 679 weak_factory_.GetWeakPtr(), callback));
648 } 680 }
649 681
650 void PushMessagingServiceImpl::DidGetEncryptionInfo( 682 void PushMessagingServiceImpl::DidGetEncryptionInfo(
651 const PushMessagingService::EncryptionInfoCallback& callback, 683 const SubscriptionInfoCallback& callback,
652 const std::string& p256dh, 684 const std::string& p256dh,
653 const std::string& auth_secret) const { 685 const std::string& auth_secret) const {
654 // I/O errors might prevent the GCM Driver from retrieving a key-pair. 686 // I/O errors might prevent the GCM Driver from retrieving a key-pair.
655 const bool success = !p256dh.empty(); 687 bool is_valid = !p256dh.empty();
656 688 callback.Run(is_valid, std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
657 callback.Run(success, std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
658 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end())); 689 std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()));
659 } 690 }
660 691
661 // Unsubscribe methods --------------------------------------------------------- 692 // Unsubscribe methods ---------------------------------------------------------
662 693
663 void PushMessagingServiceImpl::Unsubscribe( 694 void PushMessagingServiceImpl::Unsubscribe(
695 content::PushUnregistrationReason reason,
664 const GURL& requesting_origin, 696 const GURL& requesting_origin,
665 int64_t service_worker_registration_id, 697 int64_t service_worker_registration_id,
666 const std::string& sender_id, 698 const std::string& sender_id,
667 const UnregisterCallback& callback) { 699 const UnregisterCallback& callback) {
668 PushMessagingAppIdentifier app_identifier = 700 PushMessagingAppIdentifier app_identifier =
669 PushMessagingAppIdentifier::FindByServiceWorker( 701 PushMessagingAppIdentifier::FindByServiceWorker(
670 profile_, requesting_origin, service_worker_registration_id); 702 profile_, requesting_origin, service_worker_registration_id);
671 703
672 UnsubscribeInternal( 704 UnsubscribeInternal(
673 content::PUSH_UNREGISTRATION_REASON_JAVASCRIPT_API, requesting_origin, 705 reason, requesting_origin, service_worker_registration_id,
674 service_worker_registration_id,
675 app_identifier.is_null() ? std::string() : app_identifier.app_id(), 706 app_identifier.is_null() ? std::string() : app_identifier.app_id(),
676 sender_id, callback); 707 sender_id, callback);
677 } 708 }
678 709
679 void PushMessagingServiceImpl::UnsubscribeInternal( 710 void PushMessagingServiceImpl::UnsubscribeInternal(
680 content::PushUnregistrationReason reason, 711 content::PushUnregistrationReason reason,
681 const GURL& origin, 712 const GURL& origin,
682 int64_t service_worker_registration_id, 713 int64_t service_worker_registration_id,
683 const std::string& app_id, 714 const std::string& app_id,
684 const std::string& sender_id, 715 const std::string& sender_id,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 1015 }
985 1016
986 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() 1017 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver()
987 const { 1018 const {
988 instance_id::InstanceIDProfileService* instance_id_profile_service = 1019 instance_id::InstanceIDProfileService* instance_id_profile_service =
989 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); 1020 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_);
990 CHECK(instance_id_profile_service); 1021 CHECK(instance_id_profile_service);
991 CHECK(instance_id_profile_service->driver()); 1022 CHECK(instance_id_profile_service->driver());
992 return instance_id_profile_service->driver(); 1023 return instance_id_profile_service->driver();
993 } 1024 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698