Index: components/gcm_driver/gcm_driver.cc |
diff --git a/components/gcm_driver/gcm_driver.cc b/components/gcm_driver/gcm_driver.cc |
index 21d30549d07030b043adfa405f0ab45eb6b94931..f6fd466e5128e5289670a70dae97e4c4487168bf 100644 |
--- a/components/gcm_driver/gcm_driver.cc |
+++ b/components/gcm_driver/gcm_driver.cc |
@@ -12,6 +12,8 @@ |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/metrics/histogram_macros.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/time/time.h" |
#include "components/gcm_driver/gcm_app_handler.h" |
namespace gcm { |
@@ -20,6 +22,14 @@ namespace { |
const size_t kMaxSenders = 100; |
+const char* kGcmMessageTypeKey = "type"; |
+ |
+const char* kMessageReceiptType = "message_recipt"; |
Peter Beverloo
2016/12/15 19:24:24
recipt -> receipt
harkness
2016/12/21 17:23:38
Done.
|
+const char* kReceiptMessageIdKey = "message_id"; |
+const char* kReceiptStatusKey = "status"; |
+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.
|
+const int kReceiptTTLInSeconds = 10; |
+ |
} // namespace |
InstanceIDHandler::InstanceIDHandler() { |
@@ -169,6 +179,29 @@ void GCMDriver::GetEncryptionInfo( |
callback); |
} |
+void GCMDriver::SendMessageReceipt(const std::string& message_id, |
+ const std::string& app_id, |
+ int status) { |
+ DCHECK(!app_id.empty()); |
+ |
+ // Prepare a message to send to GCM which will log the status of the received |
+ // message. This is aggregated by GCM to provide better error alerting. |
+ OutgoingMessage message; |
+ message.time_to_live = kReceiptTTLInSeconds; |
+ message.id = |
+ 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
|
+ message.data[kGcmMessageTypeKey] = kMessageReceiptType; |
+ message.data[kReceiptMessageIdKey] = message_id; |
+ message.data[kReceiptStatusKey] = base::IntToString(status); |
+ |
+ SendImpl(app_id, kReceiptGCMDestinationID, message); |
+} |
+ |
+// GCM will always ack receipts, but there is no action taken when the ack is |
+// received. |
+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
|
+ GCMClient::Result result) {} |
+ |
void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, |
const std::string& sender_id) { |
NOTREACHED(); |
@@ -295,6 +328,8 @@ void GCMDriver::DispatchMessageInternal( |
switch (result) { |
case GCMEncryptionProvider::DECRYPTION_RESULT_UNENCRYPTED: |
case GCMEncryptionProvider::DECRYPTION_RESULT_DECRYPTED: |
+ // TODO(beverloo): When the DefaultAppHandler is gone, call |
+ // SendMessageReceipt here if there isn't a valid app handler. |
GetAppHandler(app_id)->OnMessage(app_id, message); |
return; |
case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER: |
@@ -302,6 +337,7 @@ void GCMDriver::DispatchMessageInternal( |
case GCMEncryptionProvider::DECRYPTION_RESULT_NO_KEYS: |
case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_SHARED_SECRET: |
case GCMEncryptionProvider::DECRYPTION_RESULT_INVALID_PAYLOAD: |
+ SendMessageReceipt(message.id, app_id, GCMClient::GCM_ENCRYPTION_FAILURE); |
RecordDecryptionFailure(app_id, result); |
return; |
} |