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/gcm_unregistration_request.h" |
| 6 |
| 7 #include "google_apis/gcm/base/gcm_util.h" |
| 8 #include "net/url_request/url_fetcher.h" |
| 9 #include "net/url_request/url_request_context_getter.h" |
| 10 |
| 11 namespace gcm { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Request constants. |
| 16 const char kUnregistrationCallerKey[] = "gcm_unreg_caller"; |
| 17 // We are going to set the value to "false" in order to forcefully unregister |
| 18 // the application. |
| 19 const char kUnregistrationCallerValue[] = "false"; |
| 20 |
| 21 // Response constants. |
| 22 const char kDeletedPrefix[] = "deleted="; |
| 23 const char kErrorPrefix[] = "Error="; |
| 24 const char kInvalidParameters[] = "INVALID_PARAMETERS"; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 GCMUnregistrationRequest::GCMUnregistrationRequest( |
| 29 const GURL& registration_url, |
| 30 const RequestInfo& request_info, |
| 31 const net::BackoffEntry::Policy& backoff_policy, |
| 32 const UnregistrationCallback& callback, |
| 33 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 34 GCMStatsRecorder* recorder) |
| 35 : UnregistrationRequest(registration_url, |
| 36 request_info, |
| 37 backoff_policy, |
| 38 callback, |
| 39 request_context_getter, |
| 40 recorder) { |
| 41 } |
| 42 |
| 43 GCMUnregistrationRequest::~GCMUnregistrationRequest() {} |
| 44 |
| 45 void GCMUnregistrationRequest::BuildRequestBody(std::string* body){ |
| 46 UnregistrationRequest::BuildRequestBody(body); |
| 47 |
| 48 BuildFormEncoding(kUnregistrationCallerKey, kUnregistrationCallerValue, body); |
| 49 } |
| 50 |
| 51 bool GCMUnregistrationRequest::ParseResponse( |
| 52 const net::URLFetcher* source, |
| 53 UnregistrationRequest::Status* status) { |
| 54 if (UnregistrationRequest::ParseResponse(source, status)) |
| 55 return true; |
| 56 |
| 57 std::string response; |
| 58 if (!source->GetResponseAsString(&response)) { |
| 59 DVLOG(1) << "Failed to get response body."; |
| 60 *status = NO_RESPONSE_BODY; |
| 61 return true; |
| 62 } |
| 63 |
| 64 DVLOG(1) << "Parsing unregistration response."; |
| 65 if (response.find(kDeletedPrefix) != std::string::npos) { |
| 66 std::string deleted_app_id = response.substr( |
| 67 response.find(kDeletedPrefix) + arraysize(kDeletedPrefix) - 1); |
| 68 *status = deleted_app_id == app_id() ? SUCCESS : INCORRECT_APP_ID; |
| 69 return true; |
| 70 } |
| 71 |
| 72 if (response.find(kErrorPrefix) != std::string::npos) { |
| 73 std::string error = response.substr( |
| 74 response.find(kErrorPrefix) + arraysize(kErrorPrefix) - 1); |
| 75 *status = error == kInvalidParameters? INVALID_PARAMETERS : UNKNOWN_ERROR; |
| 76 return true; |
| 77 } |
| 78 |
| 79 DVLOG(1) << "Not able to parse a meaningful output from response body." |
| 80 << response; |
| 81 *status = RESPONSE_PARSING_FAILED; |
| 82 return true; |
| 83 } |
| 84 |
| 85 } // namespace gcm |
OLD | NEW |