| 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_STORE_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
| 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "sync/api/attachments/attachment.h" | 13 #include "sync/api/attachments/attachment.h" |
| 13 #include "sync/api/attachments/attachment_id.h" | 14 #include "sync/api/attachments/attachment_id.h" |
| 14 #include "sync/api/attachments/attachment_metadata.h" | 15 #include "sync/api/attachments/attachment_metadata.h" |
| 15 #include "sync/base/sync_export.h" | 16 #include "sync/base/sync_export.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class FilePath; | 19 class FilePath; |
| 19 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 20 } // namespace base | 21 } // namespace base |
| 21 | 22 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 // Each attachment can have references from sync or model type. Tracking these | 53 // Each attachment can have references from sync or model type. Tracking these |
| 53 // references is needed for lifetime management of attachment, it can only be | 54 // references is needed for lifetime management of attachment, it can only be |
| 54 // deleted from the store when it doesn't have references. | 55 // deleted from the store when it doesn't have references. |
| 55 enum Component { | 56 enum Component { |
| 56 MODEL_TYPE, | 57 MODEL_TYPE, |
| 57 SYNC, | 58 SYNC, |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 typedef base::Callback<void(const Result&)> InitCallback; | 61 typedef base::Callback<void(const Result&)> InitCallback; |
| 61 typedef base::Callback<void(const Result&, | 62 typedef base::Callback<void(const Result&, |
| 62 scoped_ptr<AttachmentMap>, | 63 std::unique_ptr<AttachmentMap>, |
| 63 scoped_ptr<AttachmentIdList>)> ReadCallback; | 64 std::unique_ptr<AttachmentIdList>)> |
| 65 ReadCallback; |
| 64 typedef base::Callback<void(const Result&)> WriteCallback; | 66 typedef base::Callback<void(const Result&)> WriteCallback; |
| 65 typedef base::Callback<void(const Result&)> DropCallback; | 67 typedef base::Callback<void(const Result&)> DropCallback; |
| 66 typedef base::Callback<void(const Result&, | 68 typedef base::Callback<void(const Result&, |
| 67 scoped_ptr<AttachmentMetadataList>)> | 69 std::unique_ptr<AttachmentMetadataList>)> |
| 68 ReadMetadataCallback; | 70 ReadMetadataCallback; |
| 69 | 71 |
| 70 ~AttachmentStore(); | 72 ~AttachmentStore(); |
| 71 | 73 |
| 72 // Asynchronously reads the attachments identified by |ids|. | 74 // Asynchronously reads the attachments identified by |ids|. |
| 73 // | 75 // |
| 74 // |callback| will be invoked when finished. AttachmentStore will attempt to | 76 // |callback| will be invoked when finished. AttachmentStore will attempt to |
| 75 // read all attachments specified in ids. If any of the attachments do not | 77 // read all attachments specified in ids. If any of the attachments do not |
| 76 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. | 78 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. |
| 77 // Callback's AttachmentMap will contain all attachments that were | 79 // Callback's AttachmentMap will contain all attachments that were |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // Asynchronously reads metadata for all attachments with |component_| | 119 // Asynchronously reads metadata for all attachments with |component_| |
| 118 // reference in the store. | 120 // reference in the store. |
| 119 // | 121 // |
| 120 // |callback| will be invoked when finished. If any of the metadata entries | 122 // |callback| will be invoked when finished. If any of the metadata entries |
| 121 // could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. | 123 // could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. |
| 122 void ReadMetadata(const ReadMetadataCallback& callback); | 124 void ReadMetadata(const ReadMetadataCallback& callback); |
| 123 | 125 |
| 124 // Given current AttachmentStore (this) creates separate AttachmentStore that | 126 // Given current AttachmentStore (this) creates separate AttachmentStore that |
| 125 // will be used by sync components (AttachmentService). Resulting | 127 // will be used by sync components (AttachmentService). Resulting |
| 126 // AttachmentStore is backed by the same frontend/backend. | 128 // AttachmentStore is backed by the same frontend/backend. |
| 127 scoped_ptr<AttachmentStoreForSync> CreateAttachmentStoreForSync() const; | 129 std::unique_ptr<AttachmentStoreForSync> CreateAttachmentStoreForSync() const; |
| 128 | 130 |
| 129 // Creates an AttachmentStore backed by in-memory implementation of attachment | 131 // Creates an AttachmentStore backed by in-memory implementation of attachment |
| 130 // store. For now frontend lives on the same thread as backend. | 132 // store. For now frontend lives on the same thread as backend. |
| 131 static scoped_ptr<AttachmentStore> CreateInMemoryStore(); | 133 static std::unique_ptr<AttachmentStore> CreateInMemoryStore(); |
| 132 | 134 |
| 133 // Creates an AttachmentStore backed by on-disk implementation of attachment | 135 // Creates an AttachmentStore backed by on-disk implementation of attachment |
| 134 // store. Opens corresponding leveldb database located at |path|. All backend | 136 // store. Opens corresponding leveldb database located at |path|. All backend |
| 135 // operations are scheduled to |backend_task_runner|. Opening attachment store | 137 // operations are scheduled to |backend_task_runner|. Opening attachment store |
| 136 // is asynchronous, once it finishes |callback| will be called on the thread | 138 // is asynchronous, once it finishes |callback| will be called on the thread |
| 137 // that called CreateOnDiskStore. Calling Read/Write/Drop before | 139 // that called CreateOnDiskStore. Calling Read/Write/Drop before |
| 138 // initialization completed is allowed. Later if initialization fails these | 140 // initialization completed is allowed. Later if initialization fails these |
| 139 // operations will fail with STORE_INITIALIZATION_FAILED error. | 141 // operations will fail with STORE_INITIALIZATION_FAILED error. |
| 140 static scoped_ptr<AttachmentStore> CreateOnDiskStore( | 142 static std::unique_ptr<AttachmentStore> CreateOnDiskStore( |
| 141 const base::FilePath& path, | 143 const base::FilePath& path, |
| 142 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, | 144 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, |
| 143 const InitCallback& callback); | 145 const InitCallback& callback); |
| 144 | 146 |
| 145 // Creates set of AttachmentStore/AttachmentStoreFrontend instances for tests | 147 // Creates set of AttachmentStore/AttachmentStoreFrontend instances for tests |
| 146 // that provide their own implementation of AttachmentstoreBackend for | 148 // that provide their own implementation of AttachmentstoreBackend for |
| 147 // mocking. | 149 // mocking. |
| 148 static scoped_ptr<AttachmentStore> CreateMockStoreForTest( | 150 static std::unique_ptr<AttachmentStore> CreateMockStoreForTest( |
| 149 scoped_ptr<AttachmentStoreBackend> backend); | 151 std::unique_ptr<AttachmentStoreBackend> backend); |
| 150 | 152 |
| 151 protected: | 153 protected: |
| 152 AttachmentStore(const scoped_refptr<AttachmentStoreFrontend>& frontend, | 154 AttachmentStore(const scoped_refptr<AttachmentStoreFrontend>& frontend, |
| 153 Component component); | 155 Component component); |
| 154 | 156 |
| 155 const scoped_refptr<AttachmentStoreFrontend>& frontend() { return frontend_; } | 157 const scoped_refptr<AttachmentStoreFrontend>& frontend() { return frontend_; } |
| 156 Component component() const { return component_; } | 158 Component component() const { return component_; } |
| 157 | 159 |
| 158 private: | 160 private: |
| 159 scoped_refptr<AttachmentStoreFrontend> frontend_; | 161 scoped_refptr<AttachmentStoreFrontend> frontend_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // |sync_component_| is passed to frontend when sync related operations are | 202 // |sync_component_| is passed to frontend when sync related operations are |
| 201 // perfromed. | 203 // perfromed. |
| 202 const Component sync_component_; | 204 const Component sync_component_; |
| 203 | 205 |
| 204 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreForSync); | 206 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreForSync); |
| 205 }; | 207 }; |
| 206 | 208 |
| 207 } // namespace syncer | 209 } // namespace syncer |
| 208 | 210 |
| 209 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 211 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
| OLD | NEW |