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 "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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 INFINITE_STORE_RESET, | 75 INFINITE_STORE_RESET, |
76 // NOTE: always keep this entry at the end. Add new value only immediately | 76 // NOTE: always keep this entry at the end. Add new value only immediately |
77 // above this line. Make sure to update the corresponding histogram enum | 77 // above this line. Make sure to update the corresponding histogram enum |
78 // accordingly. | 78 // accordingly. |
79 RESET_STORE_ERROR_COUNT | 79 RESET_STORE_ERROR_COUNT |
80 }; | 80 }; |
81 | 81 |
82 const char kGCMScope[] = "GCM"; | 82 const char kGCMScope[] = "GCM"; |
83 const int kMaxRegistrationRetries = 5; | 83 const int kMaxRegistrationRetries = 5; |
84 const int kMaxUnregistrationRetries = 5; | 84 const int kMaxUnregistrationRetries = 5; |
85 const char kDeletedCountKey[] = "total_deleted"; | |
85 const char kMessageTypeDataMessage[] = "gcm"; | 86 const char kMessageTypeDataMessage[] = "gcm"; |
86 const char kMessageTypeDeletedMessagesKey[] = "deleted_messages"; | 87 const char kMessageTypeDeletedMessagesKey[] = "deleted_messages"; |
87 const char kMessageTypeKey[] = "message_type"; | 88 const char kMessageTypeKey[] = "message_type"; |
88 const char kMessageTypeSendErrorKey[] = "send_error"; | 89 const char kMessageTypeSendErrorKey[] = "send_error"; |
89 const char kSendErrorMessageIdKey[] = "google.message_id"; | 90 const char kSendErrorMessageIdKey[] = "google.message_id"; |
90 const char kSubtypeKey[] = "subtype"; | 91 const char kSubtypeKey[] = "subtype"; |
91 const char kSendMessageFromValue[] = "gcm@chrome.com"; | 92 const char kSendMessageFromValue[] = "gcm@chrome.com"; |
92 const int64_t kDefaultUserSerialNumber = 0LL; | 93 const int64_t kDefaultUserSerialNumber = 0LL; |
93 const int kDestroyGCMStoreDelayMS = 5 * 60 * 1000; // 5 minutes. | 94 const int kDestroyGCMStoreDelayMS = 5 * 60 * 1000; // 5 minutes. |
94 | 95 |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1327 if (type_iter != message_data.end()) { | 1328 if (type_iter != message_data.end()) { |
1328 message_type = DecodeMessageType(type_iter->second); | 1329 message_type = DecodeMessageType(type_iter->second); |
1329 message_data.erase(type_iter); | 1330 message_data.erase(type_iter); |
1330 } | 1331 } |
1331 | 1332 |
1332 switch (message_type) { | 1333 switch (message_type) { |
1333 case DATA_MESSAGE: | 1334 case DATA_MESSAGE: |
1334 HandleIncomingDataMessage(app_id, use_subtype, data_message_stanza, | 1335 HandleIncomingDataMessage(app_id, use_subtype, data_message_stanza, |
1335 message_data); | 1336 message_data); |
1336 break; | 1337 break; |
1337 case DELETED_MESSAGES: | 1338 case DELETED_MESSAGES: { |
1339 int deleted_count = 0; | |
1340 MessageData::iterator count_iter = message_data.find(kDeletedCountKey); | |
1341 if (count_iter != message_data.end()) { | |
1342 if (!base::StringToInt(count_iter->second, &deleted_count)) | |
1343 deleted_count = 0; | |
1344 } | |
1338 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(), | 1345 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(), |
1339 data_message_stanza.ByteSize(), true, | 1346 data_message_stanza.ByteSize(), true, |
1340 GCMStatsRecorder::DELETED_MESSAGES); | 1347 GCMStatsRecorder::DELETED_MESSAGES, |
1348 false /* has_collapse_key */, | |
1349 deleted_count); | |
1341 delegate_->OnMessagesDeleted(app_id); | 1350 delegate_->OnMessagesDeleted(app_id); |
Peter Beverloo
2016/12/07 13:44:12
nit: please split this block out into an HandleInc
johnme
2016/12/07 14:29:16
Done.
| |
1342 break; | 1351 break; |
1352 } | |
1343 case SEND_ERROR: | 1353 case SEND_ERROR: |
1344 HandleIncomingSendError(app_id, data_message_stanza, message_data); | 1354 HandleIncomingSendError(app_id, data_message_stanza, message_data); |
1345 break; | 1355 break; |
1346 case UNKNOWN: | 1356 case UNKNOWN: |
1347 DVLOG(1) << "Unknown message_type received. Message ignored. " | 1357 DVLOG(1) << "Unknown message_type received. Message ignored. " |
1348 << "App ID: " << app_id << "."; | 1358 << "App ID: " << app_id << "."; |
1349 break; | 1359 break; |
1350 } | 1360 } |
1351 } | 1361 } |
1352 | 1362 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 if (instance_id_token_iter != registrations_.end()) { | 1404 if (instance_id_token_iter != registrations_.end()) { |
1395 if (was_subtype != InstanceIDUsesSubtypeForAppId(app_id)) { | 1405 if (was_subtype != InstanceIDUsesSubtypeForAppId(app_id)) { |
1396 DLOG(ERROR) << "GCM message for " << app_id | 1406 DLOG(ERROR) << "GCM message for " << app_id |
1397 << " incorrectly had was_subtype = " << was_subtype; | 1407 << " incorrectly had was_subtype = " << was_subtype; |
1398 } else { | 1408 } else { |
1399 registered = true; | 1409 registered = true; |
1400 } | 1410 } |
1401 } | 1411 } |
1402 } | 1412 } |
1403 | 1413 |
1404 recorder_.RecordDataMessageReceived(app_id, sender, | 1414 recorder_.RecordDataMessageReceived( |
1405 data_message_stanza.ByteSize(), registered, | 1415 app_id, sender, data_message_stanza.ByteSize(), registered, |
1406 GCMStatsRecorder::DATA_MESSAGE); | 1416 GCMStatsRecorder::DATA_MESSAGE, |
1417 data_message_stanza.has_token() && !data_message_stanza.token().empty(), | |
1418 0 /* deleted_count */); | |
1407 if (!registered) | 1419 if (!registered) |
1408 return; | 1420 return; |
1409 | 1421 |
1410 IncomingMessage incoming_message; | 1422 IncomingMessage incoming_message; |
1411 incoming_message.sender_id = data_message_stanza.from(); | 1423 incoming_message.sender_id = data_message_stanza.from(); |
1412 if (data_message_stanza.has_token()) | 1424 if (data_message_stanza.has_token()) |
1413 incoming_message.collapse_key = data_message_stanza.token(); | 1425 incoming_message.collapse_key = data_message_stanza.token(); |
1414 incoming_message.data = message_data; | 1426 incoming_message.data = message_data; |
1415 incoming_message.raw_data = data_message_stanza.raw_data(); | 1427 incoming_message.raw_data = data_message_stanza.raw_data(); |
1416 | 1428 |
(...skipping 23 matching lines...) Expand all Loading... | |
1440 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1452 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
1441 if (registrations_.empty()) | 1453 if (registrations_.empty()) |
1442 return false; | 1454 return false; |
1443 // Note that account mapper is not counted as a standalone app since it is | 1455 // Note that account mapper is not counted as a standalone app since it is |
1444 // automatically started when other app uses GCM. | 1456 // automatically started when other app uses GCM. |
1445 return registrations_.size() > 1 || | 1457 return registrations_.size() > 1 || |
1446 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1458 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
1447 } | 1459 } |
1448 | 1460 |
1449 } // namespace gcm | 1461 } // namespace gcm |
OLD | NEW |