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 SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | |
6 #define SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/observer_list.h" | |
13 #include "sync/internal_api/public/sync_manager.h" | |
14 #include "sync/internal_api/public/test/test_user_share.h" | |
15 | |
16 class GURL; | |
17 | |
18 namespace base { | |
19 class SequencedTaskRunner; | |
20 } | |
21 | |
22 namespace syncer { | |
23 | |
24 class FakeSyncEncryptionHandler; | |
25 | |
26 class FakeSyncManager : public SyncManager { | |
27 public: | |
28 // |initial_sync_ended_types|: The set of types that have initial_sync_ended | |
29 // set to true. This value will be used by InitialSyncEndedTypes() until the | |
30 // next configuration is performed. | |
31 // | |
32 // |progress_marker_types|: The set of types that have valid progress | |
33 // markers. This will be used by GetTypesWithEmptyProgressMarkerToken() until | |
34 // the next configuration is performed. | |
35 // | |
36 // |configure_fail_types|: The set of types that will fail | |
37 // configuration. Once ConfigureSyncer is called, the | |
38 // |initial_sync_ended_types_| and |progress_marker_types_| will be updated | |
39 // to include those types that didn't fail. | |
40 FakeSyncManager(ModelTypeSet initial_sync_ended_types, | |
41 ModelTypeSet progress_marker_types, | |
42 ModelTypeSet configure_fail_types); | |
43 ~FakeSyncManager() override; | |
44 | |
45 // Returns those types that have been cleaned (purged from the directory) | |
46 // since the last call to GetAndResetCleanedTypes(), or since startup if never | |
47 // called. | |
48 ModelTypeSet GetAndResetCleanedTypes(); | |
49 | |
50 // Returns those types that have been downloaded since the last call to | |
51 // GetAndResetDownloadedTypes(), or since startup if never called. | |
52 ModelTypeSet GetAndResetDownloadedTypes(); | |
53 | |
54 // Returns those types that have been marked as enabled since the | |
55 // last call to GetAndResetEnabledTypes(), or since startup if never | |
56 // called. | |
57 ModelTypeSet GetAndResetEnabledTypes(); | |
58 | |
59 // Returns the types that have most recently received a refresh request. | |
60 ModelTypeSet GetLastRefreshRequestTypes(); | |
61 | |
62 // Returns the most recent configuration reason since the last call to | |
63 // GetAndResetConfigureReason, or since startup if never called. | |
64 ConfigureReason GetAndResetConfigureReason(); | |
65 | |
66 // Returns the number of invalidations received since startup. | |
67 int GetInvalidationCount() const; | |
68 | |
69 // Block until the sync thread has finished processing any pending messages. | |
70 void WaitForSyncThread(); | |
71 | |
72 // SyncManager implementation. | |
73 // Note: we treat whatever message loop this is called from as the sync | |
74 // loop for purposes of callbacks. | |
75 void Init(InitArgs* args) override; | |
76 ModelTypeSet InitialSyncEndedTypes() override; | |
77 ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | |
78 ModelTypeSet types) override; | |
79 bool PurgePartiallySyncedTypes() override; | |
80 void UpdateCredentials(const SyncCredentials& credentials) override; | |
81 void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info, | |
82 base::Time last_poll_time) override; | |
83 void ConfigureSyncer(ConfigureReason reason, | |
84 ModelTypeSet to_download, | |
85 ModelTypeSet to_purge, | |
86 ModelTypeSet to_journal, | |
87 ModelTypeSet to_unapply, | |
88 const ModelSafeRoutingInfo& new_routing_info, | |
89 const base::Closure& ready_task, | |
90 const base::Closure& retry_task) override; | |
91 void OnIncomingInvalidation( | |
92 syncer::ModelType type, | |
93 std::unique_ptr<InvalidationInterface> interface) override; | |
94 void SetInvalidatorEnabled(bool invalidator_enabled) override; | |
95 void AddObserver(Observer* observer) override; | |
96 void RemoveObserver(Observer* observer) override; | |
97 SyncStatus GetDetailedStatus() const override; | |
98 void SaveChanges() override; | |
99 void ShutdownOnSyncThread(ShutdownReason reason) override; | |
100 UserShare* GetUserShare() override; | |
101 std::unique_ptr<syncer_v2::ModelTypeConnector> GetModelTypeConnectorProxy() | |
102 override; | |
103 const std::string cache_guid() override; | |
104 bool ReceivedExperiment(Experiments* experiments) override; | |
105 bool HasUnsyncedItems() override; | |
106 SyncEncryptionHandler* GetEncryptionHandler() override; | |
107 ScopedVector<syncer::ProtocolEvent> GetBufferedProtocolEvents() override; | |
108 std::unique_ptr<base::ListValue> GetAllNodesForType( | |
109 syncer::ModelType type) override; | |
110 void RefreshTypes(ModelTypeSet types) override; | |
111 void RegisterDirectoryTypeDebugInfoObserver( | |
112 syncer::TypeDebugInfoObserver* observer) override; | |
113 void UnregisterDirectoryTypeDebugInfoObserver( | |
114 syncer::TypeDebugInfoObserver* observer) override; | |
115 bool HasDirectoryTypeDebugInfoObserver( | |
116 syncer::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 // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | |
OLD | NEW |