OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "google_apis/gcm/engine/instance_id_delete_token_request.h" |
| 6 |
| 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "google_apis/gcm/base/gcm_util.h" |
| 9 #include "net/url_request/url_fetcher.h" |
| 10 #include "net/url_request/url_request_context_getter.h" |
| 11 |
| 12 namespace gcm { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // Request constants. |
| 17 const char kGMSVersionKey[] = "gmsv"; |
| 18 const char kInstanceIDKey[] = "appid"; |
| 19 const char kSenderKey[] = "sender"; |
| 20 const char kScopeKey[] = "scope"; |
| 21 |
| 22 // Response constants. |
| 23 const char kTokenPrefix[] = "token="; |
| 24 |
| 25 } // namespace |
| 26 |
| 27 InstanceIDDeleteTokenRequest::ExtraRequestInfo::ExtraRequestInfo( |
| 28 const std::string& instance_id, |
| 29 const std::string& authorized_entity, |
| 30 const std::string& scope, |
| 31 int gcm_version) |
| 32 : instance_id(instance_id), |
| 33 authorized_entity(authorized_entity), |
| 34 scope(scope), |
| 35 gcm_version(gcm_version) { |
| 36 } |
| 37 |
| 38 InstanceIDDeleteTokenRequest::ExtraRequestInfo::~ExtraRequestInfo() {} |
| 39 |
| 40 InstanceIDDeleteTokenRequest::InstanceIDDeleteTokenRequest( |
| 41 const GURL& registration_url, |
| 42 const RequestInfo& request_info, |
| 43 const ExtraRequestInfo& extra_request_info, |
| 44 const net::BackoffEntry::Policy& backoff_policy, |
| 45 const UnregistrationCallback& callback, |
| 46 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 47 GCMStatsRecorder* recorder) |
| 48 : UnregistrationRequest(registration_url, |
| 49 request_info, |
| 50 backoff_policy, |
| 51 callback, |
| 52 request_context_getter, |
| 53 recorder), |
| 54 extra_request_info_(extra_request_info) { |
| 55 } |
| 56 |
| 57 InstanceIDDeleteTokenRequest::~InstanceIDDeleteTokenRequest() {} |
| 58 |
| 59 void InstanceIDDeleteTokenRequest::BuildRequestBody( |
| 60 std::string* body){ |
| 61 DCHECK(!extra_request_info_.instance_id.empty() && |
| 62 !extra_request_info_.authorized_entity.empty() && |
| 63 !extra_request_info_.scope.empty()); |
| 64 |
| 65 UnregistrationRequest::BuildRequestBody(body); |
| 66 |
| 67 BuildFormEncoding(kInstanceIDKey, extra_request_info_.instance_id, body); |
| 68 BuildFormEncoding(kSenderKey, |
| 69 extra_request_info_.authorized_entity, |
| 70 body); |
| 71 BuildFormEncoding(kScopeKey, extra_request_info_.scope, body); |
| 72 BuildFormEncoding(kGMSVersionKey, |
| 73 base::IntToString(extra_request_info_.gcm_version), |
| 74 body); |
| 75 } |
| 76 |
| 77 bool InstanceIDDeleteTokenRequest::ParseResponse( |
| 78 const net::URLFetcher* source, |
| 79 UnregistrationRequest::Status* status) { |
| 80 if (UnregistrationRequest::ParseResponse(source, status)) |
| 81 return true; |
| 82 |
| 83 std::string response; |
| 84 if (!source->GetResponseAsString(&response)) { |
| 85 DVLOG(1) << "Failed to get response body."; |
| 86 *status = UnregistrationRequest::NO_RESPONSE_BODY; |
| 87 return true; |
| 88 } |
| 89 |
| 90 DVLOG(1) << "Parsing unregistration response."; |
| 91 if (response.find(kTokenPrefix) != std::string::npos) { |
| 92 *status = UnregistrationRequest::SUCCESS; |
| 93 return true; |
| 94 } |
| 95 |
| 96 *status = UnregistrationRequest::RESPONSE_PARSING_FAILED; |
| 97 return true; |
| 98 } |
| 99 |
| 100 } // namespace gcm |
OLD | NEW |