| 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..da30f896a74ffb29b869ff77e115720894d051ea 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,50 @@ 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();
|
| + DCHECK(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;
|
| + DCHECK_LE(data_message->ttl(), kMaxTTLSeconds);
|
| + return data_message->ttl();
|
| +}
|
| +
|
| } // namespace gcm
|
|
|