OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/gcm_client_impl.h" | 5 #include "google_apis/gcm/gcm_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 }; | 62 }; |
63 | 63 |
64 // Indicates a message type of the received message. | 64 // Indicates a message type of the received message. |
65 enum MessageType { | 65 enum MessageType { |
66 UNKNOWN, // Undetermined type. | 66 UNKNOWN, // Undetermined type. |
67 DATA_MESSAGE, // Regular data message. | 67 DATA_MESSAGE, // Regular data message. |
68 DELETED_MESSAGES, // Messages were deleted on the server. | 68 DELETED_MESSAGES, // Messages were deleted on the server. |
69 SEND_ERROR, // Error sending a message. | 69 SEND_ERROR, // Error sending a message. |
70 }; | 70 }; |
71 | 71 |
72 enum OutgoingMessageTTLCategory { | |
73 TTL_ZERO, | |
74 TTL_LESS_THAN_OR_EQUAL_TO_ONE_MINUTE, | |
75 TTL_LESS_THAN_OR_EQUAL_TO_ONE_HOUR, | |
76 TTL_LESS_THAN_OR_EQUAL_TO_ONE_DAY, | |
77 TTL_LESS_THAN_OR_EQUAL_TO_ONE_WEEK, | |
78 TTL_MORE_THAN_ONE_WEEK, | |
79 TTL_MAXIMUM, | |
80 // NOTE: always keep this entry at the end. Add new TTL category only | |
81 // immediately above this line. Make sure to update the corresponding | |
82 // histogram enum accordingly. | |
83 TTL_CATEGORY_COUNT | |
84 }; | |
85 | |
72 // MCS endpoints. SSL Key pinning is done automatically due to the *.google.com | 86 // MCS endpoints. SSL Key pinning is done automatically due to the *.google.com |
73 // pinning rule. | 87 // pinning rule. |
74 // Note: modifying the endpoints will affect the ability to compare the | 88 // Note: modifying the endpoints will affect the ability to compare the |
75 // GCM.CurrentEnpoint histogram across versions. | 89 // GCM.CurrentEnpoint histogram across versions. |
76 const char kMCSEndpointMain[] = "https://mtalk.google.com:5228"; | 90 const char kMCSEndpointMain[] = "https://mtalk.google.com:5228"; |
77 const char kMCSEndpointFallback[] = "https://mtalk.google.com:443"; | 91 const char kMCSEndpointFallback[] = "https://mtalk.google.com:443"; |
78 | 92 |
79 const int kMaxRegistrationRetries = 5; | 93 const int kMaxRegistrationRetries = 5; |
80 const char kMessageTypeDataMessage[] = "gcm"; | 94 const char kMessageTypeDataMessage[] = "gcm"; |
81 const char kMessageTypeDeletedMessagesKey[] = "deleted_messages"; | 95 const char kMessageTypeDeletedMessagesKey[] = "deleted_messages"; |
(...skipping 28 matching lines...) Expand all Loading... | |
110 MessageType DecodeMessageType(const std::string& value) { | 124 MessageType DecodeMessageType(const std::string& value) { |
111 if (kMessageTypeDeletedMessagesKey == value) | 125 if (kMessageTypeDeletedMessagesKey == value) |
112 return DELETED_MESSAGES; | 126 return DELETED_MESSAGES; |
113 if (kMessageTypeSendErrorKey == value) | 127 if (kMessageTypeSendErrorKey == value) |
114 return SEND_ERROR; | 128 return SEND_ERROR; |
115 if (kMessageTypeDataMessage == value) | 129 if (kMessageTypeDataMessage == value) |
116 return DATA_MESSAGE; | 130 return DATA_MESSAGE; |
117 return UNKNOWN; | 131 return UNKNOWN; |
118 } | 132 } |
119 | 133 |
134 void RecordROutgoingMessageToUMA( | |
135 const gcm::GCMClient::OutgoingMessage& message) { | |
136 OutgoingMessageTTLCategory ttl_category; | |
137 if (message.time_to_live == 0) | |
138 ttl_category = TTL_ZERO; | |
139 else if (message.time_to_live <= 60 ) | |
140 ttl_category = TTL_LESS_THAN_OR_EQUAL_TO_ONE_MINUTE; | |
141 else if (message.time_to_live <= 60 * 60) | |
142 ttl_category = TTL_LESS_THAN_OR_EQUAL_TO_ONE_HOUR; | |
143 else if (message.time_to_live <= 24 * 60 * 60) | |
144 ttl_category = TTL_LESS_THAN_OR_EQUAL_TO_ONE_DAY; | |
145 else if (message.time_to_live <= 7 * 24 * 60 * 60) | |
146 ttl_category = TTL_LESS_THAN_OR_EQUAL_TO_ONE_WEEK; | |
147 else if (message.time_to_live < gcm::GCMClient::OutgoingMessage::kMaximumTTL) | |
148 ttl_category = TTL_MORE_THAN_ONE_WEEK; | |
149 else | |
150 ttl_category = TTL_MAXIMUM; | |
151 | |
152 UMA_HISTOGRAM_ENUMERATION("GCM.GCMOutgoingMessageTTLCategory", | |
153 ttl_category, | |
154 TTL_CATEGORY_COUNT); | |
155 } | |
156 | |
120 } // namespace | 157 } // namespace |
121 | 158 |
122 GCMInternalsBuilder::GCMInternalsBuilder() {} | 159 GCMInternalsBuilder::GCMInternalsBuilder() {} |
123 GCMInternalsBuilder::~GCMInternalsBuilder() {} | 160 GCMInternalsBuilder::~GCMInternalsBuilder() {} |
124 | 161 |
125 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { | 162 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { |
126 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); | 163 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); |
127 } | 164 } |
128 | 165 |
129 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( | 166 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { | 587 void GCMClientImpl::OnGCMStoreDestroyed(bool success) { |
551 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; | 588 DLOG_IF(ERROR, !success) << "GCM store failed to be destroyed!"; |
552 UMA_HISTOGRAM_BOOLEAN("GCM.StoreDestroySucceeded", success); | 589 UMA_HISTOGRAM_BOOLEAN("GCM.StoreDestroySucceeded", success); |
553 } | 590 } |
554 | 591 |
555 void GCMClientImpl::Send(const std::string& app_id, | 592 void GCMClientImpl::Send(const std::string& app_id, |
556 const std::string& receiver_id, | 593 const std::string& receiver_id, |
557 const OutgoingMessage& message) { | 594 const OutgoingMessage& message) { |
558 DCHECK_EQ(state_, READY); | 595 DCHECK_EQ(state_, READY); |
559 | 596 |
597 RecordROutgoingMessageToUMA(message); | |
Nicolas Zea
2014/05/08 21:28:19
RecordROutgoingMessageToUma -> remove the extra R
jianli
2014/05/08 21:40:47
Done.
| |
598 | |
560 mcs_proto::DataMessageStanza stanza; | 599 mcs_proto::DataMessageStanza stanza; |
561 stanza.set_ttl(message.time_to_live); | 600 stanza.set_ttl(message.time_to_live); |
562 stanza.set_sent(clock_->Now().ToInternalValue() / | 601 stanza.set_sent(clock_->Now().ToInternalValue() / |
563 base::Time::kMicrosecondsPerSecond); | 602 base::Time::kMicrosecondsPerSecond); |
564 stanza.set_id(message.id); | 603 stanza.set_id(message.id); |
565 stanza.set_from(kSendMessageFromValue); | 604 stanza.set_from(kSendMessageFromValue); |
566 stanza.set_to(receiver_id); | 605 stanza.set_to(receiver_id); |
567 stanza.set_category(app_id); | 606 stanza.set_category(app_id); |
568 | 607 |
569 for (MessageData::const_iterator iter = message.data.begin(); | 608 for (MessageData::const_iterator iter = message.data.begin(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 | 803 |
765 recorder_.RecordIncomingSendError( | 804 recorder_.RecordIncomingSendError( |
766 data_message_stanza.category(), | 805 data_message_stanza.category(), |
767 data_message_stanza.to(), | 806 data_message_stanza.to(), |
768 data_message_stanza.id()); | 807 data_message_stanza.id()); |
769 delegate_->OnMessageSendError(data_message_stanza.category(), | 808 delegate_->OnMessageSendError(data_message_stanza.category(), |
770 send_error_details); | 809 send_error_details); |
771 } | 810 } |
772 | 811 |
773 } // namespace gcm | 812 } // namespace gcm |
OLD | NEW |