| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_get_token_request_handler.h" | 5 #include "google_apis/gcm/engine/instance_id_get_token_request_handler.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "google_apis/gcm/base/gcm_util.h" | 9 #include "google_apis/gcm/base/gcm_util.h" |
| 10 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
| 11 | 11 |
| 12 namespace gcm { | 12 namespace gcm { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Request constants. | 16 // Request constants. |
| 17 const char kAuthorizedEntityKey[] = "sender"; | 17 const char kAuthorizedEntityKey[] = "sender"; |
| 18 const char kSubtypeKey[] = "X-subtype"; | |
| 19 const char kGMSVersionKey[] = "gmsv"; | 18 const char kGMSVersionKey[] = "gmsv"; |
| 20 const char kInstanceIDKey[] = "appid"; | 19 const char kInstanceIDKey[] = "appid"; |
| 21 const char kScopeKey[] = "scope"; | 20 const char kScopeKey[] = "scope"; |
| 22 const char kExtraScopeKey[] = "X-scope"; | 21 const char kExtraScopeKey[] = "X-scope"; |
| 23 // Prefix that needs to be added for each option key. | 22 // Prefix that needs to be added for each option key. |
| 24 const char kOptionKeyPrefix[] = "X-"; | 23 const char kOptionKeyPrefix[] = "X-"; |
| 25 | 24 |
| 26 } // namespace | 25 } // namespace |
| 27 | 26 |
| 28 InstanceIDGetTokenRequestHandler::InstanceIDGetTokenRequestHandler( | 27 InstanceIDGetTokenRequestHandler::InstanceIDGetTokenRequestHandler( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 44 InstanceIDGetTokenRequestHandler::~InstanceIDGetTokenRequestHandler() {} | 43 InstanceIDGetTokenRequestHandler::~InstanceIDGetTokenRequestHandler() {} |
| 45 | 44 |
| 46 void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body){ | 45 void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body){ |
| 47 BuildFormEncoding(kScopeKey, scope_, body); | 46 BuildFormEncoding(kScopeKey, scope_, body); |
| 48 BuildFormEncoding(kExtraScopeKey, scope_, body); | 47 BuildFormEncoding(kExtraScopeKey, scope_, body); |
| 49 for (auto iter = options_.begin(); iter != options_.end(); ++iter) | 48 for (auto iter = options_.begin(); iter != options_.end(); ++iter) |
| 50 BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body); | 49 BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body); |
| 51 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); | 50 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); |
| 52 BuildFormEncoding(kInstanceIDKey, instance_id_, body); | 51 BuildFormEncoding(kInstanceIDKey, instance_id_, body); |
| 53 BuildFormEncoding(kAuthorizedEntityKey, authorized_entity_, body); | 52 BuildFormEncoding(kAuthorizedEntityKey, authorized_entity_, body); |
| 54 // TODO(jianli): To work around server bug. To be removed when the server fix | |
| 55 // is deployed. | |
| 56 BuildFormEncoding(kSubtypeKey, authorized_entity_, body); | |
| 57 } | 53 } |
| 58 | 54 |
| 59 void InstanceIDGetTokenRequestHandler::ReportUMAs( | 55 void InstanceIDGetTokenRequestHandler::ReportUMAs( |
| 60 RegistrationRequest::Status status, | 56 RegistrationRequest::Status status, |
| 61 int retry_count, | 57 int retry_count, |
| 62 base::TimeDelta complete_time) { | 58 base::TimeDelta complete_time) { |
| 63 UMA_HISTOGRAM_ENUMERATION("InstanceID.GetToken.RequestStatus", | 59 UMA_HISTOGRAM_ENUMERATION("InstanceID.GetToken.RequestStatus", |
| 64 status, | 60 status, |
| 65 RegistrationRequest::STATUS_COUNT); | 61 RegistrationRequest::STATUS_COUNT); |
| 66 | 62 |
| 67 // Other UMAs are only reported when the request succeeds. | 63 // Other UMAs are only reported when the request succeeds. |
| 68 if (status != RegistrationRequest::SUCCESS) | 64 if (status != RegistrationRequest::SUCCESS) |
| 69 return; | 65 return; |
| 70 | 66 |
| 71 UMA_HISTOGRAM_COUNTS("InstanceID.GetToken.RetryCount", retry_count); | 67 UMA_HISTOGRAM_COUNTS("InstanceID.GetToken.RetryCount", retry_count); |
| 72 UMA_HISTOGRAM_TIMES("InstanceID.GetToken.CompleteTime", complete_time); | 68 UMA_HISTOGRAM_TIMES("InstanceID.GetToken.CompleteTime", complete_time); |
| 73 } | 69 } |
| 74 | 70 |
| 75 } // namespace gcm | 71 } // namespace gcm |
| OLD | NEW |