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

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

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybots Created 5 years, 7 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
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

Powered by Google App Engine
This is Rietveld 408576698