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 cases | |
970 // where all retries fail because the device is offline, which might be | |
971 // expected to result in a NETWORK_ERROR). If this is later changed, update | |
972 // FakeGCMProfileService's offline simulation to match. | |
Peter Beverloo
2017/02/07 18:11:08
Here and later, can we shorten and generalize w/ t
johnme
2017/02/08 14:14:36
Done (no longer needs to reference FakeGCMProfileS
| |
969 result = SERVER_ERROR; | 973 result = SERVER_ERROR; |
970 else | 974 } else { |
971 result = SUCCESS; | 975 result = SUCCESS; |
976 } | |
972 | 977 |
973 if (result == SUCCESS) { | 978 if (result == SUCCESS) { |
974 // Cache it. | 979 // Cache it. |
975 // Note that the existing cached record has to be removed first because | 980 // 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 | 981 // 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 | 982 // registrations, the key consists of pair of app_id and sender_ids though |
978 // only app_id is used in the comparison. | 983 // only app_id is used in the comparison. |
979 registrations_.erase(registration_info); | 984 registrations_.erase(registration_info); |
980 registrations_[registration_info] = registration_id; | 985 registrations_[registration_info] = registration_id; |
981 | 986 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 | 1112 |
1108 Result result; | 1113 Result result; |
1109 switch (status) { | 1114 switch (status) { |
1110 case UnregistrationRequest::SUCCESS: | 1115 case UnregistrationRequest::SUCCESS: |
1111 result = SUCCESS; | 1116 result = SUCCESS; |
1112 break; | 1117 break; |
1113 case UnregistrationRequest::INVALID_PARAMETERS: | 1118 case UnregistrationRequest::INVALID_PARAMETERS: |
1114 result = INVALID_PARAMETER; | 1119 result = INVALID_PARAMETER; |
1115 break; | 1120 break; |
1116 default: | 1121 default: |
1117 // All other errors are treated as SERVER_ERROR. | 1122 // All other errors are currently treated as SERVER_ERROR (including cases |
1123 // where all retries fail because the device is offline, which might be | |
1124 // expected to result in a NETWORK_ERROR). If this is later changed, | |
1125 // update FakeGCMProfileService's offline simulation to match. | |
1118 result = SERVER_ERROR; | 1126 result = SERVER_ERROR; |
1119 break; | 1127 break; |
1120 } | 1128 } |
1121 delegate_->OnUnregisterFinished(registration_info, result); | 1129 delegate_->OnUnregisterFinished(registration_info, result); |
1122 | 1130 |
1123 pending_unregistration_requests_.erase(registration_info); | 1131 pending_unregistration_requests_.erase(registration_info); |
1124 } | 1132 } |
1125 | 1133 |
1126 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { | 1134 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { |
1127 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; | 1135 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 { | 1473 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
1466 if (registrations_.empty()) | 1474 if (registrations_.empty()) |
1467 return false; | 1475 return false; |
1468 // Note that account mapper is not counted as a standalone app since it is | 1476 // Note that account mapper is not counted as a standalone app since it is |
1469 // automatically started when other app uses GCM. | 1477 // automatically started when other app uses GCM. |
1470 return registrations_.size() > 1 || | 1478 return registrations_.size() > 1 || |
1471 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1479 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
1472 } | 1480 } |
1473 | 1481 |
1474 } // namespace gcm | 1482 } // namespace gcm |
OLD | NEW |