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..d3e0077fc259928b33f8194cd443240bf2826f20 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,49 @@ void SetLastStreamIdReceived(uint32 val, |
if (protobuf->GetTypeName() == kProtoNames[kIqStanzaTag]) { |
reinterpret_cast<mcs_proto::IqStanza*>(protobuf)-> |
set_last_stream_id_received(val); |
- return; |
+ return; |
fgorski
2013/12/28 01:15:08
should be indented 2 to the left (under reinterpre
Nicolas Zea
2013/12/30 21:46:19
Done.
|
} 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(); |
+ if (ttl > 0 && |
fgorski
2013/12/28 01:15:08
would a single return in place of if statement wor
Nicolas Zea
2013/12/30 21:46:19
Done.
|
+ clock->Now() > |
+ base::Time::FromInternalValue( |
+ (sent + ttl) * base::Time::kMicrosecondsPerSecond)) { |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+int GetTTL(const google::protobuf::MessageLite& protobuf) { |
+ if (protobuf.GetTypeName() != kProtoNames[kDataMessageStanzaTag]) |
+ return 0; |
+ return reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf)-> |
fgorski
2013/12/28 01:15:08
ttl might not be set, return max in that case.
Nicolas Zea
2013/12/30 21:46:19
Should we default to max, or assume that the messa
fgorski
2014/01/02 18:09:27
The API allows the user to not set the TTL and a d
Nicolas Zea
2014/01/02 21:39:08
Done.
|
+ ttl(); |
+} |
+ |
} // namespace gcm |