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

Side by Side Diff: components/gcm_driver/gcm_stats_recorder_impl.cc

Issue 2427633005: Improve GCM enum switch type safety (Closed)
Patch Set: Rebase Created 4 years, 2 months 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 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 "components/gcm_driver/gcm_stats_recorder_impl.h" 5 #include "components/gcm_driver/gcm_stats_recorder_impl.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED: 43 case gcm::MCSClient::QUEUE_SIZE_LIMIT_REACHED:
44 return "QUEUE_SIZE_LIMIT_REACHED"; 44 return "QUEUE_SIZE_LIMIT_REACHED";
45 case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED: 45 case gcm::MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
46 return "APP_QUEUE_SIZE_LIMIT_REACHED"; 46 return "APP_QUEUE_SIZE_LIMIT_REACHED";
47 case gcm::MCSClient::MESSAGE_TOO_LARGE: 47 case gcm::MCSClient::MESSAGE_TOO_LARGE:
48 return "MESSAGE_TOO_LARGE"; 48 return "MESSAGE_TOO_LARGE";
49 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL: 49 case gcm::MCSClient::NO_CONNECTION_ON_ZERO_TTL:
50 return "NO_CONNECTION_ON_ZERO_TTL"; 50 return "NO_CONNECTION_ON_ZERO_TTL";
51 case gcm::MCSClient::TTL_EXCEEDED: 51 case gcm::MCSClient::TTL_EXCEEDED:
52 return "TTL_EXCEEDED"; 52 return "TTL_EXCEEDED";
53 default: 53 case gcm::MCSClient::SEND_STATUS_COUNT:
54 NOTREACHED(); 54 NOTREACHED();
55 return "UNKNOWN"; 55 break;
56 } 56 }
57 return "UNKNOWN";
57 } 58 }
58 59
59 // Helper for getting string representation of the 60 // Helper for getting string representation of the
60 // ConnectionFactory::ConnectionResetReason enum. 61 // ConnectionFactory::ConnectionResetReason enum.
61 std::string GetConnectionResetReasonString( 62 std::string GetConnectionResetReasonString(
62 gcm::ConnectionFactory::ConnectionResetReason reason) { 63 gcm::ConnectionFactory::ConnectionResetReason reason) {
63 switch (reason) { 64 switch (reason) {
64 case gcm::ConnectionFactory::LOGIN_FAILURE: 65 case gcm::ConnectionFactory::LOGIN_FAILURE:
65 return "LOGIN_FAILURE"; 66 return "LOGIN_FAILURE";
66 case gcm::ConnectionFactory::CLOSE_COMMAND: 67 case gcm::ConnectionFactory::CLOSE_COMMAND:
67 return "CLOSE_COMMAND"; 68 return "CLOSE_COMMAND";
68 case gcm::ConnectionFactory::HEARTBEAT_FAILURE: 69 case gcm::ConnectionFactory::HEARTBEAT_FAILURE:
69 return "HEARTBEAT_FAILURE"; 70 return "HEARTBEAT_FAILURE";
70 case gcm::ConnectionFactory::SOCKET_FAILURE: 71 case gcm::ConnectionFactory::SOCKET_FAILURE:
71 return "SOCKET_FAILURE"; 72 return "SOCKET_FAILURE";
72 case gcm::ConnectionFactory::NETWORK_CHANGE: 73 case gcm::ConnectionFactory::NETWORK_CHANGE:
73 return "NETWORK_CHANGE"; 74 return "NETWORK_CHANGE";
74 default: 75 case gcm::ConnectionFactory::NEW_HEARTBEAT_INTERVAL:
76 return "NEW_HEARTBEAT_INTERVAL";
77 case gcm::ConnectionFactory::CONNECTION_RESET_COUNT:
75 NOTREACHED(); 78 NOTREACHED();
76 return "UNKNOWN_REASON"; 79 break;
77 } 80 }
81 return "UNKNOWN_REASON";
78 } 82 }
79 83
80 // Helper for getting string representation of the RegistrationRequest::Status 84 // Helper for getting string representation of the RegistrationRequest::Status
81 // enum. 85 // enum.
82 std::string GetRegistrationStatusString( 86 std::string GetRegistrationStatusString(
83 gcm::RegistrationRequest::Status status) { 87 gcm::RegistrationRequest::Status status) {
84 switch (status) { 88 switch (status) {
85 case gcm::RegistrationRequest::SUCCESS: 89 case gcm::RegistrationRequest::SUCCESS:
86 return "SUCCESS"; 90 return "SUCCESS";
87 case gcm::RegistrationRequest::INVALID_PARAMETERS: 91 case gcm::RegistrationRequest::INVALID_PARAMETERS:
88 return "INVALID_PARAMETERS"; 92 return "INVALID_PARAMETERS";
89 case gcm::RegistrationRequest::INVALID_SENDER: 93 case gcm::RegistrationRequest::INVALID_SENDER:
90 return "INVALID_SENDER"; 94 return "INVALID_SENDER";
91 case gcm::RegistrationRequest::AUTHENTICATION_FAILED: 95 case gcm::RegistrationRequest::AUTHENTICATION_FAILED:
92 return "AUTHENTICATION_FAILED"; 96 return "AUTHENTICATION_FAILED";
93 case gcm::RegistrationRequest::DEVICE_REGISTRATION_ERROR: 97 case gcm::RegistrationRequest::DEVICE_REGISTRATION_ERROR:
94 return "DEVICE_REGISTRATION_ERROR"; 98 return "DEVICE_REGISTRATION_ERROR";
95 case gcm::RegistrationRequest::UNKNOWN_ERROR: 99 case gcm::RegistrationRequest::UNKNOWN_ERROR:
96 return "UNKNOWN_ERROR"; 100 return "UNKNOWN_ERROR";
97 case gcm::RegistrationRequest::URL_FETCHING_FAILED: 101 case gcm::RegistrationRequest::URL_FETCHING_FAILED:
98 return "URL_FETCHING_FAILED"; 102 return "URL_FETCHING_FAILED";
99 case gcm::RegistrationRequest::HTTP_NOT_OK: 103 case gcm::RegistrationRequest::HTTP_NOT_OK:
100 return "HTTP_NOT_OK"; 104 return "HTTP_NOT_OK";
101 case gcm::RegistrationRequest::RESPONSE_PARSING_FAILED: 105 case gcm::RegistrationRequest::RESPONSE_PARSING_FAILED:
102 return "RESPONSE_PARSING_FAILED"; 106 return "RESPONSE_PARSING_FAILED";
103 case gcm::RegistrationRequest::REACHED_MAX_RETRIES: 107 case gcm::RegistrationRequest::REACHED_MAX_RETRIES:
104 return "REACHED_MAX_RETRIES"; 108 return "REACHED_MAX_RETRIES";
105 default: 109 case gcm::RegistrationRequest::STATUS_COUNT:
106 NOTREACHED(); 110 NOTREACHED();
107 return "UNKNOWN_STATUS"; 111 break;
108 } 112 }
113 return "UNKNOWN_STATUS";
109 } 114 }
110 115
111 // Helper for getting string representation of the RegistrationRequest::Status 116 // Helper for getting string representation of the RegistrationRequest::Status
112 // enum. 117 // enum.
113 std::string GetUnregistrationStatusString( 118 std::string GetUnregistrationStatusString(
114 gcm::UnregistrationRequest::Status status) { 119 gcm::UnregistrationRequest::Status status) {
115 switch (status) { 120 switch (status) {
116 case gcm::UnregistrationRequest::SUCCESS: 121 case gcm::UnregistrationRequest::SUCCESS:
117 return "SUCCESS"; 122 return "SUCCESS";
118 case gcm::UnregistrationRequest::URL_FETCHING_FAILED: 123 case gcm::UnregistrationRequest::URL_FETCHING_FAILED:
119 return "URL_FETCHING_FAILED"; 124 return "URL_FETCHING_FAILED";
120 case gcm::UnregistrationRequest::NO_RESPONSE_BODY: 125 case gcm::UnregistrationRequest::NO_RESPONSE_BODY:
121 return "NO_RESPONSE_BODY"; 126 return "NO_RESPONSE_BODY";
122 case gcm::UnregistrationRequest::RESPONSE_PARSING_FAILED: 127 case gcm::UnregistrationRequest::RESPONSE_PARSING_FAILED:
123 return "RESPONSE_PARSING_FAILED"; 128 return "RESPONSE_PARSING_FAILED";
124 case gcm::UnregistrationRequest::INCORRECT_APP_ID: 129 case gcm::UnregistrationRequest::INCORRECT_APP_ID:
125 return "INCORRECT_APP_ID"; 130 return "INCORRECT_APP_ID";
126 case gcm::UnregistrationRequest::INVALID_PARAMETERS: 131 case gcm::UnregistrationRequest::INVALID_PARAMETERS:
127 return "INVALID_PARAMETERS"; 132 return "INVALID_PARAMETERS";
128 case gcm::UnregistrationRequest::SERVICE_UNAVAILABLE: 133 case gcm::UnregistrationRequest::SERVICE_UNAVAILABLE:
129 return "SERVICE_UNAVAILABLE"; 134 return "SERVICE_UNAVAILABLE";
130 case gcm::UnregistrationRequest::INTERNAL_SERVER_ERROR: 135 case gcm::UnregistrationRequest::INTERNAL_SERVER_ERROR:
131 return "INTERNAL_SERVER_ERROR"; 136 return "INTERNAL_SERVER_ERROR";
132 case gcm::UnregistrationRequest::HTTP_NOT_OK: 137 case gcm::UnregistrationRequest::HTTP_NOT_OK:
133 return "HTTP_NOT_OK"; 138 return "HTTP_NOT_OK";
134 case gcm::UnregistrationRequest::UNKNOWN_ERROR: 139 case gcm::UnregistrationRequest::UNKNOWN_ERROR:
135 return "UNKNOWN_ERROR"; 140 return "UNKNOWN_ERROR";
136 case gcm::UnregistrationRequest::REACHED_MAX_RETRIES: 141 case gcm::UnregistrationRequest::REACHED_MAX_RETRIES:
137 return "REACHED_MAX_RETRIES"; 142 return "REACHED_MAX_RETRIES";
138 default: 143 case gcm::UnregistrationRequest::UNREGISTRATION_STATUS_COUNT:
139 NOTREACHED(); 144 NOTREACHED();
140 return "UNKNOWN_STATUS"; 145 break;
141 } 146 }
147 return "UNKNOWN_STATUS";
142 } 148 }
143 149
144 } // namespace 150 } // namespace
145 151
146 GCMStatsRecorderImpl::GCMStatsRecorderImpl() 152 GCMStatsRecorderImpl::GCMStatsRecorderImpl()
147 : is_recording_(false), 153 : is_recording_(false),
148 delegate_(NULL), 154 delegate_(NULL),
149 data_message_received_since_connected_(false), 155 data_message_received_since_connected_(false),
150 received_data_message_burst_size_(0) { 156 received_data_message_burst_size_(0) {
151 } 157 }
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 443
438 if (!is_recording_) 444 if (!is_recording_)
439 return; 445 return;
440 if (!to_registered_app) { 446 if (!to_registered_app) {
441 RecordReceiving(app_id, 447 RecordReceiving(app_id,
442 from, 448 from,
443 message_byte_size, 449 message_byte_size,
444 "Data msg received", 450 "Data msg received",
445 "No such registered app found"); 451 "No such registered app found");
446 } else { 452 } else {
447 switch(message_type) { 453 switch (message_type) {
448 case GCMStatsRecorderImpl::DATA_MESSAGE: 454 case GCMStatsRecorderImpl::DATA_MESSAGE:
449 RecordReceiving(app_id, from, message_byte_size, "Data msg received", 455 RecordReceiving(app_id, from, message_byte_size, "Data msg received",
450 std::string()); 456 std::string());
451 break; 457 break;
452 case GCMStatsRecorderImpl::DELETED_MESSAGES: 458 case GCMStatsRecorderImpl::DELETED_MESSAGES:
453 RecordReceiving(app_id, from, message_byte_size, "Data msg received", 459 RecordReceiving(app_id, from, message_byte_size, "Data msg received",
454 "Message has been deleted on server"); 460 "Message has been deleted on server");
455 break; 461 break;
456 default:
457 NOTREACHED();
458 } 462 }
459 } 463 }
460 } 464 }
461 465
462 void GCMStatsRecorderImpl::CollectActivities( 466 void GCMStatsRecorderImpl::CollectActivities(
463 RecordedActivities* recorded_activities) const { 467 RecordedActivities* recorded_activities) const {
464 recorded_activities->checkin_activities.insert( 468 recorded_activities->checkin_activities.insert(
465 recorded_activities->checkin_activities.begin(), 469 recorded_activities->checkin_activities.begin(),
466 checkin_activities_.begin(), 470 checkin_activities_.begin(),
467 checkin_activities_.end()); 471 checkin_activities_.end());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 const std::string& receiver_id, 543 const std::string& receiver_id,
540 const std::string& message_id) { 544 const std::string& message_id) {
541 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1); 545 UMA_HISTOGRAM_COUNTS("GCM.IncomingSendErrors", 1);
542 if (!is_recording_) 546 if (!is_recording_)
543 return; 547 return;
544 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg", 548 RecordSending(app_id, receiver_id, message_id, "Received 'send error' msg",
545 std::string()); 549 std::string());
546 } 550 }
547 551
548 } // namespace gcm 552 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_desktop_utils.cc ('k') | components/gcm_driver/instance_id/instance_id_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698