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" |
Sigurdur Asgeirsson | 956f032f | 2021-05-12 14:49:39 | [diff] [blame] | 9 | #include "base/scoped_multi_source_observation.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(); |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame^] | 24 | |
| 25 | ConfigurationRefresher(const ConfigurationRefresher&) = delete; |
| 26 | ConfigurationRefresher& operator=(const ConfigurationRefresher&) = delete; |
| 27 | |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 28 | ~ConfigurationRefresher() override; |
| 29 | void Observe(syncer::SyncService* sync_service); |
| 30 | |
| 31 | private: |
| 32 | // syncer::SyncServiceObserver implementation. |
| 33 | void OnSyncConfigurationCompleted(syncer::SyncService* sync_service) override; |
Nicolas Ouellet-Payeur | 4743553 | 2020-11-02 17:05:27 | [diff] [blame] | 34 | void OnSyncShutdown(syncer::SyncService* sync_service) override; |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 35 | |
Sigurdur Asgeirsson | 956f032f | 2021-05-12 14:49:39 | [diff] [blame] | 36 | base::ScopedMultiSourceObservation<syncer::SyncService, |
| 37 | syncer::SyncServiceObserver> |
| 38 | scoped_observations_{this}; |
Sky Malice | a8b389e | 2017-12-08 23:17:34 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_CONFIGURATION_REFRESHER_H_ |