| OLD | NEW |
| 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 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 | 954 |
| 955 void GCMClientImpl::OnRegisterCompleted( | 955 void GCMClientImpl::OnRegisterCompleted( |
| 956 const linked_ptr<RegistrationInfo>& registration_info, | 956 const linked_ptr<RegistrationInfo>& registration_info, |
| 957 RegistrationRequest::Status status, | 957 RegistrationRequest::Status status, |
| 958 const std::string& registration_id) { | 958 const std::string& registration_id) { |
| 959 DCHECK(delegate_); | 959 DCHECK(delegate_); |
| 960 | 960 |
| 961 Result result; | 961 Result result; |
| 962 PendingRegistrationRequests::const_iterator iter = | 962 PendingRegistrationRequests::const_iterator iter = |
| 963 pending_registration_requests_.find(registration_info); | 963 pending_registration_requests_.find(registration_info); |
| 964 if (iter == pending_registration_requests_.end()) | 964 if (iter == pending_registration_requests_.end()) { |
| 965 result = UNKNOWN_ERROR; | 965 result = UNKNOWN_ERROR; |
| 966 else if (status == RegistrationRequest::INVALID_SENDER) | 966 } else if (status == RegistrationRequest::INVALID_SENDER) { |
| 967 result = INVALID_PARAMETER; | 967 result = INVALID_PARAMETER; |
| 968 else if (registration_id.empty()) | 968 } else if (registration_id.empty()) { |
| 969 // All other errors are currently treated as SERVER_ERROR (including |
| 970 // REACHED_MAX_RETRIES due to the device being offline!). |
| 969 result = SERVER_ERROR; | 971 result = SERVER_ERROR; |
| 970 else | 972 } else { |
| 971 result = SUCCESS; | 973 result = SUCCESS; |
| 974 } |
| 972 | 975 |
| 973 if (result == SUCCESS) { | 976 if (result == SUCCESS) { |
| 974 // Cache it. | 977 // Cache it. |
| 975 // Note that the existing cached record has to be removed first because | 978 // Note that the existing cached record has to be removed first because |
| 976 // otherwise the key value in registrations_ will not be updated. For GCM | 979 // otherwise the key value in registrations_ will not be updated. For GCM |
| 977 // registrations, the key consists of pair of app_id and sender_ids though | 980 // registrations, the key consists of pair of app_id and sender_ids though |
| 978 // only app_id is used in the comparison. | 981 // only app_id is used in the comparison. |
| 979 registrations_.erase(registration_info); | 982 registrations_.erase(registration_info); |
| 980 registrations_[registration_info] = registration_id; | 983 registrations_[registration_info] = registration_id; |
| 981 | 984 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 | 1110 |
| 1108 Result result; | 1111 Result result; |
| 1109 switch (status) { | 1112 switch (status) { |
| 1110 case UnregistrationRequest::SUCCESS: | 1113 case UnregistrationRequest::SUCCESS: |
| 1111 result = SUCCESS; | 1114 result = SUCCESS; |
| 1112 break; | 1115 break; |
| 1113 case UnregistrationRequest::INVALID_PARAMETERS: | 1116 case UnregistrationRequest::INVALID_PARAMETERS: |
| 1114 result = INVALID_PARAMETER; | 1117 result = INVALID_PARAMETER; |
| 1115 break; | 1118 break; |
| 1116 default: | 1119 default: |
| 1117 // All other errors are treated as SERVER_ERROR. | 1120 // All other errors are currently treated as SERVER_ERROR (including |
| 1121 // REACHED_MAX_RETRIES due to the device being offline!). |
| 1118 result = SERVER_ERROR; | 1122 result = SERVER_ERROR; |
| 1119 break; | 1123 break; |
| 1120 } | 1124 } |
| 1121 delegate_->OnUnregisterFinished(registration_info, result); | 1125 delegate_->OnUnregisterFinished(registration_info, result); |
| 1122 | 1126 |
| 1123 pending_unregistration_requests_.erase(registration_info); | 1127 pending_unregistration_requests_.erase(registration_info); |
| 1124 } | 1128 } |
| 1125 | 1129 |
| 1126 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { | 1130 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { |
| 1127 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; | 1131 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1469 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
| 1466 if (registrations_.empty()) | 1470 if (registrations_.empty()) |
| 1467 return false; | 1471 return false; |
| 1468 // Note that account mapper is not counted as a standalone app since it is | 1472 // Note that account mapper is not counted as a standalone app since it is |
| 1469 // automatically started when other app uses GCM. | 1473 // automatically started when other app uses GCM. |
| 1470 return registrations_.size() > 1 || | 1474 return registrations_.size() > 1 || |
| 1471 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1475 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
| 1472 } | 1476 } |
| 1473 | 1477 |
| 1474 } // namespace gcm | 1478 } // namespace gcm |
| OLD | NEW |