| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 std::set<Observer*> observers_; | 85 std::set<Observer*> observers_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // A StatusChangeChecker for checking the status of keys in a | 88 // A StatusChangeChecker for checking the status of keys in a |
| 89 // TestModelTypeService::Store. | 89 // TestModelTypeService::Store. |
| 90 class KeyChecker : public StatusChangeChecker, | 90 class KeyChecker : public StatusChangeChecker, |
| 91 public TestModelTypeService::Observer { | 91 public TestModelTypeService::Observer { |
| 92 public: | 92 public: |
| 93 KeyChecker(TestModelTypeService* service, const std::string& key) | 93 KeyChecker(TestModelTypeService* service, const std::string& key) |
| 94 : service_(service), key_(key) {} | 94 : service_(service), key_(key) { |
| 95 service_->AddObserver(this); |
| 96 } |
| 97 |
| 98 ~KeyChecker() override { service_->RemoveObserver(this); } |
| 95 | 99 |
| 96 void OnApplySyncChanges() override { CheckExitCondition(); } | 100 void OnApplySyncChanges() override { CheckExitCondition(); } |
| 97 | 101 |
| 98 bool Wait() { | |
| 99 if (IsExitConditionSatisfied()) { | |
| 100 DVLOG(1) << "Wait() -> Exit before waiting: " << GetDebugMessage(); | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 service_->AddObserver(this); | |
| 105 StartBlockingWait(); | |
| 106 service_->RemoveObserver(this); | |
| 107 return !TimedOut(); | |
| 108 } | |
| 109 | |
| 110 protected: | 102 protected: |
| 111 TestModelTypeService* const service_; | 103 TestModelTypeService* const service_; |
| 112 const std::string key_; | 104 const std::string key_; |
| 113 }; | 105 }; |
| 114 | 106 |
| 115 // Wait for data for a key to have a certain value. | 107 // Wait for data for a key to have a certain value. |
| 116 class DataChecker : public KeyChecker { | 108 class DataChecker : public KeyChecker { |
| 117 public: | 109 public: |
| 118 DataChecker(TestModelTypeService* service, | 110 DataChecker(TestModelTypeService* service, |
| 119 const std::string& key, | 111 const std::string& key, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); | 324 model2->SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 333 // Write an item on model 1 to trigger a GetUpdates in model 2. | 325 // Write an item on model 1 to trigger a GetUpdates in model 2. |
| 334 model1->WriteItem(kKey1, kValue2); | 326 model1->WriteItem(kKey1, kValue2); |
| 335 | 327 |
| 336 // The type should stop syncing but keep tracking metadata. | 328 // The type should stop syncing but keep tracking metadata. |
| 337 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); | 329 ASSERT_TRUE(PrefsNotRunningChecker(GetSyncService(1)).Wait()); |
| 338 ASSERT_EQ(1U, model2->db().metadata_count()); | 330 ASSERT_EQ(1U, model2->db().metadata_count()); |
| 339 model2->WriteItem(kKey2, kValue2); | 331 model2->WriteItem(kKey2, kValue2); |
| 340 ASSERT_EQ(2U, model2->db().metadata_count()); | 332 ASSERT_EQ(2U, model2->db().metadata_count()); |
| 341 } | 333 } |
| OLD | NEW |