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

Side by Side Diff: components/gcm_driver/gcm_client_impl.cc

Issue 2697793004: Push API: Validate storage before returning cached subscriptions (Closed)
Patch Set: Fix include Created 3 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
« no previous file with comments | « components/gcm_driver/gcm_client_impl.h ('k') | components/gcm_driver/gcm_driver.h » ('j') | 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 "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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 871
872 // For GCM registration, we also match the sender IDs since multiple 872 // For GCM registration, we also match the sender IDs since multiple
873 // registrations are not supported. 873 // registrations are not supported.
874 const GCMRegistrationInfo* gcm_registration_info = 874 const GCMRegistrationInfo* gcm_registration_info =
875 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); 875 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
876 if (gcm_registration_info) { 876 if (gcm_registration_info) {
877 const GCMRegistrationInfo* cached_gcm_registration_info = 877 const GCMRegistrationInfo* cached_gcm_registration_info =
878 GCMRegistrationInfo::FromRegistrationInfo( 878 GCMRegistrationInfo::FromRegistrationInfo(
879 registrations_iter->first.get()); 879 registrations_iter->first.get());
880 DCHECK(cached_gcm_registration_info); 880 DCHECK(cached_gcm_registration_info);
881 if (cached_gcm_registration_info && 881 if (gcm_registration_info->sender_ids !=
882 gcm_registration_info->sender_ids != 882 cached_gcm_registration_info->sender_ids) {
883 cached_gcm_registration_info->sender_ids) {
884 matched = false; 883 matched = false;
885 } 884 }
886 } 885 }
887 886
888 if (matched) { 887 if (matched) {
889 delegate_->OnRegisterFinished( 888 delegate_->OnRegisterFinished(
890 registration_info, registrations_iter->second, SUCCESS); 889 registration_info, registrations_iter->second, SUCCESS);
891 return; 890 return;
892 } 891 }
893 } 892 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 991
993 delegate_->OnRegisterFinished( 992 delegate_->OnRegisterFinished(
994 registration_info, 993 registration_info,
995 result == SUCCESS ? registration_id : std::string(), 994 result == SUCCESS ? registration_id : std::string(),
996 result); 995 result);
997 996
998 if (iter != pending_registration_requests_.end()) 997 if (iter != pending_registration_requests_.end())
999 pending_registration_requests_.erase(iter); 998 pending_registration_requests_.erase(iter);
1000 } 999 }
1001 1000
1001 bool GCMClientImpl::ValidateRegistration(
1002 const linked_ptr<RegistrationInfo>& registration_info,
1003 const std::string& registration_id) {
1004 DCHECK_EQ(state_, READY);
1005
1006 // Must have a cached registration.
1007 RegistrationInfoMap::const_iterator registrations_iter =
1008 registrations_.find(registration_info);
1009 if (registrations_iter == registrations_.end())
1010 return false;
1011
1012 // Cached registration ID must match.
1013 const std::string& cached_registration_id = registrations_iter->second;
1014 if (registration_id != cached_registration_id)
1015 return false;
1016
1017 // For GCM registration, we also match the sender IDs since multiple
1018 // registrations are not supported.
1019 const GCMRegistrationInfo* gcm_registration_info =
1020 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
1021 if (gcm_registration_info) {
1022 const GCMRegistrationInfo* cached_gcm_registration_info =
1023 GCMRegistrationInfo::FromRegistrationInfo(
1024 registrations_iter->first.get());
1025 DCHECK(cached_gcm_registration_info);
1026 if (gcm_registration_info->sender_ids !=
1027 cached_gcm_registration_info->sender_ids) {
1028 return false;
1029 }
1030 }
1031
1032 return true;
1033 }
1034
1002 void GCMClientImpl::Unregister( 1035 void GCMClientImpl::Unregister(
1003 const linked_ptr<RegistrationInfo>& registration_info) { 1036 const linked_ptr<RegistrationInfo>& registration_info) {
1004 DCHECK_EQ(state_, READY); 1037 DCHECK_EQ(state_, READY);
1005 1038
1006 std::unique_ptr<UnregistrationRequest::CustomRequestHandler> request_handler; 1039 std::unique_ptr<UnregistrationRequest::CustomRequestHandler> request_handler;
1007 std::string source_to_record; 1040 std::string source_to_record;
1008 1041
1009 const GCMRegistrationInfo* gcm_registration_info = 1042 const GCMRegistrationInfo* gcm_registration_info =
1010 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); 1043 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
1011 if (gcm_registration_info) { 1044 if (gcm_registration_info) {
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 bool GCMClientImpl::HasStandaloneRegisteredApp() const { 1502 bool GCMClientImpl::HasStandaloneRegisteredApp() const {
1470 if (registrations_.empty()) 1503 if (registrations_.empty())
1471 return false; 1504 return false;
1472 // Note that account mapper is not counted as a standalone app since it is 1505 // Note that account mapper is not counted as a standalone app since it is
1473 // automatically started when other app uses GCM. 1506 // automatically started when other app uses GCM.
1474 return registrations_.size() > 1 || 1507 return registrations_.size() > 1 ||
1475 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); 1508 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId);
1476 } 1509 }
1477 1510
1478 } // namespace gcm 1511 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_client_impl.h ('k') | components/gcm_driver/gcm_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698