// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_SYNC_MODEL_DATA_TYPE_STORE_H_ #define COMPONENTS_SYNC_MODEL_DATA_TYPE_STORE_H_ #include <memory> #include <optional> #include "base/functional/callback.h" #include "components/sync/base/data_type.h" #include "components/sync/model/data_type_store_base.h" #include "components/sync/model/model_error.h" namespace syncer { class MetadataBatch; // DataTypeStore is leveldb backed store for data type's data, metadata and // global metadata. // // Store keeps records for entries identified by ids. For each entry store keeps // data and metadata. Also store keeps one record for global metadata. // // To create store call one of Create*Store static factory functions. Data type // controls store's lifetime with returned unique_ptr. Call to Create*Store // function triggers asynchronous store backend initialization, callback will be // called with results when initialization is done. // // Read operations are asynchronous, initiated with one of Read* functions, // provided callback will be called with result code and output of read // operation. // // Write operations are done in context of write batch. To get one call // CreateWriteBatch(). After that pass write batch object to Write/Delete // functions. WriteBatch only accumulates pending changes, doesn't actually do // data modification. Calling CommitWriteBatch writes all accumulated changes to // disk atomically. Callback passed to CommitWriteBatch will be called with // result of write operation. If write batch object is destroyed without // comitting accumulated write operations will not be persisted. // // Destroying store object doesn't necessarily cancel asynchronous operations // issued previously. You should be prepared to handle callbacks from those // operations. class DataTypeStore : public DataTypeStoreBase { … }; // Typedef for a store factory that has all params bound except InitCallback. RepeatingDataTypeStoreFactory; // Same as above but as a OnceCallback. OnceDataTypeStoreFactory; } // namespace syncer #endif // COMPONENTS_SYNC_MODEL_DATA_TYPE_STORE_H_