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

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

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Fix Mac compile. Created 5 years, 6 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) 296 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder)
297 : internals_builder_(internals_builder.Pass()), 297 : internals_builder_(internals_builder.Pass()),
298 state_(UNINITIALIZED), 298 state_(UNINITIALIZED),
299 delegate_(NULL), 299 delegate_(NULL),
300 start_mode_(DELAYED_START), 300 start_mode_(DELAYED_START),
301 clock_(internals_builder_->BuildClock()), 301 clock_(internals_builder_->BuildClock()),
302 gcm_store_reset_(false), 302 gcm_store_reset_(false),
303 url_request_context_getter_(NULL), 303 url_request_context_getter_(NULL),
304 pending_registration_requests_deleter_(&pending_registration_requests_),
305 pending_unregistration_requests_deleter_(
306 &pending_unregistration_requests_),
307 periodic_checkin_ptr_factory_(this), 304 periodic_checkin_ptr_factory_(this),
308 destroying_gcm_store_ptr_factory_(this), 305 destroying_gcm_store_ptr_factory_(this),
309 weak_ptr_factory_(this) { 306 weak_ptr_factory_(this) {
310 } 307 }
311 308
312 GCMClientImpl::~GCMClientImpl() { 309 GCMClientImpl::~GCMClientImpl() {
313 } 310 }
314 311
315 void GCMClientImpl::Initialize( 312 void GCMClientImpl::Initialize(
316 const ChromeBuildInfo& chrome_build_info, 313 const ChromeBuildInfo& chrome_build_info,
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 828
832 void GCMClientImpl::ResetCache() { 829 void GCMClientImpl::ResetCache() {
833 weak_ptr_factory_.InvalidateWeakPtrs(); 830 weak_ptr_factory_.InvalidateWeakPtrs();
834 periodic_checkin_ptr_factory_.InvalidateWeakPtrs(); 831 periodic_checkin_ptr_factory_.InvalidateWeakPtrs();
835 device_checkin_info_.Reset(); 832 device_checkin_info_.Reset();
836 connection_factory_.reset(); 833 connection_factory_.reset();
837 delegate_->OnDisconnected(); 834 delegate_->OnDisconnected();
838 mcs_client_.reset(); 835 mcs_client_.reset();
839 checkin_request_.reset(); 836 checkin_request_.reset();
840 // Delete all of the pending registration and unregistration requests. 837 // Delete all of the pending registration and unregistration requests.
841 STLDeleteValues(&pending_registration_requests_); 838 pending_registration_requests_.clear();
842 STLDeleteValues(&pending_unregistration_requests_); 839 pending_unregistration_requests_.clear();
843 } 840 }
844 841
845 void GCMClientImpl::Register( 842 void GCMClientImpl::Register(
846 const linked_ptr<RegistrationInfo>& registration_info) { 843 const linked_ptr<RegistrationInfo>& registration_info) {
847 DCHECK_EQ(state_, READY); 844 DCHECK_EQ(state_, READY);
848 845
849 // Find and use the cached registration ID. 846 // Find and use the cached registration ID.
850 RegistrationInfoMap::const_iterator registrations_iter = 847 RegistrationInfoMap::const_iterator registrations_iter =
851 registrations_.find(registration_info); 848 registrations_.find(registration_info);
852 if (registrations_iter != registrations_.end()) { 849 if (registrations_iter != registrations_.end()) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 ConstructGCMVersion(chrome_build_info_.version), 906 ConstructGCMVersion(chrome_build_info_.version),
910 instance_id_token_info->options)); 907 instance_id_token_info->options));
911 source_to_record = instance_id_token_info->authorized_entity; 908 source_to_record = instance_id_token_info->authorized_entity;
912 } 909 }
913 910
914 RegistrationRequest::RequestInfo request_info( 911 RegistrationRequest::RequestInfo request_info(
915 device_checkin_info_.android_id, 912 device_checkin_info_.android_id,
916 device_checkin_info_.secret, 913 device_checkin_info_.secret,
917 registration_info->app_id); 914 registration_info->app_id);
918 915
919 RegistrationRequest* registration_request = 916 scoped_ptr<RegistrationRequest> registration_request(new RegistrationRequest(
920 new RegistrationRequest(gservices_settings_.GetRegistrationURL(), 917 gservices_settings_.GetRegistrationURL(), request_info,
921 request_info, 918 request_handler.Pass(), GetGCMBackoffPolicy(),
922 request_handler.Pass(), 919 base::Bind(&GCMClientImpl::OnRegisterCompleted,
923 GetGCMBackoffPolicy(), 920 weak_ptr_factory_.GetWeakPtr(), registration_info),
924 base::Bind(&GCMClientImpl::OnRegisterCompleted, 921 kMaxRegistrationRetries, url_request_context_getter_, &recorder_,
925 weak_ptr_factory_.GetWeakPtr(), 922 source_to_record));
926 registration_info),
927 kMaxRegistrationRetries,
928 url_request_context_getter_,
929 &recorder_,
930 source_to_record);
931 pending_registration_requests_[registration_info] = registration_request;
932 registration_request->Start(); 923 registration_request->Start();
924 pending_registration_requests_.insert(registration_info,
925 registration_request.Pass());
933 } 926 }
934 927
935 void GCMClientImpl::OnRegisterCompleted( 928 void GCMClientImpl::OnRegisterCompleted(
936 const linked_ptr<RegistrationInfo>& registration_info, 929 const linked_ptr<RegistrationInfo>& registration_info,
937 RegistrationRequest::Status status, 930 RegistrationRequest::Status status,
938 const std::string& registration_id) { 931 const std::string& registration_id) {
939 DCHECK(delegate_); 932 DCHECK(delegate_);
940 933
941 Result result; 934 Result result;
942 PendingRegistrationRequests::iterator iter = 935 PendingRegistrationRequests::const_iterator iter =
943 pending_registration_requests_.find(registration_info); 936 pending_registration_requests_.find(registration_info);
944 if (iter == pending_registration_requests_.end()) 937 if (iter == pending_registration_requests_.end())
945 result = UNKNOWN_ERROR; 938 result = UNKNOWN_ERROR;
946 else if (status == RegistrationRequest::INVALID_SENDER) 939 else if (status == RegistrationRequest::INVALID_SENDER)
947 result = INVALID_PARAMETER; 940 result = INVALID_PARAMETER;
948 else if (registration_id.empty()) 941 else if (registration_id.empty())
949 result = SERVER_ERROR; 942 result = SERVER_ERROR;
950 else 943 else
951 result = SUCCESS; 944 result = SUCCESS;
952 945
953 if (result == SUCCESS) { 946 if (result == SUCCESS) {
954 // Cache it. 947 // Cache it.
955 registrations_[registration_info] = registration_id; 948 registrations_[registration_info] = registration_id;
956 949
957 // Save it in the persistent store. 950 // Save it in the persistent store.
958 gcm_store_->AddRegistration( 951 gcm_store_->AddRegistration(
959 registration_info->GetSerializedKey(), 952 registration_info->GetSerializedKey(),
960 registration_info->GetSerializedValue(registration_id), 953 registration_info->GetSerializedValue(registration_id),
961 base::Bind(&GCMClientImpl::UpdateRegistrationCallback, 954 base::Bind(&GCMClientImpl::UpdateRegistrationCallback,
962 weak_ptr_factory_.GetWeakPtr())); 955 weak_ptr_factory_.GetWeakPtr()));
963 } 956 }
964 957
965 delegate_->OnRegisterFinished( 958 delegate_->OnRegisterFinished(
966 registration_info, 959 registration_info,
967 result == SUCCESS ? registration_id : std::string(), 960 result == SUCCESS ? registration_id : std::string(),
968 result); 961 result);
969 962
970 if (iter != pending_registration_requests_.end()) { 963 if (iter != pending_registration_requests_.end())
971 delete iter->second;
972 pending_registration_requests_.erase(iter); 964 pending_registration_requests_.erase(iter);
973 }
974 } 965 }
975 966
976 void GCMClientImpl::Unregister( 967 void GCMClientImpl::Unregister(
977 const linked_ptr<RegistrationInfo>& registration_info) { 968 const linked_ptr<RegistrationInfo>& registration_info) {
978 DCHECK_EQ(state_, READY); 969 DCHECK_EQ(state_, READY);
979 if (pending_unregistration_requests_.count(registration_info) == 1) 970 if (pending_unregistration_requests_.count(registration_info) == 1)
980 return; 971 return;
981 972
982 // Remove from the cache and persistent store. 973 // Remove from the cache and persistent store.
983 registrations_.erase(registration_info); 974 registrations_.erase(registration_info);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 instance_id_token_info->authorized_entity, 1026 instance_id_token_info->authorized_entity,
1036 instance_id_token_info->scope, 1027 instance_id_token_info->scope,
1037 ConstructGCMVersion(chrome_build_info_.version))); 1028 ConstructGCMVersion(chrome_build_info_.version)));
1038 } 1029 }
1039 1030
1040 UnregistrationRequest::RequestInfo request_info( 1031 UnregistrationRequest::RequestInfo request_info(
1041 device_checkin_info_.android_id, 1032 device_checkin_info_.android_id,
1042 device_checkin_info_.secret, 1033 device_checkin_info_.secret,
1043 registration_info->app_id); 1034 registration_info->app_id);
1044 1035
1045 UnregistrationRequest* unregistration_request = new UnregistrationRequest( 1036 scoped_ptr<UnregistrationRequest> unregistration_request(
1046 gservices_settings_.GetRegistrationURL(), 1037 new UnregistrationRequest(
1047 request_info, 1038 gservices_settings_.GetRegistrationURL(), request_info,
1048 request_handler.Pass(), 1039 request_handler.Pass(), GetGCMBackoffPolicy(),
1049 GetGCMBackoffPolicy(), 1040 base::Bind(&GCMClientImpl::OnUnregisterCompleted,
1050 base::Bind(&GCMClientImpl::OnUnregisterCompleted, 1041 weak_ptr_factory_.GetWeakPtr(), registration_info),
1051 weak_ptr_factory_.GetWeakPtr(), 1042 url_request_context_getter_, &recorder_));
1052 registration_info),
1053 url_request_context_getter_,
1054 &recorder_);
1055 pending_unregistration_requests_[registration_info] = unregistration_request;
1056 unregistration_request->Start(); 1043 unregistration_request->Start();
1044 pending_unregistration_requests_.insert(registration_info,
1045 unregistration_request.Pass());
1057 } 1046 }
1058 1047
1059 void GCMClientImpl::OnUnregisterCompleted( 1048 void GCMClientImpl::OnUnregisterCompleted(
1060 const linked_ptr<RegistrationInfo>& registration_info, 1049 const linked_ptr<RegistrationInfo>& registration_info,
1061 UnregistrationRequest::Status status) { 1050 UnregistrationRequest::Status status) {
1062 DVLOG(1) << "Unregister completed for app: " << registration_info->app_id 1051 DVLOG(1) << "Unregister completed for app: " << registration_info->app_id
1063 << " with " << (status ? "success." : "failure."); 1052 << " with " << (status ? "success." : "failure.");
1064 delegate_->OnUnregisterFinished( 1053 delegate_->OnUnregisterFinished(
1065 registration_info, 1054 registration_info,
1066 status == UnregistrationRequest::SUCCESS ? SUCCESS : SERVER_ERROR); 1055 status == UnregistrationRequest::SUCCESS ? SUCCESS : SERVER_ERROR);
1067 1056
1068 PendingUnregistrationRequests::iterator iter = 1057 pending_unregistration_requests_.erase(registration_info);
1069 pending_unregistration_requests_.find(registration_info);
1070 if (iter == pending_unregistration_requests_.end())
1071 return;
1072
1073 delete iter->second;
1074 pending_unregistration_requests_.erase(iter);
1075 } 1058 }
1076 1059
1077 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { 1060 void GCMClientImpl::OnGCMStoreDestroyed(bool success) {
1078 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; 1061 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!";
1079 UMA_HISTOGRAM_BOOLEAN("GCM.StoreDestroySucceeded", success); 1062 UMA_HISTOGRAM_BOOLEAN("GCM.StoreDestroySucceeded", success);
1080 } 1063 }
1081 1064
1082 void GCMClientImpl::Send(const std::string& app_id, 1065 void GCMClientImpl::Send(const std::string& app_id,
1083 const std::string& receiver_id, 1066 const std::string& receiver_id,
1084 const OutgoingMessage& message) { 1067 const OutgoingMessage& message) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 bool GCMClientImpl::HasStandaloneRegisteredApp() const { 1329 bool GCMClientImpl::HasStandaloneRegisteredApp() const {
1347 if (registrations_.empty()) 1330 if (registrations_.empty())
1348 return false; 1331 return false;
1349 // Note that account mapper is not counted as a standalone app since it is 1332 // Note that account mapper is not counted as a standalone app since it is
1350 // automatically started when other app uses GCM. 1333 // automatically started when other app uses GCM.
1351 return registrations_.size() > 1 || 1334 return registrations_.size() > 1 ||
1352 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); 1335 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId);
1353 } 1336 }
1354 1337
1355 } // namespace gcm 1338 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698