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..750321a0a671cae495b3ba11551dcf9583368cd6 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 { |
@@ -209,25 +211,46 @@ 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 = |
+ reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf)->ttl(); |
+ 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; |
+ return reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf)-> |
+ ttl(); |
+} |
+ |
} // namespace gcm |