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_driver.h" | 5 #include "components/gcm_driver/gcm_driver.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_number_conversions.h" | |
16 #include "base/time/time.h" | |
15 #include "components/gcm_driver/gcm_app_handler.h" | 17 #include "components/gcm_driver/gcm_app_handler.h" |
16 | 18 |
17 namespace gcm { | 19 namespace gcm { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const size_t kMaxSenders = 100; | 23 const size_t kMaxSenders = 100; |
22 | 24 |
25 const char* kGcmMessageTypeKey = "type"; | |
26 | |
27 const char* kMessageReceiptType = "message_recipt"; | |
Peter Beverloo
2016/12/15 19:24:24
recipt -> receipt
harkness
2016/12/21 17:23:38
Done.
| |
28 const char* kReceiptMessageIdKey = "message_id"; | |
29 const char* kReceiptStatusKey = "status"; | |
30 const char* kReceiptGCMDestinationID = "1029510549786@google.com"; | |
Peter Beverloo
2016/12/15 19:24:24
Also what is this number? Would other users of the
Peter Beverloo
2016/12/15 19:24:24
micro nit:
const char kFoo[] = "bar";
harkness
2016/12/21 17:23:38
Done.
harkness
2016/12/21 17:23:38
Done.
| |
31 const int kReceiptTTLInSeconds = 10; | |
32 | |
23 } // namespace | 33 } // namespace |
24 | 34 |
25 InstanceIDHandler::InstanceIDHandler() { | 35 InstanceIDHandler::InstanceIDHandler() { |
26 } | 36 } |
27 | 37 |
28 InstanceIDHandler::~InstanceIDHandler() { | 38 InstanceIDHandler::~InstanceIDHandler() { |
29 } | 39 } |
30 | 40 |
31 void InstanceIDHandler::DeleteAllTokensForApp( | 41 void InstanceIDHandler::DeleteAllTokensForApp( |
32 const std::string& app_id, const DeleteTokenCallback& callback) { | 42 const std::string& app_id, const DeleteTokenCallback& callback) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 SendImpl(app_id, receiver_id, message); | 172 SendImpl(app_id, receiver_id, message); |
163 } | 173 } |
164 | 174 |
165 void GCMDriver::GetEncryptionInfo( | 175 void GCMDriver::GetEncryptionInfo( |
166 const std::string& app_id, | 176 const std::string& app_id, |
167 const GetEncryptionInfoCallback& callback) { | 177 const GetEncryptionInfoCallback& callback) { |
168 encryption_provider_.GetEncryptionInfo(app_id, "" /* authorized_entity */, | 178 encryption_provider_.GetEncryptionInfo(app_id, "" /* authorized_entity */, |
169 callback); | 179 callback); |
170 } | 180 } |
171 | 181 |
182 void GCMDriver::SendMessageReceipt(const std::string& message_id, | |
183 const std::string& app_id, | |
184 int status) { | |
185 DCHECK(!app_id.empty()); | |
186 | |
187 // Prepare a message to send to GCM which will log the status of the received | |
188 // message. This is aggregated by GCM to provide better error alerting. | |
189 OutgoingMessage message; | |
190 message.time_to_live = kReceiptTTLInSeconds; | |
191 message.id = | |
192 base::Int64ToString(base::Time::NowFromSystemTime().ToInternalValue()); | |
Peter Beverloo
2016/12/15 19:24:24
Why is the difference between Now() and NowFromSys
harkness
2016/12/21 17:23:38
I used it for consistency with Send(), but accordi
| |
193 message.data[kGcmMessageTypeKey] = kMessageReceiptType; | |
194 message.data[kReceiptMessageIdKey] = message_id; | |
195 message.data[kReceiptStatusKey] = base::IntToString(status); | |
196 | |
197 SendImpl(app_id, kReceiptGCMDestinationID, message); | |
198 } | |
199 | |
200 // GCM will always ack receipts, but there is no action taken when the ack is | |
201 // received. | |
202 void GCMDriver::SendMessageReceiptCallback(const std::string& message_id, | |
Peter Beverloo
2016/12/15 19:24:24
unused
harkness
2016/12/21 17:23:38
Yup, this was the callback stuff that I mentioned
| |
203 GCMClient::Result result) {} | |
204 | |
172 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, | 205 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, |
173 const std::string& sender_id) { | 206 const std::string& sender_id) { |
174 NOTREACHED(); | 207 NOTREACHED(); |
175 } | 208 } |
176 | 209 |
177 void GCMDriver::RegisterFinished(const std::string& app_id, | 210 void GCMDriver::RegisterFinished(const std::string& app_id, |
178 const std::string& registration_id, | 211 const std::string& registration_id, |
179 GCMClient::Result result) { | 212 GCMClient::Result result) { |
180 std::map<std::string, RegisterCallback>::iterator callback_iter = | 213 std::map<std::string, RegisterCallback>::iterator callback_iter = |
181 register_callbacks_.find(app_id); | 214 register_callbacks_.find(app_id); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 void GCMDriver::DispatchMessageInternal( | 321 void GCMDriver::DispatchMessageInternal( |
289 const std::string& app_id, | 322 const std::string& app_id, |
290 GCMEncryptionProvider::DecryptionResult result, | 323 GCMEncryptionProvider::DecryptionResult result, |
291 const IncomingMessage& message) { | 324 const IncomingMessage& message) { |
292 UMA_HISTOGRAM_ENUMERATION("GCM.Crypto.DecryptMessageResult", result, | 325 UMA_HISTOGRAM_ENUMERATION("GCM.Crypto.DecryptMessageResult", result, |
293 GCMEncryptionProvider::DECRYPTION_RESULT_LAST + 1); | 326 GCMEncryptionProvider::DECRYPTION_RESULT_LAST + 1); |
294 | 327 |
295 switch (result) { | 328 switch (result) { |
296 case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED: | 329 case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED: |
297 case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED: | 330 case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED: |
331 // TODO(beverloo): When the DefaultAppHandler is gone, call | |
332 // SendMessageReceipt here if there isn't a valid app handler. | |
298 GetAppHandler(app_id)->OnMessage(app_id, message); | 333 GetAppHandler(app_id)->OnMessage(app_id, message); |
299 return; | 334 return; |
300 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER: | 335 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER: |
301 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER: | 336 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER: |
302 case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS: | 337 case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS: |
303 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET: | 338 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET: |
304 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD: | 339 case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD: |
340 SendMessageReceipt(message.id, app_id, GCMClient::GCM_ENCRYPTION_FAILURE); | |
305 RecordDecryptionFailure(app_id, result); | 341 RecordDecryptionFailure(app_id, result); |
306 return; | 342 return; |
307 } | 343 } |
308 | 344 |
309 NOTREACHED(); | 345 NOTREACHED(); |
310 } | 346 } |
311 | 347 |
312 void GCMDriver::RegisterAfterUnregister( | 348 void GCMDriver::RegisterAfterUnregister( |
313 const std::string& app_id, | 349 const std::string& app_id, |
314 const std::vector<std::string>& normalized_sender_ids, | 350 const std::vector<std::string>& normalized_sender_ids, |
315 const UnregisterCallback& unregister_callback, | 351 const UnregisterCallback& unregister_callback, |
316 GCMClient::Result result) { | 352 GCMClient::Result result) { |
317 // Invoke the original unregister callback. | 353 // Invoke the original unregister callback. |
318 unregister_callback.Run(result); | 354 unregister_callback.Run(result); |
319 | 355 |
320 // Trigger the pending registration. | 356 // Trigger the pending registration. |
321 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 357 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
322 RegisterImpl(app_id, normalized_sender_ids); | 358 RegisterImpl(app_id, normalized_sender_ids); |
323 } | 359 } |
324 | 360 |
325 } // namespace gcm | 361 } // namespace gcm |
OLD | NEW |