| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gcm/engine/instance_id_delete_token_request_handler.h" | 5 #include "google_apis/gcm/engine/instance_id_delete_token_request_handler.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "google_apis/gcm/base/gcm_util.h" | 10 #include "google_apis/gcm/base/gcm_util.h" |
| 11 #include "net/url_request/url_fetcher.h" | 11 #include "net/url_request/url_fetcher.h" |
| 12 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
| 13 | 13 |
| 14 namespace gcm { | 14 namespace gcm { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Request constants. | 18 // Request constants. |
| 19 const char kGMSVersionKey[] = "gmsv"; | 19 const char kGMSVersionKey[] = "gmsv"; |
| 20 const char kInstanceIDKey[] = "appid"; | 20 const char kInstanceIDKey[] = "appid"; |
| 21 const char kSenderKey[] = "sender"; | 21 const char kSenderKey[] = "sender"; |
| 22 const char kSubtypeKey[] = "X-subtype"; | |
| 23 const char kScopeKey[] = "scope"; | 22 const char kScopeKey[] = "scope"; |
| 24 const char kExtraScopeKey[] = "X-scope"; | 23 const char kExtraScopeKey[] = "X-scope"; |
| 25 | 24 |
| 26 // Response constants. | 25 // Response constants. |
| 27 const char kTokenPrefix[] = "token="; | 26 const char kTokenPrefix[] = "token="; |
| 28 const char kErrorPrefix[] = "Error="; | 27 const char kErrorPrefix[] = "Error="; |
| 29 const char kInvalidParameters[] = "INVALID_PARAMETERS"; | 28 const char kInvalidParameters[] = "INVALID_PARAMETERS"; |
| 30 | 29 |
| 31 } // namespace | 30 } // namespace |
| 32 | 31 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 45 } | 44 } |
| 46 | 45 |
| 47 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {} | 46 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {} |
| 48 | 47 |
| 49 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){ | 48 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){ |
| 50 BuildFormEncoding(kInstanceIDKey, instance_id_, body); | 49 BuildFormEncoding(kInstanceIDKey, instance_id_, body); |
| 51 BuildFormEncoding(kSenderKey, authorized_entity_, body); | 50 BuildFormEncoding(kSenderKey, authorized_entity_, body); |
| 52 BuildFormEncoding(kScopeKey, scope_, body); | 51 BuildFormEncoding(kScopeKey, scope_, body); |
| 53 BuildFormEncoding(kExtraScopeKey, scope_, body); | 52 BuildFormEncoding(kExtraScopeKey, scope_, body); |
| 54 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); | 53 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); |
| 55 // TODO(jianli): To work around server bug. To be removed when the server fix | |
| 56 // is deployed. | |
| 57 BuildFormEncoding(kSubtypeKey, authorized_entity_, body); | |
| 58 } | 54 } |
| 59 | 55 |
| 60 UnregistrationRequest::Status | 56 UnregistrationRequest::Status |
| 61 InstanceIDDeleteTokenRequestHandler::ParseResponse( | 57 InstanceIDDeleteTokenRequestHandler::ParseResponse( |
| 62 const net::URLFetcher* source) { | 58 const net::URLFetcher* source) { |
| 63 std::string response; | 59 std::string response; |
| 64 if (!source->GetResponseAsString(&response)) { | 60 if (!source->GetResponseAsString(&response)) { |
| 65 DVLOG(1) << "Failed to get response body."; | 61 DVLOG(1) << "Failed to get response body."; |
| 66 return UnregistrationRequest::NO_RESPONSE_BODY; | 62 return UnregistrationRequest::NO_RESPONSE_BODY; |
| 67 } | 63 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 90 | 86 |
| 91 // Other UMAs are only reported when the request succeeds. | 87 // Other UMAs are only reported when the request succeeds. |
| 92 if (status != UnregistrationRequest::SUCCESS) | 88 if (status != UnregistrationRequest::SUCCESS) |
| 93 return; | 89 return; |
| 94 | 90 |
| 95 UMA_HISTOGRAM_COUNTS("InstanceID.DeleteToken.RetryCount", retry_count); | 91 UMA_HISTOGRAM_COUNTS("InstanceID.DeleteToken.RetryCount", retry_count); |
| 96 UMA_HISTOGRAM_TIMES("InstanceID.DeleteToken.CompleteTime", complete_time); | 92 UMA_HISTOGRAM_TIMES("InstanceID.DeleteToken.CompleteTime", complete_time); |
| 97 } | 93 } |
| 98 | 94 |
| 99 } // namespace gcm | 95 } // namespace gcm |
| OLD | NEW |