| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_READING_LIST_IOS_READING_LIST_STORE_H_ | 5 #ifndef COMPONENTS_READING_LIST_IOS_READING_LIST_STORE_H_ |
| 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_STORE_H_ | 6 #define COMPONENTS_READING_LIST_IOS_READING_LIST_STORE_H_ |
| 7 | 7 |
| 8 #include "base/threading/non_thread_safe.h" | 8 #include "base/threading/non_thread_safe.h" |
| 9 #include "components/reading_list/ios/reading_list_model_storage.h" | 9 #include "components/reading_list/ios/reading_list_model_storage.h" |
| 10 #include "components/reading_list/ios/reading_list_store_delegate.h" | 10 #include "components/reading_list/ios/reading_list_store_delegate.h" |
| 11 #include "components/sync/model/model_error.h" |
| 11 #include "components/sync/model/model_type_store.h" | 12 #include "components/sync/model/model_type_store.h" |
| 12 | 13 |
| 13 namespace syncer { | 14 namespace syncer { |
| 14 class MutableDataBatch; | 15 class MutableDataBatch; |
| 15 } | 16 } |
| 16 | 17 |
| 17 class ReadingListModel; | 18 class ReadingListModel; |
| 18 | 19 |
| 19 // A ReadingListModelStorage storing and syncing data in protobufs. | 20 // A ReadingListModelStorage storing and syncing data in protobufs. |
| 20 class ReadingListStore : public ReadingListModelStorage, | 21 class ReadingListStore : public ReadingListModelStorage, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 // keys in the |entity_data_map| will have been created via GetClientTag(...), | 48 // keys in the |entity_data_map| will have been created via GetClientTag(...), |
| 48 // and if a local and sync data should match/merge but disagree on tags, the | 49 // and if a local and sync data should match/merge but disagree on tags, the |
| 49 // service should use the sync data's tag. Any local pieces of data that are | 50 // service should use the sync data's tag. Any local pieces of data that are |
| 50 // not present in sync should immediately be Put(...) to the processor before | 51 // not present in sync should immediately be Put(...) to the processor before |
| 51 // returning. The same MetadataChangeList that was passed into this function | 52 // returning. The same MetadataChangeList that was passed into this function |
| 52 // can be passed to Put(...) calls. Delete(...) can also be called but should | 53 // can be passed to Put(...) calls. Delete(...) can also be called but should |
| 53 // not be needed for most model types. Durable storage writes, if not able to | 54 // not be needed for most model types. Durable storage writes, if not able to |
| 54 // combine all change atomically, should save the metadata after the data | 55 // combine all change atomically, should save the metadata after the data |
| 55 // changes, so that this merge will be re-driven by sync if is not completely | 56 // changes, so that this merge will be re-driven by sync if is not completely |
| 56 // saved during the current run. | 57 // saved during the current run. |
| 57 syncer::SyncError MergeSyncData( | 58 syncer::ModelError MergeSyncData( |
| 58 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, | 59 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, |
| 59 syncer::EntityDataMap entity_data_map) override; | 60 syncer::EntityDataMap entity_data_map) override; |
| 60 | 61 |
| 61 // Apply changes from the sync server locally. | 62 // Apply changes from the sync server locally. |
| 62 // Please note that |entity_changes| might have fewer entries than | 63 // Please note that |entity_changes| might have fewer entries than |
| 63 // |metadata_change_list| in case when some of the data changes are filtered | 64 // |metadata_change_list| in case when some of the data changes are filtered |
| 64 // out, or even be empty in case when a commit confirmation is processed and | 65 // out, or even be empty in case when a commit confirmation is processed and |
| 65 // only the metadata needs to persisted. | 66 // only the metadata needs to persisted. |
| 66 syncer::SyncError ApplySyncChanges( | 67 syncer::ModelError ApplySyncChanges( |
| 67 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, | 68 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, |
| 68 syncer::EntityChangeList entity_changes) override; | 69 syncer::EntityChangeList entity_changes) override; |
| 69 | 70 |
| 70 // Returns whether entries respect a strict order for sync and if |rhs| can be | 71 // Returns whether entries respect a strict order for sync and if |rhs| can be |
| 71 // submitted to sync after |lhs| has been received. | 72 // submitted to sync after |lhs| has been received. |
| 72 // The order should ensure that there is no sync loop in sync and should be | 73 // The order should ensure that there is no sync loop in sync and should be |
| 73 // submitted to sync in strictly increasing order. | 74 // submitted to sync in strictly increasing order. |
| 74 // Entries are in increasing order if all the fields respect increasing order. | 75 // Entries are in increasing order if all the fields respect increasing order. |
| 75 // - URL must be the same. | 76 // - URL must be the same. |
| 76 // - update_title_time_us: | 77 // - update_title_time_us: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 }; | 141 }; |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 void BeginTransaction(); | 144 void BeginTransaction(); |
| 144 void CommitTransaction(); | 145 void CommitTransaction(); |
| 145 // Callbacks needed for the database handling. | 146 // Callbacks needed for the database handling. |
| 146 void OnDatabaseLoad( | 147 void OnDatabaseLoad( |
| 147 syncer::ModelTypeStore::Result result, | 148 syncer::ModelTypeStore::Result result, |
| 148 std::unique_ptr<syncer::ModelTypeStore::RecordList> entries); | 149 std::unique_ptr<syncer::ModelTypeStore::RecordList> entries); |
| 149 void OnDatabaseSave(syncer::ModelTypeStore::Result result); | 150 void OnDatabaseSave(syncer::ModelTypeStore::Result result); |
| 150 void OnReadAllMetadata(syncer::SyncError sync_error, | 151 void OnReadAllMetadata(syncer::ModelError error, |
| 151 std::unique_ptr<syncer::MetadataBatch> metadata_batch); | 152 std::unique_ptr<syncer::MetadataBatch> metadata_batch); |
| 152 | 153 |
| 153 void AddEntryToBatch(syncer::MutableDataBatch* batch, | 154 void AddEntryToBatch(syncer::MutableDataBatch* batch, |
| 154 const ReadingListEntry& entry); | 155 const ReadingListEntry& entry); |
| 155 | 156 |
| 156 std::unique_ptr<syncer::ModelTypeStore> store_; | 157 std::unique_ptr<syncer::ModelTypeStore> store_; |
| 157 ReadingListModel* model_; | 158 ReadingListModel* model_; |
| 158 ReadingListStoreDelegate* delegate_; | 159 ReadingListStoreDelegate* delegate_; |
| 159 StoreFactoryFunction create_store_callback_; | 160 StoreFactoryFunction create_store_callback_; |
| 160 | 161 |
| 161 int pending_transaction_count_; | 162 int pending_transaction_count_; |
| 162 std::unique_ptr<syncer::ModelTypeStore::WriteBatch> batch_; | 163 std::unique_ptr<syncer::ModelTypeStore::WriteBatch> batch_; |
| 163 }; | 164 }; |
| 164 | 165 |
| 165 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_STORE_H_ | 166 #endif // COMPONENTS_READING_LIST_IOS_READING_LIST_STORE_H_ |
| OLD | NEW |