Index: google_apis/gcm/base/mcs_util.cc |
diff --git a/google_apis/gcm/base/mcs_util.cc b/google_apis/gcm/base/mcs_util.cc |
index 736556079f8e8b902f95c5b8b104850e2ffaf036..2e41966e4ce4a7201d768cd6331e9f330a7b6126 100644 |
--- a/google_apis/gcm/base/mcs_util.cc |
+++ b/google_apis/gcm/base/mcs_util.cc |
@@ -8,6 +8,8 @@ |
#include "base/logging.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringprintf.h" |
+#include "base/time/clock.h" |
+#include "base/time/time.h" |
namespace gcm { |
@@ -44,6 +46,9 @@ const char kLoginDeviceIdPrefix[] = "android-"; |
const char kLoginSettingName[] = "new_vc"; |
const char kLoginSettingValue[] = "1"; |
+// Maximum amount of time to save an unsent outgoing message for. |
+const int kMaxTTLSeconds = 4 * 7 * 24 * 60 * 60; // 4 weeks. |
+ |
} // namespace |
scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(uint64 auth_id, |
@@ -209,25 +214,49 @@ void SetLastStreamIdReceived(uint32 val, |
if (protobuf->GetTypeName() == kProtoNames[kIqStanzaTag]) { |
reinterpret_cast<mcs_proto::IqStanza*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
} else if (protobuf->GetTypeName() == kProtoNames[kHeartbeatPingTag]) { |
reinterpret_cast<mcs_proto::HeartbeatPing*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
} else if (protobuf->GetTypeName() == kProtoNames[kHeartbeatAckTag]) { |
reinterpret_cast<mcs_proto::HeartbeatAck*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
} else if (protobuf->GetTypeName() == kProtoNames[kDataMessageStanzaTag]) { |
reinterpret_cast<mcs_proto::DataMessageStanza*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
} else if (protobuf->GetTypeName() == kProtoNames[kLoginResponseTag]) { |
reinterpret_cast<mcs_proto::LoginResponse*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
} |
NOTREACHED(); |
} |
+bool HasTTLExpired(const google::protobuf::MessageLite& protobuf, |
+ base::Clock* clock) { |
+ if (protobuf.GetTypeName() != kProtoNames[kDataMessageStanzaTag]) |
+ return false; |
+ uint64 ttl = GetTTL(protobuf); |
+ uint64 sent = |
+ reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf)->sent(); |
+ return ttl > 0 && |
+ clock->Now() > |
+ base::Time::FromInternalValue( |
+ (sent + ttl) * base::Time::kMicrosecondsPerSecond); |
+} |
+ |
+int GetTTL(const google::protobuf::MessageLite& protobuf) { |
+ if (protobuf.GetTypeName() != kProtoNames[kDataMessageStanzaTag]) |
+ return 0; |
+ const mcs_proto::DataMessageStanza* data_message = |
+ reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf); |
+ if (!data_message->has_ttl()) |
+ return kMaxTTLSeconds; |
+ return data_message->ttl() <= kMaxTTLSeconds ? |
+ data_message->ttl() : kMaxTTLSeconds; |
fgorski
2014/01/02 21:47:35
I think sanitizing of the input is expected to hap
Nicolas Zea
2014/01/02 21:50:52
Yeah, I guess this implies it's valid, when it sho
|
+} |
+ |
} // namespace gcm |