| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ | 5 #ifndef COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ |
| 6 #define COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ | 6 #define COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/optional.h" | 14 #include "base/optional.h" |
| 15 #include "components/sync/base/model_type.h" | 15 #include "components/sync/base/model_type.h" |
| 16 #include "components/sync/model/metadata_batch.h" | 16 #include "components/sync/model/metadata_batch.h" |
| 17 #include "components/sync/model/metadata_change_list.h" | 17 #include "components/sync/model/metadata_change_list.h" |
| 18 #include "components/sync/model/model_error.h" | 18 #include "components/sync/model/model_error.h" |
| 19 | 19 |
| 20 namespace base { | |
| 21 class SequencedTaskRunner; | |
| 22 } // namespace base | |
| 23 | |
| 24 namespace syncer { | 20 namespace syncer { |
| 25 | 21 |
| 26 // ModelTypeStore is leveldb backed store for model type's data, metadata and | 22 // ModelTypeStore is leveldb backed store for model type's data, metadata and |
| 27 // global metadata. | 23 // global metadata. |
| 28 // | 24 // |
| 29 // Store keeps records for entries identified by ids. For each entry store keeps | 25 // Store keeps records for entries identified by ids. For each entry store keeps |
| 30 // data and metadata. Also store keeps one record for global metadata. | 26 // data and metadata. Also store keeps one record for global metadata. |
| 31 // | 27 // |
| 32 // To create store call one of Create*Store static factory functions. Model type | 28 // To create store call one of Create*Store static factory functions. Model type |
| 33 // controls store's lifetime with returned unique_ptr. Call to Create*Store | 29 // controls store's lifetime with returned unique_ptr. Call to Create*Store |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 base::Callback<void(Result result, | 113 base::Callback<void(Result result, |
| 118 std::unique_ptr<RecordList> data_records, | 114 std::unique_ptr<RecordList> data_records, |
| 119 std::unique_ptr<IdList> missing_id_list)>; | 115 std::unique_ptr<IdList> missing_id_list)>; |
| 120 using ReadAllDataCallback = | 116 using ReadAllDataCallback = |
| 121 base::Callback<void(Result result, | 117 base::Callback<void(Result result, |
| 122 std::unique_ptr<RecordList> data_records)>; | 118 std::unique_ptr<RecordList> data_records)>; |
| 123 using ReadMetadataCallback = | 119 using ReadMetadataCallback = |
| 124 base::Callback<void(base::Optional<ModelError> error, | 120 base::Callback<void(base::Optional<ModelError> error, |
| 125 std::unique_ptr<MetadataBatch> metadata_batch)>; | 121 std::unique_ptr<MetadataBatch> metadata_batch)>; |
| 126 | 122 |
| 127 // CreateStore takes |path| and |blocking_task_runner|. Here is how to get | 123 // CreateStore takes |path|, and will run blocking calls on a task runner |
| 128 // task runner in production code: | 124 // scoped to the given path. Tests likely don't want to use this method. |
| 129 // | |
| 130 // base::SequencedWorkerPool* worker_pool = | |
| 131 // content::BrowserThread::GetBlockingPool(); | |
| 132 // scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | |
| 133 // worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 134 // worker_pool->GetNamedSequenceToken(path), | |
| 135 // base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 136 // | |
| 137 // In test get task runner from MessageLoop::task_runner(). | |
| 138 static void CreateStore( | 125 static void CreateStore( |
| 139 ModelType type, | 126 ModelType type, |
| 140 const std::string& path, | 127 const std::string& path, |
| 141 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | |
| 142 const InitCallback& callback); | 128 const InitCallback& callback); |
| 143 // Creates store object backed by in-memory leveldb database. It is used in | 129 // Creates store object backed by in-memory leveldb database, gets its task |
| 144 // tests. | 130 // runner from MessageLoop::task_runner(), and should only be used in tests. |
| 145 static void CreateInMemoryStoreForTest(ModelType type, | 131 static void CreateInMemoryStoreForTest(ModelType type, |
| 146 const InitCallback& callback); | 132 const InitCallback& callback); |
| 147 | 133 |
| 148 virtual ~ModelTypeStore(); | 134 virtual ~ModelTypeStore(); |
| 149 | 135 |
| 150 // Read operations return records either for all entries or only for ones | 136 // Read operations return records either for all entries or only for ones |
| 151 // identified in |id_list|. Result is SUCCESS if all records were read | 137 // identified in |id_list|. Result is SUCCESS if all records were read |
| 152 // successfully. If reading any of records fails result is UNSPECIFIED_ERROR | 138 // successfully. If reading any of records fails result is UNSPECIFIED_ERROR |
| 153 // and RecordList contains some records that were read successfully. There is | 139 // and RecordList contains some records that were read successfully. There is |
| 154 // no guarantee that RecordList will contain all successfully read records in | 140 // no guarantee that RecordList will contain all successfully read records in |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // It will delete all metadata records and global metadata record. | 181 // It will delete all metadata records and global metadata record. |
| 196 }; | 182 }; |
| 197 | 183 |
| 198 // Typedef for a store factory that has all params bound except InitCallback. | 184 // Typedef for a store factory that has all params bound except InitCallback. |
| 199 using ModelTypeStoreFactory = | 185 using ModelTypeStoreFactory = |
| 200 base::Callback<void(const ModelTypeStore::InitCallback&)>; | 186 base::Callback<void(const ModelTypeStore::InitCallback&)>; |
| 201 | 187 |
| 202 } // namespace syncer | 188 } // namespace syncer |
| 203 | 189 |
| 204 #endif // COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ | 190 #endif // COMPONENTS_SYNC_MODEL_MODEL_TYPE_STORE_H_ |
| OLD | NEW |