| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 COMPONENTS_SYNC_CORE_TEST_FAKE_SYNC_MANAGER_H_ | |
| 6 #define COMPONENTS_SYNC_CORE_TEST_FAKE_SYNC_MANAGER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/observer_list.h" | |
| 15 #include "components/sync/core/sync_manager.h" | |
| 16 #include "components/sync/syncable/test_user_share.h" | |
| 17 | |
| 18 class GURL; | |
| 19 | |
| 20 namespace base { | |
| 21 class SequencedTaskRunner; | |
| 22 } | |
| 23 | |
| 24 namespace syncer { | |
| 25 | |
| 26 class FakeSyncEncryptionHandler; | |
| 27 | |
| 28 class FakeSyncManager : public SyncManager { | |
| 29 public: | |
| 30 // |initial_sync_ended_types|: The set of types that have initial_sync_ended | |
| 31 // set to true. This value will be used by InitialSyncEndedTypes() until the | |
| 32 // next configuration is performed. | |
| 33 // | |
| 34 // |progress_marker_types|: The set of types that have valid progress | |
| 35 // markers. This will be used by GetTypesWithEmptyProgressMarkerToken() until | |
| 36 // the next configuration is performed. | |
| 37 // | |
| 38 // |configure_fail_types|: The set of types that will fail | |
| 39 // configuration. Once ConfigureSyncer is called, the | |
| 40 // |initial_sync_ended_types_| and |progress_marker_types_| will be updated | |
| 41 // to include those types that didn't fail. | |
| 42 FakeSyncManager(ModelTypeSet initial_sync_ended_types, | |
| 43 ModelTypeSet progress_marker_types, | |
| 44 ModelTypeSet configure_fail_types); | |
| 45 ~FakeSyncManager() override; | |
| 46 | |
| 47 // Returns those types that have been cleaned (purged from the directory) | |
| 48 // since the last call to GetAndResetCleanedTypes(), or since startup if never | |
| 49 // called. | |
| 50 ModelTypeSet GetAndResetCleanedTypes(); | |
| 51 | |
| 52 // Returns those types that have been downloaded since the last call to | |
| 53 // GetAndResetDownloadedTypes(), or since startup if never called. | |
| 54 ModelTypeSet GetAndResetDownloadedTypes(); | |
| 55 | |
| 56 // Returns those types that have been marked as enabled since the | |
| 57 // last call to GetAndResetEnabledTypes(), or since startup if never | |
| 58 // called. | |
| 59 ModelTypeSet GetAndResetEnabledTypes(); | |
| 60 | |
| 61 // Returns the types that have most recently received a refresh request. | |
| 62 ModelTypeSet GetLastRefreshRequestTypes(); | |
| 63 | |
| 64 // Returns the most recent configuration reason since the last call to | |
| 65 // GetAndResetConfigureReason, or since startup if never called. | |
| 66 ConfigureReason GetAndResetConfigureReason(); | |
| 67 | |
| 68 // Returns the number of invalidations received since startup. | |
| 69 int GetInvalidationCount() const; | |
| 70 | |
| 71 // Block until the sync thread has finished processing any pending messages. | |
| 72 void WaitForSyncThread(); | |
| 73 | |
| 74 // SyncManager implementation. | |
| 75 // Note: we treat whatever message loop this is called from as the sync | |
| 76 // loop for purposes of callbacks. | |
| 77 void Init(InitArgs* args) override; | |
| 78 ModelTypeSet InitialSyncEndedTypes() override; | |
| 79 ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | |
| 80 ModelTypeSet types) override; | |
| 81 bool PurgePartiallySyncedTypes() override; | |
| 82 void UpdateCredentials(const SyncCredentials& credentials) override; | |
| 83 void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info, | |
| 84 base::Time last_poll_time) override; | |
| 85 void ConfigureSyncer(ConfigureReason reason, | |
| 86 ModelTypeSet to_download, | |
| 87 ModelTypeSet to_purge, | |
| 88 ModelTypeSet to_journal, | |
| 89 ModelTypeSet to_unapply, | |
| 90 const ModelSafeRoutingInfo& new_routing_info, | |
| 91 const base::Closure& ready_task, | |
| 92 const base::Closure& retry_task) override; | |
| 93 void OnIncomingInvalidation( | |
| 94 ModelType type, | |
| 95 std::unique_ptr<InvalidationInterface> interface) override; | |
| 96 void SetInvalidatorEnabled(bool invalidator_enabled) override; | |
| 97 void AddObserver(Observer* observer) override; | |
| 98 void RemoveObserver(Observer* observer) override; | |
| 99 SyncStatus GetDetailedStatus() const override; | |
| 100 void SaveChanges() override; | |
| 101 void ShutdownOnSyncThread(ShutdownReason reason) override; | |
| 102 UserShare* GetUserShare() override; | |
| 103 std::unique_ptr<ModelTypeConnector> GetModelTypeConnectorProxy() override; | |
| 104 const std::string cache_guid() override; | |
| 105 bool ReceivedExperiment(Experiments* experiments) override; | |
| 106 bool HasUnsyncedItems() override; | |
| 107 SyncEncryptionHandler* GetEncryptionHandler() override; | |
| 108 std::vector<std::unique_ptr<ProtocolEvent>> GetBufferedProtocolEvents() | |
| 109 override; | |
| 110 void RefreshTypes(ModelTypeSet types) override; | |
| 111 void RegisterDirectoryTypeDebugInfoObserver( | |
| 112 TypeDebugInfoObserver* observer) override; | |
| 113 void UnregisterDirectoryTypeDebugInfoObserver( | |
| 114 TypeDebugInfoObserver* observer) override; | |
| 115 bool HasDirectoryTypeDebugInfoObserver( | |
| 116 TypeDebugInfoObserver* observer) override; | |
| 117 void RequestEmitDebugInfo() override; | |
| 118 void ClearServerData(const ClearServerDataCallback& callback) override; | |
| 119 void OnCookieJarChanged(bool account_mismatch, bool empty_jar) override; | |
| 120 | |
| 121 private: | |
| 122 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; | |
| 123 | |
| 124 base::ObserverList<SyncManager::Observer> observers_; | |
| 125 | |
| 126 // Faked directory state. | |
| 127 ModelTypeSet initial_sync_ended_types_; | |
| 128 ModelTypeSet progress_marker_types_; | |
| 129 | |
| 130 // Test specific state. | |
| 131 // The types that should fail configuration attempts. These types will not | |
| 132 // have their progress markers or initial_sync_ended bits set. | |
| 133 ModelTypeSet configure_fail_types_; | |
| 134 // The set of types that have been cleaned up. | |
| 135 ModelTypeSet cleaned_types_; | |
| 136 // The set of types that have been downloaded. | |
| 137 ModelTypeSet downloaded_types_; | |
| 138 // The set of types that have been enabled. | |
| 139 ModelTypeSet enabled_types_; | |
| 140 | |
| 141 // The types for which a refresh was most recently requested. | |
| 142 ModelTypeSet last_refresh_request_types_; | |
| 143 | |
| 144 // The most recent configure reason. | |
| 145 ConfigureReason last_configure_reason_; | |
| 146 | |
| 147 std::unique_ptr<FakeSyncEncryptionHandler> fake_encryption_handler_; | |
| 148 | |
| 149 TestUserShare test_user_share_; | |
| 150 | |
| 151 // Number of invalidations received since startup. | |
| 152 int num_invalidations_received_; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(FakeSyncManager); | |
| 155 }; | |
| 156 | |
| 157 } // namespace syncer | |
| 158 | |
| 159 #endif // COMPONENTS_SYNC_CORE_TEST_FAKE_SYNC_MANAGER_H_ | |
| OLD | NEW |