OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Utility methods for MCS interactions. | 5 // Utility methods for MCS interactions. |
6 | 6 |
7 #ifndef GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ | 7 #ifndef GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ |
8 #define GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ | 8 #define GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
| 12 #include <memory> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
18 #include "google_apis/gcm/protocol/mcs.pb.h" | 18 #include "google_apis/gcm/protocol/mcs.pb.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class Clock; | 21 class Clock; |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 class StreamSocket; | 25 class StreamSocket; |
26 } | 26 } |
(...skipping 22 matching lines...) Expand all Loading... |
49 kTalkMetadataTag, | 49 kTalkMetadataTag, |
50 kNumProtoTypes, | 50 kNumProtoTypes, |
51 }; | 51 }; |
52 | 52 |
53 enum MCSIqStanzaExtension { | 53 enum MCSIqStanzaExtension { |
54 kSelectiveAck = 12, | 54 kSelectiveAck = 12, |
55 kStreamAck = 13, | 55 kStreamAck = 13, |
56 }; | 56 }; |
57 | 57 |
58 // Builds a LoginRequest with the hardcoded local data. | 58 // Builds a LoginRequest with the hardcoded local data. |
59 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest( | 59 GCM_EXPORT std::unique_ptr<mcs_proto::LoginRequest> BuildLoginRequest( |
60 uint64_t auth_id, | 60 uint64_t auth_id, |
61 uint64_t auth_token, | 61 uint64_t auth_token, |
62 const std::string& version_string); | 62 const std::string& version_string); |
63 | 63 |
64 // Builds a StreamAck IqStanza message. | 64 // Builds a StreamAck IqStanza message. |
65 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck(); | 65 GCM_EXPORT std::unique_ptr<mcs_proto::IqStanza> BuildStreamAck(); |
66 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildSelectiveAck( | 66 GCM_EXPORT std::unique_ptr<mcs_proto::IqStanza> BuildSelectiveAck( |
67 const std::vector<std::string>& acked_ids); | 67 const std::vector<std::string>& acked_ids); |
68 | 68 |
69 // Utility methods for building and identifying MCS protobufs. | 69 // Utility methods for building and identifying MCS protobufs. |
70 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite> BuildProtobufFromTag( | 70 GCM_EXPORT std::unique_ptr<google::protobuf::MessageLite> BuildProtobufFromTag( |
71 uint8_t tag); | 71 uint8_t tag); |
72 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message); | 72 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message); |
73 | 73 |
74 // RMQ utility methods for extracting/setting common data from/to protobufs. | 74 // RMQ utility methods for extracting/setting common data from/to protobufs. |
75 GCM_EXPORT std::string GetPersistentId( | 75 GCM_EXPORT std::string GetPersistentId( |
76 const google::protobuf::MessageLite& message); | 76 const google::protobuf::MessageLite& message); |
77 GCM_EXPORT void SetPersistentId( | 77 GCM_EXPORT void SetPersistentId( |
78 const std::string& persistent_id, | 78 const std::string& persistent_id, |
79 google::protobuf::MessageLite* message); | 79 google::protobuf::MessageLite* message); |
80 GCM_EXPORT uint32_t | 80 GCM_EXPORT uint32_t |
81 GetLastStreamIdReceived(const google::protobuf::MessageLite& protobuf); | 81 GetLastStreamIdReceived(const google::protobuf::MessageLite& protobuf); |
82 GCM_EXPORT void SetLastStreamIdReceived( | 82 GCM_EXPORT void SetLastStreamIdReceived( |
83 uint32_t last_stream_id_received, | 83 uint32_t last_stream_id_received, |
84 google::protobuf::MessageLite* protobuf); | 84 google::protobuf::MessageLite* protobuf); |
85 | 85 |
86 // Returns whether the TTL (time to live) for this message has expired, based | 86 // Returns whether the TTL (time to live) for this message has expired, based |
87 // on the |sent| timestamps and base::TimeTicks::Now(). If |protobuf| is not | 87 // on the |sent| timestamps and base::TimeTicks::Now(). If |protobuf| is not |
88 // for a DataMessageStanza or the TTL is 0, will return false. | 88 // for a DataMessageStanza or the TTL is 0, will return false. |
89 GCM_EXPORT bool HasTTLExpired(const google::protobuf::MessageLite& protobuf, | 89 GCM_EXPORT bool HasTTLExpired(const google::protobuf::MessageLite& protobuf, |
90 base::Clock* clock); | 90 base::Clock* clock); |
91 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf); | 91 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf); |
92 | 92 |
93 // Returns whether the message was sent with an immediate ack request. | 93 // Returns whether the message was sent with an immediate ack request. |
94 GCM_EXPORT bool IsImmediateAckRequested( | 94 GCM_EXPORT bool IsImmediateAckRequested( |
95 const google::protobuf::MessageLite& protobuf); | 95 const google::protobuf::MessageLite& protobuf); |
96 | 96 |
97 } // namespace gcm | 97 } // namespace gcm |
98 | 98 |
99 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ | 99 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ |
OLD | NEW |