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 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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: |
1338 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(), | 1339 HandleIncomingDeletedMessages(app_id, data_message_stanza, message_data); |
1339 data_message_stanza.ByteSize(), true, | |
1340 GCMStatsRecorder::DELETED_MESSAGES); | |
1341 delegate_->OnMessagesDeleted(app_id); | |
1342 break; | 1340 break; |
1343 case SEND_ERROR: | 1341 case SEND_ERROR: |
1344 HandleIncomingSendError(app_id, data_message_stanza, message_data); | 1342 HandleIncomingSendError(app_id, data_message_stanza, message_data); |
1345 break; | 1343 break; |
1346 case UNKNOWN: | 1344 case UNKNOWN: |
1347 DVLOG(1) << "Unknown message_type received. Message ignored. " | 1345 DVLOG(1) << "Unknown message_type received. Message ignored. " |
1348 << "App ID: " << app_id << "."; | 1346 << "App ID: " << app_id << "."; |
1349 break; | 1347 break; |
1350 } | 1348 } |
1351 } | 1349 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 if (instance_id_token_iter != registrations_.end()) { | 1392 if (instance_id_token_iter != registrations_.end()) { |
1395 if (was_subtype != InstanceIDUsesSubtypeForAppId(app_id)) { | 1393 if (was_subtype != InstanceIDUsesSubtypeForAppId(app_id)) { |
1396 DLOG(ERROR) << "GCM message for " << app_id | 1394 DLOG(ERROR) << "GCM message for " << app_id |
1397 << " incorrectly had was_subtype = " << was_subtype; | 1395 << " incorrectly had was_subtype = " << was_subtype; |
1398 } else { | 1396 } else { |
1399 registered = true; | 1397 registered = true; |
1400 } | 1398 } |
1401 } | 1399 } |
1402 } | 1400 } |
1403 | 1401 |
1402 UMA_HISTOGRAM_BOOLEAN("GCM.DataMessageReceivedHasRegisteredApp", registered); | |
1403 if (registered) { | |
1404 UMA_HISTOGRAM_COUNTS("GCM.DataMessageReceived", 1); | |
Ilya Sherman
2016/12/08 06:54:56
Hmm, this is a very odd histogram -- it allocates
johnme
2016/12/12 20:43:33
I'd be happy to do so if that's safe. How would I
Ilya Sherman
2016/12/12 21:07:16
Thanks! I double-checked, and it does seem safe.
johnme
2016/12/13 16:04:34
Thanks, done. I updated the xml accordingly to be
| |
1405 bool has_collapse_key = | |
1406 data_message_stanza.has_token() && !data_message_stanza.token().empty(); | |
1407 UMA_HISTOGRAM_BOOLEAN("GCM.DataMessageReceivedHasCollapseKey", | |
1408 has_collapse_key); | |
1409 } | |
1404 recorder_.RecordDataMessageReceived(app_id, sender, | 1410 recorder_.RecordDataMessageReceived(app_id, sender, |
1405 data_message_stanza.ByteSize(), registered, | 1411 data_message_stanza.ByteSize(), registered, |
1406 GCMStatsRecorder::DATA_MESSAGE); | 1412 GCMStatsRecorder::DATA_MESSAGE); |
1407 if (!registered) | 1413 if (!registered) |
1408 return; | 1414 return; |
1409 | 1415 |
1410 IncomingMessage incoming_message; | 1416 IncomingMessage incoming_message; |
1411 incoming_message.sender_id = data_message_stanza.from(); | 1417 incoming_message.sender_id = data_message_stanza.from(); |
1412 if (data_message_stanza.has_token()) | 1418 if (data_message_stanza.has_token()) |
1413 incoming_message.collapse_key = data_message_stanza.token(); | 1419 incoming_message.collapse_key = data_message_stanza.token(); |
1414 incoming_message.data = message_data; | 1420 incoming_message.data = message_data; |
1415 incoming_message.raw_data = data_message_stanza.raw_data(); | 1421 incoming_message.raw_data = data_message_stanza.raw_data(); |
1416 | 1422 |
1417 delegate_->OnMessageReceived(app_id, incoming_message); | 1423 delegate_->OnMessageReceived(app_id, incoming_message); |
1418 } | 1424 } |
1419 | 1425 |
1426 void GCMClientImpl::HandleIncomingDeletedMessages( | |
1427 const std::string& app_id, | |
1428 const mcs_proto::DataMessageStanza& data_message_stanza, | |
1429 MessageData& message_data) { | |
1430 int deleted_count = 0; | |
1431 MessageData::iterator count_iter = message_data.find(kDeletedCountKey); | |
1432 if (count_iter != message_data.end()) { | |
1433 if (!base::StringToInt(count_iter->second, &deleted_count)) | |
1434 deleted_count = 0; | |
1435 } | |
1436 UMA_HISTOGRAM_COUNTS_1000("GCM.DeletedMessagesReceived", deleted_count); | |
1437 | |
1438 recorder_.RecordDataMessageReceived(app_id, data_message_stanza.from(), | |
1439 data_message_stanza.ByteSize(), | |
1440 true /* to_registered_app */, | |
1441 GCMStatsRecorder::DELETED_MESSAGES); | |
1442 delegate_->OnMessagesDeleted(app_id); | |
1443 } | |
1444 | |
1420 void GCMClientImpl::HandleIncomingSendError( | 1445 void GCMClientImpl::HandleIncomingSendError( |
1421 const std::string& app_id, | 1446 const std::string& app_id, |
1422 const mcs_proto::DataMessageStanza& data_message_stanza, | 1447 const mcs_proto::DataMessageStanza& data_message_stanza, |
1423 MessageData& message_data) { | 1448 MessageData& message_data) { |
1424 SendErrorDetails send_error_details; | 1449 SendErrorDetails send_error_details; |
1425 send_error_details.additional_data = message_data; | 1450 send_error_details.additional_data = message_data; |
1426 send_error_details.result = SERVER_ERROR; | 1451 send_error_details.result = SERVER_ERROR; |
1427 | 1452 |
1428 MessageData::iterator iter = | 1453 MessageData::iterator iter = |
1429 send_error_details.additional_data.find(kSendErrorMessageIdKey); | 1454 send_error_details.additional_data.find(kSendErrorMessageIdKey); |
(...skipping 10 matching lines...) Expand all Loading... | |
1440 bool GCMClientImpl::HasStandaloneRegisteredApp() const { | 1465 bool GCMClientImpl::HasStandaloneRegisteredApp() const { |
1441 if (registrations_.empty()) | 1466 if (registrations_.empty()) |
1442 return false; | 1467 return false; |
1443 // Note that account mapper is not counted as a standalone app since it is | 1468 // Note that account mapper is not counted as a standalone app since it is |
1444 // automatically started when other app uses GCM. | 1469 // automatically started when other app uses GCM. |
1445 return registrations_.size() > 1 || | 1470 return registrations_.size() > 1 || |
1446 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); | 1471 !ExistsGCMRegistrationInMap(registrations_, kGCMAccountMapperAppId); |
1447 } | 1472 } |
1448 | 1473 |
1449 } // namespace gcm | 1474 } // namespace gcm |
OLD | NEW |