| 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_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_H_ |
| 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "sync/api/attachments/attachment_id.h" | 15 #include "sync/api/attachments/attachment_id.h" |
| 17 #include "sync/base/sync_export.h" | 16 #include "sync/base/sync_export.h" |
| 18 | 17 |
| 19 namespace syncer { | 18 namespace syncer { |
| 20 | 19 |
| 21 // A blob of in-memory data attached to a sync item. | 20 // A blob of in-memory data attached to a sync item. |
| 22 // | 21 // |
| 23 // While Attachment objects themselves aren't immutable (they are assignable) | 22 // While Attachment objects themselves aren't immutable (they are assignable) |
| 24 // the data they wrap is immutable. | 23 // the data they wrap is immutable. |
| 25 // | 24 // |
| 26 // It is cheap to copy Attachments. Feel free to store and return by value. | 25 // It is cheap to copy Attachments. Feel free to store and return by value. |
| 27 class SYNC_EXPORT Attachment { | 26 class SYNC_EXPORT Attachment { |
| 28 public: | 27 public: |
| 29 ~Attachment(); | 28 ~Attachment(); |
| 30 | 29 |
| 31 // Default copy and assignment are welcome. | 30 // Default copy and assignment are welcome. |
| 32 | 31 |
| 33 // Creates an attachment with a unique id and the supplied data. | 32 // Creates an attachment with a unique id and the supplied data. |
| 34 // | 33 // |
| 35 // Used when creating a brand new attachment. | 34 // Used when creating a brand new attachment. |
| 36 static scoped_ptr<Attachment> Create( | 35 static Attachment Create(const scoped_refptr<base::RefCountedMemory>& data); |
| 37 const scoped_refptr<base::RefCountedMemory>& data); | |
| 38 | 36 |
| 39 // Creates an attachment with the supplied id and data. | 37 // Creates an attachment with the supplied id and data. |
| 40 // | 38 // |
| 41 // Used when you want to recreate a specific attachment. E.g. creating a local | 39 // Used when you want to recreate a specific attachment. E.g. creating a local |
| 42 // copy of an attachment that already exists on the sync server. | 40 // copy of an attachment that already exists on the sync server. |
| 43 static scoped_ptr<Attachment> CreateWithId( | 41 static Attachment CreateWithId( |
| 44 const AttachmentId& id, | 42 const AttachmentId& id, |
| 45 const scoped_refptr<base::RefCountedMemory>& data); | 43 const scoped_refptr<base::RefCountedMemory>& data); |
| 46 | 44 |
| 47 // Returns this attachment's id. | 45 // Returns this attachment's id. |
| 48 const AttachmentId& GetId() const; | 46 const AttachmentId& GetId() const; |
| 49 | 47 |
| 50 // Returns this attachment's data. | 48 // Returns this attachment's data. |
| 51 const scoped_refptr<base::RefCountedMemory>& GetData() const; | 49 const scoped_refptr<base::RefCountedMemory>& GetData() const; |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 AttachmentId id_; | 52 AttachmentId id_; |
| 55 scoped_refptr<base::RefCountedMemory> data_; | 53 scoped_refptr<base::RefCountedMemory> data_; |
| 56 | 54 |
| 57 friend class AttachmentTest; | |
| 58 FRIEND_TEST_ALL_PREFIXES(AttachmentTest, CreateId_UniqueIdIsUnique); | |
| 59 | |
| 60 Attachment(const AttachmentId& id, | 55 Attachment(const AttachmentId& id, |
| 61 const scoped_refptr<base::RefCountedMemory>& data); | 56 const scoped_refptr<base::RefCountedMemory>& data); |
| 62 }; | 57 }; |
| 63 | 58 |
| 64 typedef std::vector<syncer::Attachment> AttachmentList; | 59 typedef std::vector<syncer::Attachment> AttachmentList; |
| 65 typedef std::map<AttachmentId, Attachment> AttachmentMap; | 60 typedef std::map<AttachmentId, Attachment> AttachmentMap; |
| 66 | 61 |
| 67 } // namespace syncer | 62 } // namespace syncer |
| 68 | 63 |
| 69 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_H_ | 64 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_H_ |
| OLD | NEW |