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

Unified Diff: google_apis/gcm/engine/unregistration_request.cc

Issue 2427633005: Improve GCM enum switch type safety (Closed)
Patch Set: Rebase Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/registration_request.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/engine/unregistration_request.cc
diff --git a/google_apis/gcm/engine/unregistration_request.cc b/google_apis/gcm/engine/unregistration_request.cc
index c0b444e709b74bd6198f2dcca9d362f489bd47d3..15c8d883fa39dc806c2475555f849dd26c8b89fa 100644
--- a/google_apis/gcm/engine/unregistration_request.cc
+++ b/google_apis/gcm/engine/unregistration_request.cc
@@ -36,6 +36,29 @@ const char kDeleteValue[] = "true";
const char kDeviceIdKey[] = "device";
const char kLoginHeader[] = "AidLogin";
+// Determines whether to retry based on the status of the last request.
+bool ShouldRetryWithStatus(UnregistrationRequest::Status status) {
+ switch (status) {
+ case UnregistrationRequest::URL_FETCHING_FAILED:
+ case UnregistrationRequest::NO_RESPONSE_BODY:
+ case UnregistrationRequest::RESPONSE_PARSING_FAILED:
+ case UnregistrationRequest::INCORRECT_APP_ID:
+ case UnregistrationRequest::SERVICE_UNAVAILABLE:
+ case UnregistrationRequest::INTERNAL_SERVER_ERROR:
+ case UnregistrationRequest::HTTP_NOT_OK:
+ return true;
+ case UnregistrationRequest::SUCCESS:
+ case UnregistrationRequest::INVALID_PARAMETERS:
+ case UnregistrationRequest::UNKNOWN_ERROR:
+ case UnregistrationRequest::REACHED_MAX_RETRIES:
+ return false;
+ case UnregistrationRequest::UNREGISTRATION_STATUS_COUNT:
+ NOTREACHED();
+ break;
+ }
+ return false;
+}
+
} // namespace
UnregistrationRequest::RequestInfo::RequestInfo(uint64_t android_id,
@@ -177,7 +200,7 @@ void UnregistrationRequest::RetryWithBackoff() {
void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) {
UnregistrationRequest::Status status = ParseResponse(source);
- DVLOG(1) << "UnregistrationRequestStauts: " << status;
+ DVLOG(1) << "UnregistrationRequestStatus: " << status;
DCHECK(custom_request_handler_.get());
custom_request_handler_->ReportUMAs(
@@ -188,13 +211,7 @@ void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) {
recorder_->RecordUnregistrationResponse(request_info_.app_id(),
source_to_record_, status);
- if (status == URL_FETCHING_FAILED ||
- status == HTTP_NOT_OK ||
- status == NO_RESPONSE_BODY ||
- status == SERVICE_UNAVAILABLE ||
- status == INTERNAL_SERVER_ERROR ||
- status == INCORRECT_APP_ID ||
- status == RESPONSE_PARSING_FAILED) {
+ if (ShouldRetryWithStatus(status)) {
if (retries_left_ > 0) {
RetryWithBackoff();
return;
@@ -210,9 +227,6 @@ void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) {
custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta());
}
- // status == SUCCESS || INVALID_PARAMETERS || UNKNOWN_ERROR ||
- // REACHED_MAX_RETRIES
-
callback_.Run(status);
}
« no previous file with comments | « google_apis/gcm/engine/registration_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698