Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / google_apis / gcm / base / mcs_util.h
blob95d97f29489e5ef32243796ec6c121d24546189e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Utility methods for MCS interactions.
7 #ifndef GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_
8 #define GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "google_apis/gcm/base/gcm_export.h"
17 #include "google_apis/gcm/protocol/mcs.pb.h"
19 namespace base {
20 class Clock;
23 namespace net {
24 class StreamSocket;
27 namespace gcm {
29 // MCS Message tags.
30 // WARNING: the order of these tags must remain the same, as the tag values
31 // must be consistent with those used on the server.
32 enum MCSProtoTag {
33 kHeartbeatPingTag = 0,
34 kHeartbeatAckTag,
35 kLoginRequestTag,
36 kLoginResponseTag,
37 kCloseTag,
38 kMessageStanzaTag,
39 kPresenceStanzaTag,
40 kIqStanzaTag,
41 kDataMessageStanzaTag,
42 kBatchPresenceStanzaTag,
43 kStreamErrorStanzaTag,
44 kHttpRequestTag,
45 kHttpResponseTag,
46 kBindAccountRequestTag,
47 kBindAccountResponseTag,
48 kTalkMetadataTag,
49 kNumProtoTypes,
52 enum MCSIqStanzaExtension {
53 kSelectiveAck = 12,
54 kStreamAck = 13,
57 // Builds a LoginRequest with the hardcoded local data.
58 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest(
59 uint64 auth_id,
60 uint64 auth_token,
61 const std::string& version_string);
63 // Builds a StreamAck IqStanza message.
64 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck();
65 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildSelectiveAck(
66 const std::vector<std::string>& acked_ids);
68 // Utility methods for building and identifying MCS protobufs.
69 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite>
70 BuildProtobufFromTag(uint8 tag);
71 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message);
73 // RMQ utility methods for extracting/setting common data from/to protobufs.
74 GCM_EXPORT std::string GetPersistentId(
75 const google::protobuf::MessageLite& message);
76 GCM_EXPORT void SetPersistentId(
77 const std::string& persistent_id,
78 google::protobuf::MessageLite* message);
79 GCM_EXPORT uint32 GetLastStreamIdReceived(
80 const google::protobuf::MessageLite& protobuf);
81 GCM_EXPORT void SetLastStreamIdReceived(
82 uint32 last_stream_id_received,
83 google::protobuf::MessageLite* protobuf);
85 // Returns whether the TTL (time to live) for this message has expired, based
86 // on the |sent| timestamps and base::TimeTicks::Now(). If |protobuf| is not
87 // for a DataMessageStanza or the TTL is 0, will return false.
88 GCM_EXPORT bool HasTTLExpired(const google::protobuf::MessageLite& protobuf,
89 base::Clock* clock);
90 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf);
92 } // namespace gcm
94 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_