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

Side by Side Diff: components/gcm_driver/gcm_client_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 "components/gcm_driver/gcm_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 992
993 delegate_->OnRegisterFinished( 993 delegate_->OnRegisterFinished(
994 registration_info, 994 registration_info,
995 result == SUCCESS ? registration_id : std::string(), 995 result == SUCCESS ? registration_id : std::string(),
996 result); 996 result);
997 997
998 if (iter != pending_registration_requests_.end()) 998 if (iter != pending_registration_requests_.end())
999 pending_registration_requests_.erase(iter); 999 pending_registration_requests_.erase(iter);
1000 } 1000 }
1001 1001
1002 bool GCMClientImpl::ValidateRegistration(
1003 const linked_ptr<RegistrationInfo>& registration_info,
1004 const std::string& registration_id) {
1005 DCHECK_EQ(state_, READY);
1006
1007 // Must have a cached registration.
1008 RegistrationInfoMap::const_iterator registrations_iter =
1009 registrations_.find(registration_info);
1010 if (registrations_iter == registrations_.end())
1011 return false;
1012
1013 // Cached registration ID must match.
1014 const std::string& cached_registration_id = registrations_iter->second;
1015 if (registration_id != cached_registration_id)
1016 return false;
1017
1018 // For GCM registration, we also match the sender IDs since multiple
1019 // registrations are not supported.
1020 const GCMRegistrationInfo* gcm_registration_info =
1021 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
1022 if (gcm_registration_info) {
1023 const GCMRegistrationInfo* cached_gcm_registration_info =
1024 GCMRegistrationInfo::FromRegistrationInfo(
1025 registrations_iter->first.get());
1026 DCHECK(cached_gcm_registration_info);
1027 if (cached_gcm_registration_info &&
Peter Beverloo 2017/03/20 23:50:13 nit: don't have to be nice for |!cached_gcm_regist
johnme 2017/03/30 18:36:38 M'ok. In that case I'll also remove the niceness f
1028 gcm_registration_info->sender_ids !=
1029 cached_gcm_registration_info->sender_ids) {
1030 return false;
1031 }
1032 }
1033
1034 return true;
1035 }
1036
1002 void GCMClientImpl::Unregister( 1037 void GCMClientImpl::Unregister(
1003 const linked_ptr<RegistrationInfo>& registration_info) { 1038 const linked_ptr<RegistrationInfo>& registration_info) {
1004 DCHECK_EQ(state_, READY); 1039 DCHECK_EQ(state_, READY);
1005 1040
1006 std::unique_ptr<UnregistrationRequest::CustomRequestHandler> request_handler; 1041 std::unique_ptr<UnregistrationRequest::CustomRequestHandler> request_handler;
1007 std::string source_to_record; 1042 std::string source_to_record;
1008 1043
1009 const GCMRegistrationInfo* gcm_registration_info = 1044 const GCMRegistrationInfo* gcm_registration_info =
1010 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); 1045 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
1011 if (gcm_registration_info) { 1046 if (gcm_registration_info) {
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 bool GCMClientImpl::HasStandaloneRegisteredApp() const { 1504 bool GCMClientImpl::HasStandaloneRegisteredApp() const {
1470 if (registrations_.empty()) 1505 if (registrations_.empty())
1471 return false; 1506 return false;
1472 // Note that account mapper is not counted as a standalone app since it is 1507 // Note that account mapper is not counted as a standalone app since it is
1473 // automatically started when other app uses GCM. 1508 // automatically started when other app uses GCM.
1474 return registrations_.size() > 1 || 1509 return registrations_.size() > 1 ||
1475 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); 1510 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId);
1476 } 1511 }
1477 1512
1478 } // namespace gcm 1513 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698