Add a link to crbug.com/512301 to TODO in media_permission.cc regarding pepper media...
[chromium-blink-merge.git] / google_apis / gcm / engine / instance_id_get_token_request_handler.cc
blob187db61df2c7fff0b5333cb997068603483eee56
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
3 // found in the LICENSE file.
5 #include "google_apis/gcm/engine/instance_id_get_token_request_handler.h"
7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "google_apis/gcm/base/gcm_util.h"
10 #include "net/url_request/url_request_context_getter.h"
12 namespace gcm {
14 namespace {
16 // Request constants.
17 const char kAuthorizedEntityKey[] = "sender";
18 const char kSubtypeKey[] = "X-subtype";
19 const char kGMSVersionKey[] = "gmsv";
20 const char kInstanceIDKey[] = "appid";
21 const char kScopeKey[] = "scope";
22 const char kExtraScopeKey[] = "X-scope";
23 // Prefix that needs to be added for each option key.
24 const char kOptionKeyPrefix[] = "X-";
26 } // namespace
28 InstanceIDGetTokenRequestHandler::InstanceIDGetTokenRequestHandler(
29 const std::string& instance_id,
30 const std::string& authorized_entity,
31 const std::string& scope,
32 int gcm_version,
33 const std::map<std::string, std::string>& options)
34 : instance_id_(instance_id),
35 authorized_entity_(authorized_entity),
36 scope_(scope),
37 gcm_version_(gcm_version),
38 options_(options) {
39 DCHECK(!instance_id.empty());
40 DCHECK(!authorized_entity.empty());
41 DCHECK(!scope.empty());
44 InstanceIDGetTokenRequestHandler::~InstanceIDGetTokenRequestHandler() {}
46 void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body){
47 BuildFormEncoding(kScopeKey, scope_, body);
48 BuildFormEncoding(kExtraScopeKey, scope_, body);
49 for (auto iter = options_.begin(); iter != options_.end(); ++iter)
50 BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body);
51 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body);
52 BuildFormEncoding(kInstanceIDKey, instance_id_, body);
53 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);
59 void InstanceIDGetTokenRequestHandler::ReportUMAs(
60 RegistrationRequest::Status status,
61 int retry_count,
62 base::TimeDelta complete_time) {
63 UMA_HISTOGRAM_ENUMERATION("InstanceID.GetToken.RequestStatus",
64 status,
65 RegistrationRequest::STATUS_COUNT);
67 // Other UMAs are only reported when the request succeeds.
68 if (status != RegistrationRequest::SUCCESS)
69 return;
71 UMA_HISTOGRAM_COUNTS("InstanceID.GetToken.RetryCount", retry_count);
72 UMA_HISTOGRAM_TIMES("InstanceID.GetToken.CompleteTime", complete_time);
75 } // namespace gcm