| 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> |
| 11 |
| 10 #include <string> | 12 #include <string> |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "google_apis/gcm/base/gcm_export.h" | 17 #include "google_apis/gcm/base/gcm_export.h" |
| 17 #include "google_apis/gcm/protocol/mcs.pb.h" | 18 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class Clock; | 21 class Clock; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace net { | 24 namespace net { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 kNumProtoTypes, | 50 kNumProtoTypes, |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 enum MCSIqStanzaExtension { | 53 enum MCSIqStanzaExtension { |
| 53 kSelectiveAck = 12, | 54 kSelectiveAck = 12, |
| 54 kStreamAck = 13, | 55 kStreamAck = 13, |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Builds a LoginRequest with the hardcoded local data. | 58 // Builds a LoginRequest with the hardcoded local data. |
| 58 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest( | 59 GCM_EXPORT scoped_ptr<mcs_proto::LoginRequest> BuildLoginRequest( |
| 59 uint64 auth_id, | 60 uint64_t auth_id, |
| 60 uint64 auth_token, | 61 uint64_t auth_token, |
| 61 const std::string& version_string); | 62 const std::string& version_string); |
| 62 | 63 |
| 63 // Builds a StreamAck IqStanza message. | 64 // Builds a StreamAck IqStanza message. |
| 64 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck(); | 65 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildStreamAck(); |
| 65 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildSelectiveAck( | 66 GCM_EXPORT scoped_ptr<mcs_proto::IqStanza> BuildSelectiveAck( |
| 66 const std::vector<std::string>& acked_ids); | 67 const std::vector<std::string>& acked_ids); |
| 67 | 68 |
| 68 // Utility methods for building and identifying MCS protobufs. | 69 // Utility methods for building and identifying MCS protobufs. |
| 69 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite> | 70 GCM_EXPORT scoped_ptr<google::protobuf::MessageLite> BuildProtobufFromTag( |
| 70 BuildProtobufFromTag(uint8 tag); | 71 uint8_t tag); |
| 71 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message); | 72 GCM_EXPORT int GetMCSProtoTag(const google::protobuf::MessageLite& message); |
| 72 | 73 |
| 73 // RMQ utility methods for extracting/setting common data from/to protobufs. | 74 // RMQ utility methods for extracting/setting common data from/to protobufs. |
| 74 GCM_EXPORT std::string GetPersistentId( | 75 GCM_EXPORT std::string GetPersistentId( |
| 75 const google::protobuf::MessageLite& message); | 76 const google::protobuf::MessageLite& message); |
| 76 GCM_EXPORT void SetPersistentId( | 77 GCM_EXPORT void SetPersistentId( |
| 77 const std::string& persistent_id, | 78 const std::string& persistent_id, |
| 78 google::protobuf::MessageLite* message); | 79 google::protobuf::MessageLite* message); |
| 79 GCM_EXPORT uint32 GetLastStreamIdReceived( | 80 GCM_EXPORT uint32_t |
| 80 const google::protobuf::MessageLite& protobuf); | 81 GetLastStreamIdReceived(const google::protobuf::MessageLite& protobuf); |
| 81 GCM_EXPORT void SetLastStreamIdReceived( | 82 GCM_EXPORT void SetLastStreamIdReceived( |
| 82 uint32 last_stream_id_received, | 83 uint32_t last_stream_id_received, |
| 83 google::protobuf::MessageLite* protobuf); | 84 google::protobuf::MessageLite* protobuf); |
| 84 | 85 |
| 85 // 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 |
| 86 // 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 |
| 87 // for a DataMessageStanza or the TTL is 0, will return false. | 88 // for a DataMessageStanza or the TTL is 0, will return false. |
| 88 GCM_EXPORT bool HasTTLExpired(const google::protobuf::MessageLite& protobuf, | 89 GCM_EXPORT bool HasTTLExpired(const google::protobuf::MessageLite& protobuf, |
| 89 base::Clock* clock); | 90 base::Clock* clock); |
| 90 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf); | 91 GCM_EXPORT int GetTTL(const google::protobuf::MessageLite& protobuf); |
| 91 | 92 |
| 92 // Returns whether the message was sent with an immediate ack request. | 93 // Returns whether the message was sent with an immediate ack request. |
| 93 GCM_EXPORT bool IsImmediateAckRequested( | 94 GCM_EXPORT bool IsImmediateAckRequested( |
| 94 const google::protobuf::MessageLite& protobuf); | 95 const google::protobuf::MessageLite& protobuf); |
| 95 | 96 |
| 96 } // namespace gcm | 97 } // namespace gcm |
| 97 | 98 |
| 98 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ | 99 #endif // GOOGLE_APIS_GCM_BASE_MCS_UTIL_H_ |
| OLD | NEW |