| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "sync/base/sync_export.h" | 11 #include "sync/base/sync_export.h" |
| 12 #include "sync/internal_api/public/util/immutable.h" |
| 13 |
| 14 namespace sync_pb { |
| 15 class AttachmentIdProto; |
| 16 } // namespace sync_pb |
| 12 | 17 |
| 13 namespace syncer { | 18 namespace syncer { |
| 14 | 19 |
| 15 // Uniquely identifies an attachment. | 20 // Uniquely identifies an attachment. |
| 16 // | 21 // |
| 17 // Two attachments with equal (operator==) AttachmentIds are considered | 22 // Two attachments with equal (operator==) AttachmentIds are considered |
| 18 // equivalent. | 23 // equivalent. |
| 19 class SYNC_EXPORT AttachmentId { | 24 class SYNC_EXPORT AttachmentId { |
| 20 public: | 25 public: |
| 21 ~AttachmentId(); | 26 ~AttachmentId(); |
| 22 | 27 |
| 23 // Default copy and assignment are welcome. | 28 // Default copy and assignment are welcome. |
| 24 | 29 |
| 25 bool operator==(const AttachmentId& other) const; | 30 bool operator==(const AttachmentId& other) const; |
| 26 | 31 |
| 27 bool operator!=(const AttachmentId& other) const; | 32 bool operator!=(const AttachmentId& other) const; |
| 28 | 33 |
| 29 // Needed for using AttachmentId as key in std::map. | 34 // Needed for using AttachmentId as key in std::map. |
| 30 bool operator<(const AttachmentId& other) const; | 35 bool operator<(const AttachmentId& other) const; |
| 31 | 36 |
| 32 | |
| 33 // Creates a unique attachment id. | 37 // Creates a unique attachment id. |
| 34 static AttachmentId Create(); | 38 static AttachmentId Create(); |
| 35 | 39 |
| 40 // Creates an attachment id from an initialized proto. |
| 41 static AttachmentId CreateFromProto(const sync_pb::AttachmentIdProto& proto); |
| 42 |
| 43 const sync_pb::AttachmentIdProto& GetProto() const; |
| 44 |
| 36 private: | 45 private: |
| 37 std::string unique_id_; | 46 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments |
| 47 // in immutable.h. |
| 48 struct ImmutableAttachmentIdProtoTraits { |
| 49 typedef sync_pb::AttachmentIdProto* Wrapper; |
| 50 static void InitializeWrapper(Wrapper* wrapper); |
| 51 static void DestroyWrapper(Wrapper* wrapper); |
| 52 static const sync_pb::AttachmentIdProto& Unwrap(const Wrapper& wrapper); |
| 53 static sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper* wrapper); |
| 54 static void Swap(sync_pb::AttachmentIdProto* t1, |
| 55 sync_pb::AttachmentIdProto* t2); |
| 56 }; |
| 38 | 57 |
| 39 AttachmentId(const std::string& unique_id); | 58 typedef Immutable<sync_pb::AttachmentIdProto, |
| 59 ImmutableAttachmentIdProtoTraits> |
| 60 ImmutableAttachmentIdProto; |
| 61 |
| 62 ImmutableAttachmentIdProto proto_; |
| 63 |
| 64 AttachmentId(sync_pb::AttachmentIdProto* proto); |
| 40 }; | 65 }; |
| 41 | 66 |
| 42 typedef std::vector<AttachmentId> AttachmentIdList; | 67 typedef std::vector<AttachmentId> AttachmentIdList; |
| 43 | 68 |
| 44 } // namespace syncer | 69 } // namespace syncer |
| 45 | 70 |
| 46 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 71 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| OLD | NEW |