| 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 #include "components/reading_list/ios/reading_list_store.h" | 5 #include "components/reading_list/ios/reading_list_store.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/logging.h" | 8 #include "base/logging.h" | 
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" | 
| 10 #include "components/reading_list/ios/proto/reading_list.pb.h" | 10 #include "components/reading_list/ios/proto/reading_list.pb.h" | 
| 11 #include "components/reading_list/ios/reading_list_model_impl.h" | 11 #include "components/reading_list/ios/reading_list_model_impl.h" | 
| 12 #include "components/sync/model/entity_change.h" | 12 #include "components/sync/model/entity_change.h" | 
| 13 #include "components/sync/model/metadata_batch.h" | 13 #include "components/sync/model/metadata_batch.h" | 
| 14 #include "components/sync/model/metadata_change_list.h" | 14 #include "components/sync/model/metadata_change_list.h" | 
| 15 #include "components/sync/model/model_type_change_processor.h" | 15 #include "components/sync/model/model_type_change_processor.h" | 
| 16 #include "components/sync/model/mutable_data_batch.h" | 16 #include "components/sync/model/mutable_data_batch.h" | 
| 17 #include "components/sync/model_impl/accumulating_metadata_change_list.h" | 17 #include "components/sync/model_impl/accumulating_metadata_change_list.h" | 
| 18 #include "components/sync/protocol/model_type_state.pb.h" | 18 #include "components/sync/protocol/model_type_state.pb.h" | 
| 19 | 19 | 
| 20 ReadingListStore::ReadingListStore( | 20 ReadingListStore::ReadingListStore( | 
| 21     StoreFactoryFunction create_store_callback, | 21     StoreFactoryFunction create_store_callback, | 
| 22     const ChangeProcessorFactory& change_processor_factory) | 22     const ChangeProcessorFactory& change_processor_factory) | 
| 23     : ModelTypeSyncBridge(change_processor_factory, syncer::READING_LIST), | 23     : ReadingListModelStorage(change_processor_factory, syncer::READING_LIST), | 
| 24       create_store_callback_(create_store_callback), | 24       create_store_callback_(create_store_callback), | 
| 25       pending_transaction_count_(0) {} | 25       pending_transaction_count_(0) {} | 
| 26 | 26 | 
| 27 ReadingListStore::~ReadingListStore() { | 27 ReadingListStore::~ReadingListStore() { | 
| 28   DCHECK(pending_transaction_count_ == 0); | 28   DCHECK(pending_transaction_count_ == 0); | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 void ReadingListStore::SetReadingListModel(ReadingListModel* model, | 31 void ReadingListStore::SetReadingListModel(ReadingListModel* model, | 
| 32                                            ReadingListStoreDelegate* delegate) { | 32                                            ReadingListStoreDelegate* delegate) { | 
| 33   DCHECK(CalledOnValidThread()); | 33   DCHECK(CalledOnValidThread()); | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 169   if (result != syncer::ModelTypeStore::Result::SUCCESS) { | 169   if (result != syncer::ModelTypeStore::Result::SUCCESS) { | 
| 170     // TODO(crbug.com/664926): handle store creation error. | 170     // TODO(crbug.com/664926): handle store creation error. | 
| 171     return; | 171     return; | 
| 172   } | 172   } | 
| 173   store_ = std::move(store); | 173   store_ = std::move(store); | 
| 174   store_->ReadAllData( | 174   store_->ReadAllData( | 
| 175       base::Bind(&ReadingListStore::OnDatabaseLoad, base::AsWeakPtr(this))); | 175       base::Bind(&ReadingListStore::OnDatabaseLoad, base::AsWeakPtr(this))); | 
| 176   return; | 176   return; | 
| 177 } | 177 } | 
| 178 | 178 | 
| 179 syncer::ModelTypeSyncBridge* ReadingListStore::GetModelTypeSyncBridge() { |  | 
| 180   return this; |  | 
| 181 } |  | 
| 182 |  | 
| 183 // Creates an object used to communicate changes in the sync metadata to the | 179 // Creates an object used to communicate changes in the sync metadata to the | 
| 184 // model type store. | 180 // model type store. | 
| 185 std::unique_ptr<syncer::MetadataChangeList> | 181 std::unique_ptr<syncer::MetadataChangeList> | 
| 186 ReadingListStore::CreateMetadataChangeList() { | 182 ReadingListStore::CreateMetadataChangeList() { | 
| 187   return syncer::ModelTypeStore::WriteBatch::CreateMetadataChangeList(); | 183   return syncer::ModelTypeStore::WriteBatch::CreateMetadataChangeList(); | 
| 188 } | 184 } | 
| 189 | 185 | 
| 190 // Perform the initial merge between local and sync data. This should only be | 186 // Perform the initial merge between local and sync data. This should only be | 
| 191 // called when a data type is first enabled to start syncing, and there is no | 187 // called when a data type is first enabled to start syncing, and there is no | 
| 192 // sync metadata. Best effort should be made to match local and sync data. The | 188 // sync metadata. Best effort should be made to match local and sync data. The | 
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 446     if (rhs.first_read_time_us() == 0 && lhs.first_read_time_us() != 0) { | 442     if (rhs.first_read_time_us() == 0 && lhs.first_read_time_us() != 0) { | 
| 447       return false; | 443       return false; | 
| 448     } | 444     } | 
| 449     if (rhs.first_read_time_us() > lhs.first_read_time_us() && | 445     if (rhs.first_read_time_us() > lhs.first_read_time_us() && | 
| 450         lhs.first_read_time_us() != 0) { | 446         lhs.first_read_time_us() != 0) { | 
| 451       return false; | 447       return false; | 
| 452     } | 448     } | 
| 453   } | 449   } | 
| 454   return true; | 450   return true; | 
| 455 } | 451 } | 
| OLD | NEW | 
|---|