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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_store.h

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
6 #define IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
7
8 #include "base/threading/non_thread_safe.h"
9 #include "components/leveldb_proto/proto_database.h"
pavely 2016/11/14 07:45:34 proto_database.h and ReadingListDB are not used.
Olivier 2016/11/14 11:36:49 Done.
10 #include "components/sync/model/model_type_store.h"
11 #include "components/sync/model/model_type_sync_bridge.h"
12 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
13 #include "ios/chrome/browser/reading_list/reading_list_store_delegate.h"
14
15 using ReadingListDB =
16 leveldb_proto::ProtoDatabase<reading_list::ReadingListLocal>;
17
18 namespace syncer {
19 class MutableDataBatch;
20 }
21
22 class ReadingListModel;
23
24 typedef base::Callback<void(
pavely 2016/11/14 07:45:34 Could you move this typedef inside ReadingListStor
Olivier 2016/11/14 11:36:49 Done.
25 const syncer::ModelTypeStore::InitCallback& callback)>
26 StoreFactoryFunction;
27
28 // A ReadingListModelStorage storing and syncing data in protobufs.
29 class ReadingListStore : public syncer::ModelTypeSyncBridge,
30 public ReadingListModelStorage,
31 public base::NonThreadSafe {
32 using EntryVector = std::vector<reading_list::ReadingListLocal>;
pavely 2016/11/14 07:45:34 EntryVector is not used.
Olivier 2016/11/14 11:36:49 Done.
33
34 public:
35 ReadingListStore(StoreFactoryFunction create_store_callback,
36 const ChangeProcessorFactory& change_processor_factory);
37 ~ReadingListStore() override;
38
39 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override;
40
41 // ReadingListModelStorage implementation
42 void SetReadingListModel(ReadingListModel* model,
pavely 2016/11/14 07:45:34 Could you add comment to this function here or in
Olivier 2016/11/14 11:36:49 Done.
43 ReadingListStoreDelegate* delegate) override;
44
45 void SaveEntry(const ReadingListEntry& entry,
46 bool read,
47 bool from_sync) override;
48 void RemoveEntry(const ReadingListEntry& entry, bool from_sync) override;
49
50 // ReadingListModelStorage implementation.
51 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override;
52
53 // Creates an object used to communicate changes in the sync metadata to the
54 // model type store.
55 std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
56 override;
57
58 // Perform the initial merge between local and sync data. This should only be
59 // called when a data type is first enabled to start syncing, and there is no
60 // sync metadata. Best effort should be made to match local and sync data. The
61 // keys in the |entity_data_map| will have been created via GetClientTag(...),
62 // and if a local and sync data should match/merge but disagree on tags, the
63 // service should use the sync data's tag. Any local pieces of data that are
64 // not present in sync should immediately be Put(...) to the processor before
65 // returning. The same MetadataChangeList that was passed into this function
66 // can be passed to Put(...) calls. Delete(...) can also be called but should
67 // not be needed for most model types. Durable storage writes, if not able to
68 // combine all change atomically, should save the metadata after the data
69 // changes, so that this merge will be re-driven by sync if is not completely
70 // saved during the current run.
71 syncer::SyncError MergeSyncData(
72 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
73 syncer::EntityDataMap entity_data_map) override;
74
75 // Apply changes from the sync server locally.
76 // Please note that |entity_changes| might have fewer entries than
77 // |metadata_change_list| in case when some of the data changes are filtered
78 // out, or even be empty in case when a commit confirmation is processed and
79 // only the metadata needs to persisted.
80 syncer::SyncError ApplySyncChanges(
81 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
82 syncer::EntityChangeList entity_changes) override;
83
84 // Asynchronously retrieve the corresponding sync data for |storage_keys|.
85 void GetData(StorageKeyList storage_keys, DataCallback callback) override;
86
87 // Asynchronously retrieve all of the local sync data.
88 void GetAllData(DataCallback callback) override;
89
90 // Get or generate a client tag for |entity_data|. This must be the same tag
91 // that was/would have been generated in the SyncableService/Directory world
92 // for backward compatibility with pre-USS clients. The only time this
93 // theoretically needs to be called is on the creation of local data, however
94 // it is also used to verify the hash of remote data. If a data type was never
95 // launched pre-USS, then method does not need to be different from
96 // GetStorageKey().
97 std::string GetClientTag(const syncer::EntityData& entity_data) override;
98
99 // Get or generate a storage key for |entity_data|. This will only ever be
100 // called once when first encountering a remote entity. Local changes will
101 // provide their storage keys directly to Put instead of using this method.
102 // Theoretically this function doesn't need to be stable across multiple calls
103 // on the same or different clients, but to keep things simple, it probably
104 // should be.
105 std::string GetStorageKey(const syncer::EntityData& entity_data) override;
106
107 // Methods used as callbacks given to DataTypeStore.
108 void OnStoreCreated(syncer::ModelTypeStore::Result result,
109 std::unique_ptr<syncer::ModelTypeStore> store);
110
111 class ScopedBatchUpdate : public ReadingListModelStorage::ScopedBatchUpdate {
112 public:
113 explicit ScopedBatchUpdate(ReadingListStore* store);
114
115 ~ScopedBatchUpdate() override;
116
117 private:
118 ReadingListStore* store_;
119
120 DISALLOW_COPY_AND_ASSIGN(ScopedBatchUpdate);
121 };
122
123 private:
124 void BeginTransaction();
125 void CommitTransaction();
126 // Callbacks needed for the database handling.
127 void OnDatabaseInit(bool success);
pavely 2016/11/14 07:45:34 OnDatabaseInit is not defined.
Olivier 2016/11/14 11:36:49 Done.
128 void OnDatabaseLoad(
129 syncer::ModelTypeStore::Result result,
130 std::unique_ptr<syncer::ModelTypeStore::RecordList> entries);
131 void OnDatabaseSave(syncer::ModelTypeStore::Result result);
132 void OnReadAllMetadata(syncer::SyncError sync_error,
133 std::unique_ptr<syncer::MetadataBatch> metadata_batch);
134
135 void AddEntryToBatch(syncer::MutableDataBatch* batch,
136 const ReadingListEntry& entry,
137 bool read);
138
139 std::unique_ptr<syncer::ModelTypeStore> store_;
140 bool database_loaded_;
pavely 2016/11/14 07:45:34 database_loaded_ doesn't seem to be read anywhere.
Olivier 2016/11/14 11:36:49 Done.
141 ReadingListModel* model_;
142 ReadingListStoreDelegate* delegate_;
143 StoreFactoryFunction create_store_callback_;
144 bool has_metadata_loaded_ = false;
145
146 int pending_transaction_;
pavely 2016/11/14 07:45:34 I think pending_transaction_count_ would be a bett
Olivier 2016/11/14 11:36:49 Done.
147 std::unique_ptr<syncer::ModelTypeStore::WriteBatch> batch_;
148 };
149
150 #endif // IOS_CHROME_BROWSER_READING_LIST_READING_LIST_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698