Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: google_apis/gcm/engine/instance_id_delete_token_request_handler.cc

Issue 2434243002: GCM Engine: Split up reg/unreg UNKNOWN_ERROR to improve metrics (Closed)
Patch Set: mid-cycle -> mid-beta Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kScopeKey[] = "scope"; 22 const char kScopeKey[] = "scope";
23 const char kExtraScopeKey[] = "X-scope"; 23 const char kExtraScopeKey[] = "X-scope";
24 24
25 // Response constants. 25 // Response constants.
26 const char kTokenPrefix[] = "token="; 26 const char kTokenPrefix[] = "token=";
27 const char kErrorPrefix[] = "Error=";
28 const char kInvalidParameters[] = "INVALID_PARAMETERS";
29 27
30 } // namespace 28 } // namespace
31 29
32 InstanceIDDeleteTokenRequestHandler::InstanceIDDeleteTokenRequestHandler( 30 InstanceIDDeleteTokenRequestHandler::InstanceIDDeleteTokenRequestHandler(
33 const std::string& instance_id, 31 const std::string& instance_id,
34 const std::string& authorized_entity, 32 const std::string& authorized_entity,
35 const std::string& scope, 33 const std::string& scope,
36 int gcm_version) 34 int gcm_version)
37 : instance_id_(instance_id), 35 : instance_id_(instance_id),
38 authorized_entity_(authorized_entity), 36 authorized_entity_(authorized_entity),
39 scope_(scope), 37 scope_(scope),
40 gcm_version_(gcm_version) { 38 gcm_version_(gcm_version) {
41 DCHECK(!instance_id.empty()); 39 DCHECK(!instance_id.empty());
42 DCHECK(!authorized_entity.empty()); 40 DCHECK(!authorized_entity.empty());
43 DCHECK(!scope.empty()); 41 DCHECK(!scope.empty());
44 } 42 }
45 43
46 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {} 44 InstanceIDDeleteTokenRequestHandler::~InstanceIDDeleteTokenRequestHandler() {}
47 45
48 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){ 46 void InstanceIDDeleteTokenRequestHandler::BuildRequestBody(std::string* body){
49 BuildFormEncoding(kInstanceIDKey, instance_id_, body); 47 BuildFormEncoding(kInstanceIDKey, instance_id_, body);
50 BuildFormEncoding(kSenderKey, authorized_entity_, body); 48 BuildFormEncoding(kSenderKey, authorized_entity_, body);
51 BuildFormEncoding(kScopeKey, scope_, body); 49 BuildFormEncoding(kScopeKey, scope_, body);
52 BuildFormEncoding(kExtraScopeKey, scope_, body); 50 BuildFormEncoding(kExtraScopeKey, scope_, body);
53 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); 51 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body);
54 } 52 }
55 53
56 UnregistrationRequest::Status 54 UnregistrationRequest::Status
57 InstanceIDDeleteTokenRequestHandler::ParseResponse( 55 InstanceIDDeleteTokenRequestHandler::ParseResponse(
58 const net::URLFetcher* source) { 56 const std::string& response) {
59 std::string response;
60 if (!source->GetResponseAsString(&response)) {
61 DVLOG(1) << "Failed to get response body.";
62 return UnregistrationRequest::NO_RESPONSE_BODY;
63 }
64
65 if (response.find(kErrorPrefix) != std::string::npos) {
66 std::string error = response.substr(
67 response.find(kErrorPrefix) + arraysize(kErrorPrefix) - 1);
68 return error == kInvalidParameters ?
69 UnregistrationRequest::INVALID_PARAMETERS :
70 UnregistrationRequest::UNKNOWN_ERROR;
71 }
72
73 if (response.find(kTokenPrefix) == std::string::npos) 57 if (response.find(kTokenPrefix) == std::string::npos)
74 return UnregistrationRequest::RESPONSE_PARSING_FAILED; 58 return UnregistrationRequest::RESPONSE_PARSING_FAILED;
75 59
76 return UnregistrationRequest::SUCCESS; 60 return UnregistrationRequest::SUCCESS;
77 } 61 }
78 62
79 void InstanceIDDeleteTokenRequestHandler::ReportUMAs( 63 void InstanceIDDeleteTokenRequestHandler::ReportUMAs(
80 UnregistrationRequest::Status status, 64 UnregistrationRequest::Status status,
81 int retry_count, 65 int retry_count,
82 base::TimeDelta complete_time) { 66 base::TimeDelta complete_time) {
83 UMA_HISTOGRAM_ENUMERATION("InstanceID.DeleteToken.RequestStatus", 67 UMA_HISTOGRAM_ENUMERATION("InstanceID.DeleteToken.RequestStatus",
84 status, 68 status,
85 UnregistrationRequest::UNREGISTRATION_STATUS_COUNT); 69 UnregistrationRequest::UNREGISTRATION_STATUS_COUNT);
86 70
87 // Other UMAs are only reported when the request succeeds. 71 // Other UMAs are only reported when the request succeeds.
88 if (status != UnregistrationRequest::SUCCESS) 72 if (status != UnregistrationRequest::SUCCESS)
89 return; 73 return;
90 74
91 UMA_HISTOGRAM_COUNTS("InstanceID.DeleteToken.RetryCount", retry_count); 75 UMA_HISTOGRAM_COUNTS("InstanceID.DeleteToken.RetryCount", retry_count);
92 UMA_HISTOGRAM_TIMES("InstanceID.DeleteToken.CompleteTime", complete_time); 76 UMA_HISTOGRAM_TIMES("InstanceID.DeleteToken.CompleteTime", complete_time);
93 } 77 }
94 78
95 } // namespace gcm 79 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/instance_id_delete_token_request_handler.h ('k') | google_apis/gcm/engine/registration_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698