Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: ios/chrome/browser/reading_list/reading_list_store.h

Issue 2398233003: with sync (Closed)
Patch Set: done Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/reading_list/reading_list_store.h
diff --git a/ios/chrome/browser/reading_list/reading_list_store.h b/ios/chrome/browser/reading_list/reading_list_store.h
index da2636719eee7cdf272c1b92c7cf3a1cd361c01c..2f6bff60d30860ed558cb66bfe339d00f8b179df 100644
--- a/ios/chrome/browser/reading_list/reading_list_store.h
+++ b/ios/chrome/browser/reading_list/reading_list_store.h
@@ -5,21 +5,32 @@
#ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
#define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
-#include "base/memory/weak_ptr.h"
#include "components/leveldb_proto/proto_database.h"
+#include "components/sync/api/model_type_service.h"
+#include "components/sync/api/model_type_store.h"
#include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
using ReadingListDB =
leveldb_proto::ProtoDatabase<reading_list::ReadingListLocal>;
+namespace syncer {
+class ModelTypeService;
+}
+
+typedef base::Callback<void(
+ const syncer::ModelTypeStore::InitCallback& callback)>
+ StoreFactoryFunction;
+
// A ReadingListModelStorage storing data in protobufs.
-class ReadingListStore : public ReadingListModelStorage {
+class ReadingListStore : public ReadingListModelStorage,
+ public syncer::ModelTypeService {
using EntryVector = std::vector<reading_list::ReadingListLocal>;
public:
ReadingListStore(std::unique_ptr<ReadingListDB> database,
- const base::FilePath& database_dir);
- virtual ~ReadingListStore();
+ const base::FilePath& database_dir,
+ StoreFactoryFunction create_store_callback);
+ ~ReadingListStore() override;
// ReadingListModelStorage implementation
void SetReadingListModel(ReadingListModelImpl* model) override;
@@ -29,20 +40,95 @@ class ReadingListStore : public ReadingListModelStorage {
void SaveEntry(const ReadingListEntry& entry, bool read) override;
void RemoveEntry(const ReadingListEntry& entry) override;
+ // ReadingListModelStorage implementation.
+ syncer::ModelTypeService* GetModelTypeService() override;
+
+ // Creates an object used to communicate changes in the sync metadata to the
+ // model type store.
+ std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
+ override;
+
+ // Perform the initial merge between local and sync data. This should only be
+ // called when a data type is first enabled to start syncing, and there is no
+ // sync metadata. Best effort should be made to match local and sync data. The
+ // keys in the |entity_data_map| will have been created via GetClientTag(...),
+ // and if a local and sync data should match/merge but disagree on tags, the
+ // service should use the sync data's tag. Any local pieces of data that are
+ // not present in sync should immediately be Put(...) to the processor before
+ // returning. The same MetadataChangeList that was passed into this function
+ // can be passed to Put(...) calls. Delete(...) can also be called but should
+ // not be needed for most model types. Durable storage writes, if not able to
+ // combine all change atomically, should save the metadata after the data
+ // changes, so that this merge will be re-driven by sync if is not completely
+ // saved during the current run.
+ syncer::SyncError MergeSyncData(
+ std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
+ syncer::EntityDataMap entity_data_map) override;
+
+ // Apply changes from the sync server locally.
+ // Please note that |entity_changes| might have fewer entries than
+ // |metadata_change_list| in case when some of the data changes are filtered
+ // out, or even be empty in case when a commit confirmation is processed and
+ // only the metadata needs to persisted.
+ syncer::SyncError ApplySyncChanges(
+ std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
+ syncer::EntityChangeList entity_changes) override;
+
+ // Asynchronously retrieve the corresponding sync data for |storage_keys|.
+ void GetData(StorageKeyList storage_keys, DataCallback callback) override;
+
+ // Asynchronously retrieve all of the local sync data.
+ void GetAllData(DataCallback callback) override;
+
+ // Get or generate a client tag for |entity_data|. This must be the same tag
+ // that was/would have been generated in the SyncableService/Directory world
+ // for backward compatibility with pre-USS clients. The only time this
+ // theoretically needs to be called is on the creation of local data, however
+ // it is also used to verify the hash of remote data. If a data type was never
+ // launched pre-USS, then method does not need to be different from
+ // GetStorageKey().
+ std::string GetClientTag(const syncer::EntityData& entity_data) override;
+
+ // Get or generate a storage key for |entity_data|. This will only ever be
+ // called once when first encountering a remote entity. Local changes will
+ // provide their storage keys directly to Put instead of using this method.
+ // Theoretically this function doesn't need to be stable across multiple calls
+ // on the same or different clients, but to keep things simple, it probably
+ // should be.
+ std::string GetStorageKey(const syncer::EntityData& entity_data) override;
+
+ // Overridable notification for when the processor is set. This is typically
+ // when the service should start loading metadata and then subsequently giving
+ // it to the processor.
+ void OnChangeProcessorSet() override;
+
+ // Methods used as callbacks given to DataTypeStore.
+ void OnStoreCreated(syncer::ModelTypeStore::Result result,
+ std::unique_ptr<syncer::ModelTypeStore> store);
+
private:
void OnDatabaseInit(bool success);
- void OnDatabaseLoad(bool success, std::unique_ptr<EntryVector> entries);
- void OnDatabaseSave(bool success);
+ void OnDatabaseLoad(
+ syncer::ModelTypeStore::Result result,
+ std::unique_ptr<syncer::ModelTypeStore::RecordList> entries);
+ void OnDatabaseSave(syncer::ModelTypeStore::Result result);
+ void OnReadAllMetadata(
+ syncer::ModelTypeStore::Result result,
+ std::unique_ptr<syncer::ModelTypeStore::RecordList> metadata_records,
+ const std::string& global_metadata);
+
+ void NoopEntry(const ReadingListEntry&);
- std::unique_ptr<ReadingListDB> database_;
+ std::unique_ptr<syncer::ModelTypeStore> store_;
bool database_loaded_;
ReadingListModelImpl* model_;
+ StoreFactoryFunction create_store_callback_;
+ bool has_metadata_loaded_ = false;
int pending_transaction_;
std::unique_ptr<ReadingListDB::KeyEntryVector> pending_keys_to_save_;
std::unique_ptr<std::vector<std::string>> pending_keys_to_remove_;
- base::WeakPtrFactory<ReadingListStore> weak_ptr_factory_;
};
#endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_model_storage.h ('k') | ios/chrome/browser/reading_list/reading_list_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698