Index: google_apis/gcm/engine/instance_id_delete_token_request.cc |
diff --git a/google_apis/gcm/engine/instance_id_delete_token_request.cc b/google_apis/gcm/engine/instance_id_delete_token_request.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..deb0a4c0f88e42645d79a23dd0d50d948814cef3 |
--- /dev/null |
+++ b/google_apis/gcm/engine/instance_id_delete_token_request.cc |
@@ -0,0 +1,100 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "google_apis/gcm/engine/instance_id_delete_token_request.h" |
+ |
+#include "base/strings/string_number_conversions.h" |
+#include "google_apis/gcm/base/gcm_util.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_request_context_getter.h" |
+ |
+namespace gcm { |
+ |
+namespace { |
+ |
+// Request constants. |
+const char kGMSVersionKey[] = "gmsv"; |
+const char kInstanceIDKey[] = "appid"; |
+const char kSenderKey[] = "sender"; |
+const char kScopeKey[] = "scope"; |
+ |
+// Response constants. |
+const char kTokenPrefix[] = "token="; |
+ |
+} // namespace |
+ |
+InstanceIDDeleteTokenRequest::ExtraRequestInfo::ExtraRequestInfo( |
+ const std::string& instance_id, |
+ const std::string& authorized_entity, |
+ const std::string& scope, |
+ int gcm_version) |
+ : instance_id(instance_id), |
+ authorized_entity(authorized_entity), |
+ scope(scope), |
+ gcm_version(gcm_version) { |
+} |
+ |
+InstanceIDDeleteTokenRequest::ExtraRequestInfo::~ExtraRequestInfo() {} |
+ |
+InstanceIDDeleteTokenRequest::InstanceIDDeleteTokenRequest( |
+ const GURL& registration_url, |
+ const RequestInfo& request_info, |
+ const ExtraRequestInfo& extra_request_info, |
+ const net::BackoffEntry::Policy& backoff_policy, |
+ const UnregistrationCallback& callback, |
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
+ GCMStatsRecorder* recorder) |
+ : UnregistrationRequest(registration_url, |
+ request_info, |
+ backoff_policy, |
+ callback, |
+ request_context_getter, |
+ recorder), |
+ extra_request_info_(extra_request_info) { |
+} |
+ |
+InstanceIDDeleteTokenRequest::~InstanceIDDeleteTokenRequest() {} |
+ |
+void InstanceIDDeleteTokenRequest::BuildRequestBody( |
+ std::string* body){ |
+ DCHECK(!extra_request_info_.instance_id.empty() && |
+ !extra_request_info_.authorized_entity.empty() && |
+ !extra_request_info_.scope.empty()); |
+ |
+ UnregistrationRequest::BuildRequestBody(body); |
+ |
+ BuildFormEncoding(kInstanceIDKey, extra_request_info_.instance_id, body); |
+ BuildFormEncoding(kSenderKey, |
+ extra_request_info_.authorized_entity, |
+ body); |
+ BuildFormEncoding(kScopeKey, extra_request_info_.scope, body); |
+ BuildFormEncoding(kGMSVersionKey, |
+ base::IntToString(extra_request_info_.gcm_version), |
+ body); |
+} |
+ |
+bool InstanceIDDeleteTokenRequest::ParseResponse( |
+ const net::URLFetcher* source, |
+ UnregistrationRequest::Status* status) { |
+ if (UnregistrationRequest::ParseResponse(source, status)) |
+ return true; |
+ |
+ std::string response; |
+ if (!source->GetResponseAsString(&response)) { |
+ DVLOG(1) << "Failed to get response body."; |
+ *status = UnregistrationRequest::NO_RESPONSE_BODY; |
+ return true; |
+ } |
+ |
+ DVLOG(1) << "Parsing unregistration response."; |
+ if (response.find(kTokenPrefix) != std::string::npos) { |
+ *status = UnregistrationRequest::SUCCESS; |
+ return true; |
+ } |
+ |
+ *status = UnregistrationRequest::RESPONSE_PARSING_FAILED; |
+ return true; |
+} |
+ |
+} // namespace gcm |