| 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_CORE_MODEL_TYPE_STORE_IMPL_H_ | 5 #ifndef COMPONENTS_SYNC_CORE_MODEL_TYPE_STORE_IMPL_H_ |
| 6 #define COMPONENTS_SYNC_CORE_MODEL_TYPE_STORE_IMPL_H_ | 6 #define COMPONENTS_SYNC_CORE_MODEL_TYPE_STORE_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "components/sync/api/model_type_store.h" | 14 #include "components/sync/api/model_type_store.h" |
| 15 #include "components/sync/base/model_type.h" | 15 #include "components/sync/base/model_type.h" |
| 16 | 16 |
| 17 namespace leveldb { | 17 namespace leveldb { |
| 18 class WriteBatch; | 18 class WriteBatch; |
| 19 } // namespace leveldb | 19 } // namespace leveldb |
| 20 | 20 |
| 21 namespace syncer_v2 { | 21 namespace syncer { |
| 22 | 22 |
| 23 class ModelTypeStoreBackend; | 23 class ModelTypeStoreBackend; |
| 24 | 24 |
| 25 // ModelTypeStoreImpl handles details of store initialization, threading and | 25 // ModelTypeStoreImpl handles details of store initialization, threading and |
| 26 // leveldb key formatting. Actual leveldb IO calls are performed by | 26 // leveldb key formatting. Actual leveldb IO calls are performed by |
| 27 // ModelTypeStoreBackend. | 27 // ModelTypeStoreBackend. |
| 28 class ModelTypeStoreImpl : public ModelTypeStore, public base::NonThreadSafe { | 28 class ModelTypeStoreImpl : public ModelTypeStore, public base::NonThreadSafe { |
| 29 public: | 29 public: |
| 30 ~ModelTypeStoreImpl() override; | 30 ~ModelTypeStoreImpl() override; |
| 31 | 31 |
| 32 static void CreateStore( | 32 static void CreateStore( |
| 33 const syncer::ModelType type, | 33 const ModelType type, |
| 34 const std::string& path, | 34 const std::string& path, |
| 35 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 35 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
| 36 const InitCallback& callback); | 36 const InitCallback& callback); |
| 37 static void CreateInMemoryStoreForTest(const InitCallback& callback); | 37 static void CreateInMemoryStoreForTest(const InitCallback& callback); |
| 38 | 38 |
| 39 // ModelTypeStore implementation. | 39 // ModelTypeStore implementation. |
| 40 void ReadData(const IdList& id_list, | 40 void ReadData(const IdList& id_list, |
| 41 const ReadDataCallback& callback) override; | 41 const ReadDataCallback& callback) override; |
| 42 void ReadAllData(const ReadAllDataCallback& callback) override; | 42 void ReadAllData(const ReadAllDataCallback& callback) override; |
| 43 void ReadAllMetadata(const ReadMetadataCallback& callback) override; | 43 void ReadAllMetadata(const ReadMetadataCallback& callback) override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 class WriteBatchImpl : public WriteBatch { | 60 class WriteBatchImpl : public WriteBatch { |
| 61 public: | 61 public: |
| 62 WriteBatchImpl(); | 62 WriteBatchImpl(); |
| 63 ~WriteBatchImpl() override; | 63 ~WriteBatchImpl() override; |
| 64 std::unique_ptr<leveldb::WriteBatch> leveldb_write_batch_; | 64 std::unique_ptr<leveldb::WriteBatch> leveldb_write_batch_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 static void BackendInitDone( | 67 static void BackendInitDone( |
| 68 const syncer::ModelType type, | 68 const ModelType type, |
| 69 std::unique_ptr<Result> result, | 69 std::unique_ptr<Result> result, |
| 70 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 70 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
| 71 const InitCallback& callback, | 71 const InitCallback& callback, |
| 72 scoped_refptr<ModelTypeStoreBackend> backend); | 72 scoped_refptr<ModelTypeStoreBackend> backend); |
| 73 | 73 |
| 74 // Format prefix key for data/metadata records with |type|. | 74 // Format prefix key for data/metadata records with |type|. |
| 75 static std::string FormatDataPrefix(const syncer::ModelType type); | 75 static std::string FormatDataPrefix(const ModelType type); |
| 76 static std::string FormatMetaPrefix(const syncer::ModelType type); | 76 static std::string FormatMetaPrefix(const ModelType type); |
| 77 | 77 |
| 78 static leveldb::WriteBatch* GetLeveldbWriteBatch(WriteBatch* write_batch); | 78 static leveldb::WriteBatch* GetLeveldbWriteBatch(WriteBatch* write_batch); |
| 79 | 79 |
| 80 // Format key for data/metadata records with given id. | 80 // Format key for data/metadata records with given id. |
| 81 std::string FormatDataKey(const std::string& id); | 81 std::string FormatDataKey(const std::string& id); |
| 82 std::string FormatMetadataKey(const std::string& id); | 82 std::string FormatMetadataKey(const std::string& id); |
| 83 | 83 |
| 84 ModelTypeStoreImpl( | 84 ModelTypeStoreImpl( |
| 85 const syncer::ModelType type, | 85 const ModelType type, |
| 86 scoped_refptr<ModelTypeStoreBackend> backend, | 86 scoped_refptr<ModelTypeStoreBackend> backend, |
| 87 scoped_refptr<base::SequencedTaskRunner> backend_task_runner); | 87 scoped_refptr<base::SequencedTaskRunner> backend_task_runner); |
| 88 | 88 |
| 89 // Callbacks for different calls to ModelTypeStoreBackend. | 89 // Callbacks for different calls to ModelTypeStoreBackend. |
| 90 void ReadDataDone(const ReadDataCallback& callback, | 90 void ReadDataDone(const ReadDataCallback& callback, |
| 91 std::unique_ptr<RecordList> record_list, | 91 std::unique_ptr<RecordList> record_list, |
| 92 std::unique_ptr<IdList> missing_id_list, | 92 std::unique_ptr<IdList> missing_id_list, |
| 93 Result result); | 93 Result result); |
| 94 void ReadAllDataDone(const ReadAllDataCallback& callback, | 94 void ReadAllDataDone(const ReadAllDataCallback& callback, |
| 95 std::unique_ptr<RecordList> record_list, | 95 std::unique_ptr<RecordList> record_list, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 111 scoped_refptr<ModelTypeStoreBackend> backend_; | 111 scoped_refptr<ModelTypeStoreBackend> backend_; |
| 112 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; | 112 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 113 | 113 |
| 114 // Key prefix for data/metadata records of this model type. | 114 // Key prefix for data/metadata records of this model type. |
| 115 const std::string data_prefix_; | 115 const std::string data_prefix_; |
| 116 const std::string metadata_prefix_; | 116 const std::string metadata_prefix_; |
| 117 | 117 |
| 118 base::WeakPtrFactory<ModelTypeStoreImpl> weak_ptr_factory_; | 118 base::WeakPtrFactory<ModelTypeStoreImpl> weak_ptr_factory_; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 } // namespace syncer_v2 | 121 } // namespace syncer |
| 122 | 122 |
| 123 #endif // COMPONENTS_SYNC_CORE_MODEL_TYPE_STORE_IMPL_H_ | 123 #endif // COMPONENTS_SYNC_CORE_MODEL_TYPE_STORE_IMPL_H_ |
| OLD | NEW |