Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: google_apis/gcm/base/mcs_util.cc

Issue 117513004: [GCM] Add TTL support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/base/mcs_util.h ('k') | google_apis/gcm/engine/mcs_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « google_apis/gcm/base/mcs_util.h ('k') | google_apis/gcm/engine/mcs_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698