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

Side by Side Diff: components/gcm_driver/gcm_client_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
« no previous file with comments | « no previous file | components/gcm_driver/gcm_desktop_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const char kSendErrorMessageIdKey[] = "google.message_id"; 89 const char kSendErrorMessageIdKey[] = "google.message_id";
90 const char kSubtypeKey[] = "subtype"; 90 const char kSubtypeKey[] = "subtype";
91 const char kSendMessageFromValue[] = "gcm@chrome.com"; 91 const char kSendMessageFromValue[] = "gcm@chrome.com";
92 const int64_t kDefaultUserSerialNumber = 0LL; 92 const int64_t kDefaultUserSerialNumber = 0LL;
93 const int kDestroyGCMStoreDelayMS = 5 * 60 * 1000; // 5 minutes. 93 const int kDestroyGCMStoreDelayMS = 5 * 60 * 1000; // 5 minutes.
94 94
95 GCMClient::Result ToGCMClientResult(MCSClient::MessageSendStatus status) { 95 GCMClient::Result ToGCMClientResult(MCSClient::MessageSendStatus status) {
96 switch (status) { 96 switch (status) {
97 case MCSClient::QUEUED: 97 case MCSClient::QUEUED:
98 return GCMClient::SUCCESS; 98 return GCMClient::SUCCESS;
99 case MCSClient::QUEUE_SIZE_LIMIT_REACHED:
100 return GCMClient::NETWORK_ERROR;
101 case MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
102 return GCMClient::NETWORK_ERROR;
103 case MCSClient::MESSAGE_TOO_LARGE: 99 case MCSClient::MESSAGE_TOO_LARGE:
104 return GCMClient::INVALID_PARAMETER; 100 return GCMClient::INVALID_PARAMETER;
101 case MCSClient::QUEUE_SIZE_LIMIT_REACHED:
102 case MCSClient::APP_QUEUE_SIZE_LIMIT_REACHED:
105 case MCSClient::NO_CONNECTION_ON_ZERO_TTL: 103 case MCSClient::NO_CONNECTION_ON_ZERO_TTL:
106 return GCMClient::NETWORK_ERROR;
107 case MCSClient::TTL_EXCEEDED: 104 case MCSClient::TTL_EXCEEDED:
108 return GCMClient::NETWORK_ERROR; 105 return GCMClient::NETWORK_ERROR;
109 case MCSClient::SENT: 106 case MCSClient::SENT:
110 default: 107 case MCSClient::SEND_STATUS_COUNT:
111 NOTREACHED(); 108 NOTREACHED();
112 break; 109 break;
113 } 110 }
114 return GCMClientImpl::UNKNOWN_ERROR; 111 return GCMClientImpl::UNKNOWN_ERROR;
115 } 112 }
116 113
117 void ToCheckinProtoVersion( 114 void ToCheckinProtoVersion(
118 const GCMClient::ChromeBuildInfo& chrome_build_info, 115 const GCMClient::ChromeBuildInfo& chrome_build_info,
119 checkin_proto::ChromeBuildProto* android_build_info) { 116 checkin_proto::ChromeBuildProto* android_build_info) {
120 checkin_proto::ChromeBuildProto_Platform platform; 117 checkin_proto::ChromeBuildProto_Platform platform =
118 checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
121 switch (chrome_build_info.platform) { 119 switch (chrome_build_info.platform) {
122 case GCMClient::PLATFORM_WIN: 120 case GCMClient::PLATFORM_WIN:
123 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN; 121 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN;
124 break; 122 break;
125 case GCMClient::PLATFORM_MAC: 123 case GCMClient::PLATFORM_MAC:
126 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC; 124 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC;
127 break; 125 break;
128 case GCMClient::PLATFORM_LINUX: 126 case GCMClient::PLATFORM_LINUX:
129 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX; 127 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
130 break; 128 break;
131 case GCMClient::PLATFORM_IOS: 129 case GCMClient::PLATFORM_IOS:
132 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS; 130 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS;
133 break; 131 break;
134 case GCMClient::PLATFORM_ANDROID: 132 case GCMClient::PLATFORM_ANDROID:
135 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_ANDROID; 133 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_ANDROID;
136 break; 134 break;
137 case GCMClient::PLATFORM_CROS: 135 case GCMClient::PLATFORM_CROS:
138 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS; 136 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS;
139 break; 137 break;
140 case GCMClient::PLATFORM_UNKNOWN: 138 case GCMClient::PLATFORM_UNKNOWN:
141 // For unknown platform, return as LINUX. 139 // For unknown platform, return as LINUX.
142 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX; 140 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
143 break; 141 break;
144 default:
145 NOTREACHED();
146 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
147 break;
148 } 142 }
149 android_build_info->set_platform(platform); 143 android_build_info->set_platform(platform);
150 144
151 checkin_proto::ChromeBuildProto_Channel channel; 145 checkin_proto::ChromeBuildProto_Channel channel =
146 checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
152 switch (chrome_build_info.channel) { 147 switch (chrome_build_info.channel) {
153 case GCMClient::CHANNEL_STABLE: 148 case GCMClient::CHANNEL_STABLE:
154 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE; 149 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE;
155 break; 150 break;
156 case GCMClient::CHANNEL_BETA: 151 case GCMClient::CHANNEL_BETA:
157 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA; 152 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA;
158 break; 153 break;
159 case GCMClient::CHANNEL_DEV: 154 case GCMClient::CHANNEL_DEV:
160 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV; 155 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV;
161 break; 156 break;
162 case GCMClient::CHANNEL_CANARY: 157 case GCMClient::CHANNEL_CANARY:
163 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY; 158 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY;
164 break; 159 break;
165 case GCMClient::CHANNEL_UNKNOWN: 160 case GCMClient::CHANNEL_UNKNOWN:
166 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN; 161 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
167 break; 162 break;
168 default:
169 NOTREACHED();
170 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
171 break;
172 } 163 }
173 android_build_info->set_channel(channel); 164 android_build_info->set_channel(channel);
174 165
175 android_build_info->set_chrome_version(chrome_build_info.version); 166 android_build_info->set_chrome_version(chrome_build_info.version);
176 } 167 }
177 168
178 MessageType DecodeMessageType(const std::string& value) { 169 MessageType DecodeMessageType(const std::string& value) {
179 if (kMessageTypeDeletedMessagesKey == value) 170 if (kMessageTypeDeletedMessagesKey == value)
180 return DELETED_MESSAGES; 171 return DELETED_MESSAGES;
181 if (kMessageTypeSendErrorKey == value) 172 if (kMessageTypeSendErrorKey == value)
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 app_data->set_value(iter->second); 1143 app_data->set_value(iter->second);
1153 } 1144 }
1154 1145
1155 MCSMessage mcs_message(stanza); 1146 MCSMessage mcs_message(stanza);
1156 DVLOG(1) << "MCS message size: " << mcs_message.size(); 1147 DVLOG(1) << "MCS message size: " << mcs_message.size();
1157 mcs_client_->SendMessage(mcs_message); 1148 mcs_client_->SendMessage(mcs_message);
1158 } 1149 }
1159 1150
1160 std::string GCMClientImpl::GetStateString() const { 1151 std::string GCMClientImpl::GetStateString() const {
1161 switch(state_) { 1152 switch(state_) {
1153 case GCMClientImpl::UNINITIALIZED:
1154 return "UNINITIALIZED";
1162 case GCMClientImpl::INITIALIZED: 1155 case GCMClientImpl::INITIALIZED:
1163 return "INITIALIZED"; 1156 return "INITIALIZED";
1164 case GCMClientImpl::UNINITIALIZED:
1165 return "UNINITIALIZED";
1166 case GCMClientImpl::LOADING: 1157 case GCMClientImpl::LOADING:
1167 return "LOADING"; 1158 return "LOADING";
1168 case GCMClientImpl::LOADED: 1159 case GCMClientImpl::LOADED:
1169 return "LOADED"; 1160 return "LOADED";
1170 case GCMClientImpl::INITIAL_DEVICE_CHECKIN: 1161 case GCMClientImpl::INITIAL_DEVICE_CHECKIN:
1171 return "INITIAL_DEVICE_CHECKIN"; 1162 return "INITIAL_DEVICE_CHECKIN";
1172 case GCMClientImpl::READY: 1163 case GCMClientImpl::READY:
1173 return "READY"; 1164 return "READY";
1174 default:
1175 NOTREACHED();
1176 return std::string();
1177 } 1165 }
1166 NOTREACHED();
1167 return std::string();
1178 } 1168 }
1179 1169
1180 void GCMClientImpl::RecordDecryptionFailure( 1170 void GCMClientImpl::RecordDecryptionFailure(
1181 const std::string& app_id, 1171 const std::string& app_id,
1182 GCMEncryptionProvider::DecryptionResult result) { 1172 GCMEncryptionProvider::DecryptionResult result) {
1183 recorder_.RecordDecryptionFailure(app_id, result); 1173 recorder_.RecordDecryptionFailure(app_id, result);
1184 } 1174 }
1185 1175
1186 void GCMClientImpl::SetRecording(bool recording) { 1176 void GCMClientImpl::SetRecording(bool recording) {
1187 recorder_.set_is_recording(recording); 1177 recorder_.set_is_recording(recording);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 case DELETED_MESSAGES: 1326 case DELETED_MESSAGES:
1337 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(), 1327 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(),
1338 data_message_stanza.ByteSize(), true, 1328 data_message_stanza.ByteSize(), true,
1339 GCMStatsRecorder::DELETED_MESSAGES); 1329 GCMStatsRecorder::DELETED_MESSAGES);
1340 delegate_->OnMessagesDeleted(app_id); 1330 delegate_->OnMessagesDeleted(app_id);
1341 break; 1331 break;
1342 case SEND_ERROR: 1332 case SEND_ERROR:
1343 HandleIncomingSendError(app_id, data_message_stanza, message_data); 1333 HandleIncomingSendError(app_id, data_message_stanza, message_data);
1344 break; 1334 break;
1345 case UNKNOWN: 1335 case UNKNOWN:
1346 default: // Treat default the same as UNKNOWN.
1347 DVLOG(1) << "Unknown message_type received. Message ignored. " 1336 DVLOG(1) << "Unknown message_type received. Message ignored. "
1348 << "App ID: " << app_id << "."; 1337 << "App ID: " << app_id << ".";
1349 break; 1338 break;
1350 } 1339 }
1351 } 1340 }
1352 1341
1353 void GCMClientImpl::HandleIncomingDataMessage( 1342 void GCMClientImpl::HandleIncomingDataMessage(
1354 const std::string& app_id, 1343 const std::string& app_id,
1355 bool was_subtype, 1344 bool was_subtype,
1356 const mcs_proto::DataMessageStanza& data_message_stanza, 1345 const mcs_proto::DataMessageStanza& data_message_stanza,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 bool GCMClientImpl::HasStandaloneRegisteredApp() const { 1429 bool GCMClientImpl::HasStandaloneRegisteredApp() const {
1441 if (registrations_.empty()) 1430 if (registrations_.empty())
1442 return false; 1431 return false;
1443 // Note that account mapper is not counted as a standalone app since it is 1432 // Note that account mapper is not counted as a standalone app since it is
1444 // automatically started when other app uses GCM. 1433 // automatically started when other app uses GCM.
1445 return registrations_.size() > 1 || 1434 return registrations_.size() > 1 ||
1446 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); 1435 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId);
1447 } 1436 }
1448 1437
1449 } // namespace gcm 1438 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | components/gcm_driver/gcm_desktop_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698