Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 1 | // Copyright 2017 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 CHROME_BROWSER_SYNC_TEST_INTEGRATION_CONFIGURATION_REFRESHER_H_ |
| 6 | #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_CONFIGURATION_REFRESHER_H_ |
| 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/scoped_observer.h" |
Evan Stade | 22e3f9b | 2019-10-01 21:12:17 | [diff] [blame] | 10 | #include "components/sync/driver/sync_service.h" |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 11 | #include "components/sync/driver/sync_service_observer.h" |
| 12 | |
| 13 | // Triggers a GetUpdates via refresh for any observed SyncService after a |
| 14 | // configuration. This class was created to be used in conjunction with fake |
| 15 | // invalidations. It turns out there's a race during configuration, after the |
| 16 | // initial GetUpdates was called, but before invalidations were re-subscribed to |
| 17 | // that caused updates to be missed. This resulted in some flakey test cases, |
| 18 | // see crbug,com/644367 for more details. This class fills the gap by forcing a |
| 19 | // GetUpdates after configuration to fetch anything missed while a client was |
| 20 | // not subscribed to invalidation(s). |
| 21 | class ConfigurationRefresher : public syncer::SyncServiceObserver { |
| 22 | public: |
| 23 | ConfigurationRefresher(); |
| 24 | ~ConfigurationRefresher() override; |
| 25 | void Observe(syncer::SyncService* sync_service); |
| 26 | |
| 27 | private: |
| 28 | // syncer::SyncServiceObserver implementation. |
| 29 | void OnSyncConfigurationCompleted(syncer::SyncService* sync_service) override; |
Nicolas Ouellet-Payeur | 4743553 | 2020-11-02 17:05:27 | [diff] [blame^] | 30 | void OnSyncShutdown(syncer::SyncService* sync_service) override; |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 31 | |
Evan Stade | 22e3f9b | 2019-10-01 21:12:17 | [diff] [blame] | 32 | ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> |
| 33 | scoped_observer_{this}; |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 34 | |
| 35 | DISALLOW_COPY_AND_ASSIGN(ConfigurationRefresher); |
| 36 | }; |
| 37 | |
| 38 | #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_CONFIGURATION_REFRESHER_H_ |