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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "chrome/browser/sync/chrome_sync_client.h" | 8 #include "chrome/browser/sync/chrome_sync_client.h" |
9 #include "chrome/browser/sync/profile_sync_service_factory.h" | 9 #include "chrome/browser/sync/profile_sync_service_factory.h" |
10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 10 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // A FakeModelTypeService that supports observing ApplySyncChanges. | 51 // A FakeModelTypeService that supports observing ApplySyncChanges. |
52 class TestModelTypeService : public FakeModelTypeService { | 52 class TestModelTypeService : public FakeModelTypeService { |
53 public: | 53 public: |
54 class Observer { | 54 class Observer { |
55 public: | 55 public: |
56 virtual void OnApplySyncChanges() = 0; | 56 virtual void OnApplySyncChanges() = 0; |
57 }; | 57 }; |
58 | 58 |
59 TestModelTypeService() | 59 TestModelTypeService() |
60 : FakeModelTypeService(base::Bind(&ModelTypeChangeProcessor::Create)) {} | 60 : FakeModelTypeService(base::Bind(&ModelTypeChangeProcessor::Create)) { |
| 61 change_processor()->OnMetadataLoaded(syncer::SyncError(), |
| 62 db().CreateMetadataBatch()); |
| 63 } |
61 | 64 |
62 syncer::SyncError ApplySyncChanges( | 65 syncer::SyncError ApplySyncChanges( |
63 std::unique_ptr<syncer::MetadataChangeList> metadata_changes, | 66 std::unique_ptr<syncer::MetadataChangeList> metadata_changes, |
64 syncer::EntityChangeList entity_changes) override { | 67 syncer::EntityChangeList entity_changes) override { |
65 syncer::SyncError error = FakeModelTypeService::ApplySyncChanges( | 68 syncer::SyncError error = FakeModelTypeService::ApplySyncChanges( |
66 std::move(metadata_changes), entity_changes); | 69 std::move(metadata_changes), entity_changes); |
67 NotifyObservers(); | 70 NotifyObservers(); |
68 return error; | 71 return error; |
69 } | 72 } |
70 | 73 |
71 void OnChangeProcessorSet() override { | |
72 change_processor()->OnMetadataLoaded(syncer::SyncError(), | |
73 db().CreateMetadataBatch()); | |
74 } | |
75 | |
76 void AddObserver(Observer* observer) { observers_.insert(observer); } | 74 void AddObserver(Observer* observer) { observers_.insert(observer); } |
77 void RemoveObserver(Observer* observer) { observers_.erase(observer); } | 75 void RemoveObserver(Observer* observer) { observers_.erase(observer); } |
78 | 76 |
79 private: | 77 private: |
80 void NotifyObservers() { | 78 void NotifyObservers() { |
81 for (Observer* observer : observers_) { | 79 for (Observer* observer : observers_) { |
82 observer->OnApplySyncChanges(); | 80 observer->OnApplySyncChanges(); |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); | 318 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
321 // Write an item on model 1 to trigger a GetUpdates in model 2. | 319 // Write an item on model 1 to trigger a GetUpdates in model 2. |
322 model1->WriteItem(kKey1, kValue2); | 320 model1->WriteItem(kKey1, kValue2); |
323 | 321 |
324 // The type should stop syncing but keep tracking metadata. | 322 // The type should stop syncing but keep tracking metadata. |
325 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); | 323 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); |
326 ASSERT_EQ(1U, model2->db().metadata_count()); | 324 ASSERT_EQ(1U, model2->db().metadata_count()); |
327 model2->WriteItem(kKey2, kValue2); | 325 model2->WriteItem(kKey2, kValue2); |
328 ASSERT_EQ(2U, model2->db().metadata_count()); | 326 ASSERT_EQ(2U, model2->db().metadata_count()); |
329 } | 327 } |
OLD | NEW |