OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/observer_list.h" |
10 #include "sync/internal_api/public/sync_manager.h" | 12 #include "sync/internal_api/public/sync_manager.h" |
| 13 #include "sync/notifier/sync_notifier_helper.h" |
11 | 14 |
12 #include "base/observer_list.h" | 15 namespace base { |
13 | 16 class SequencedTaskRunner; |
14 class MessageLoop; | 17 } |
15 | 18 |
16 namespace syncer { | 19 namespace syncer { |
17 | 20 |
18 class FakeSyncManager : public SyncManager { | 21 class FakeSyncManager : public SyncManager { |
19 public: | 22 public: |
20 explicit FakeSyncManager(); | 23 explicit FakeSyncManager(); |
21 virtual ~FakeSyncManager(); | 24 virtual ~FakeSyncManager(); |
22 | 25 |
23 // The set of types that have initial_sync_ended set to true. This value will | 26 // The set of types that have initial_sync_ended set to true. This value will |
24 // be used by InitialSyncEndedTypes() until the next configuration is | 27 // be used by InitialSyncEndedTypes() until the next configuration is |
(...skipping 18 matching lines...) Expand all Loading... |
43 | 46 |
44 // Returns those types that have been downloaded since the last call to | 47 // Returns those types that have been downloaded since the last call to |
45 // GetAndResetDownloadedTypes(), or since startup if never called. | 48 // GetAndResetDownloadedTypes(), or since startup if never called. |
46 ModelTypeSet GetAndResetDownloadedTypes(); | 49 ModelTypeSet GetAndResetDownloadedTypes(); |
47 | 50 |
48 // Returns those types that have been marked as enabled since the | 51 // Returns those types that have been marked as enabled since the |
49 // last call to GetAndResetEnabledTypes(), or since startup if never | 52 // last call to GetAndResetEnabledTypes(), or since startup if never |
50 // called. | 53 // called. |
51 ModelTypeSet GetAndResetEnabledTypes(); | 54 ModelTypeSet GetAndResetEnabledTypes(); |
52 | 55 |
| 56 // Posts a method to invalidate the given IDs on the sync thread. |
| 57 void Invalidate( |
| 58 const ObjectIdPayloadMap& id_payloads, |
| 59 IncomingNotificationSource source); |
| 60 |
| 61 // Posts a method to enable notifications on the sync thread. |
| 62 void EnableNotifications(); |
| 63 |
| 64 // Posts a method to disable notifications on the sync thread. |
| 65 void DisableNotifications(NotificationsDisabledReason reason); |
| 66 |
53 // SyncManager implementation. | 67 // SyncManager implementation. |
54 // Note: we treat whatever message loop this is called from as the sync | 68 // Note: we treat whatever message loop this is called from as the sync |
55 // loop for purposes of callbacks. | 69 // loop for purposes of callbacks. |
56 virtual bool Init( | 70 virtual bool Init( |
57 const FilePath& database_location, | 71 const FilePath& database_location, |
58 const WeakHandle<JsEventHandler>& event_handler, | 72 const WeakHandle<JsEventHandler>& event_handler, |
59 const std::string& sync_server_and_path, | 73 const std::string& sync_server_and_path, |
60 int sync_server_port, | 74 int sync_server_port, |
61 bool use_ssl, | 75 bool use_ssl, |
62 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 76 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
63 scoped_ptr<HttpPostProviderFactory> post_factory, | 77 scoped_ptr<HttpPostProviderFactory> post_factory, |
64 const std::vector<ModelSafeWorker*>& workers, | 78 const std::vector<ModelSafeWorker*>& workers, |
65 ExtensionsActivityMonitor* extensions_activity_monitor, | 79 ExtensionsActivityMonitor* extensions_activity_monitor, |
66 ChangeDelegate* change_delegate, | 80 ChangeDelegate* change_delegate, |
67 const SyncCredentials& credentials, | 81 const SyncCredentials& credentials, |
68 scoped_ptr<SyncNotifier> sync_notifier, | 82 scoped_ptr<SyncNotifier> sync_notifier, |
69 const std::string& restored_key_for_bootstrapping, | 83 const std::string& restored_key_for_bootstrapping, |
70 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 84 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
71 Encryptor* encryptor, | 85 Encryptor* encryptor, |
72 UnrecoverableErrorHandler* unrecoverable_error_handler, | 86 UnrecoverableErrorHandler* unrecoverable_error_handler, |
73 ReportUnrecoverableErrorFunction | 87 ReportUnrecoverableErrorFunction |
74 report_unrecoverable_error_function) OVERRIDE; | 88 report_unrecoverable_error_function) OVERRIDE; |
75 virtual void ThrowUnrecoverableError() OVERRIDE; | 89 virtual void ThrowUnrecoverableError() OVERRIDE; |
76 virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; | 90 virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; |
77 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | 91 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
78 ModelTypeSet types) OVERRIDE; | 92 ModelTypeSet types) OVERRIDE; |
79 virtual bool PurgePartiallySyncedTypes() OVERRIDE; | 93 virtual bool PurgePartiallySyncedTypes() OVERRIDE; |
80 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; | 94 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; |
81 virtual void UpdateEnabledTypes(const ModelTypeSet& types) OVERRIDE; | 95 virtual void UpdateEnabledTypes(const ModelTypeSet& types) OVERRIDE; |
| 96 virtual void UpdateRegisteredIds( |
| 97 SyncNotifierObserver* handler, const ObjectIdSet& ids) OVERRIDE; |
82 virtual void StartSyncingNormally( | 98 virtual void StartSyncingNormally( |
83 const ModelSafeRoutingInfo& routing_info) OVERRIDE; | 99 const ModelSafeRoutingInfo& routing_info) OVERRIDE; |
84 virtual void SetEncryptionPassphrase(const std::string& passphrase, | 100 virtual void SetEncryptionPassphrase(const std::string& passphrase, |
85 bool is_explicit) OVERRIDE; | 101 bool is_explicit) OVERRIDE; |
86 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; | 102 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; |
87 virtual void ConfigureSyncer( | 103 virtual void ConfigureSyncer( |
88 ConfigureReason reason, | 104 ConfigureReason reason, |
89 const ModelTypeSet& types_to_config, | 105 const ModelTypeSet& types_to_config, |
90 const ModelSafeRoutingInfo& new_routing_info, | 106 const ModelSafeRoutingInfo& new_routing_info, |
91 const base::Closure& ready_task, | 107 const base::Closure& ready_task, |
92 const base::Closure& retry_task) OVERRIDE; | 108 const base::Closure& retry_task) OVERRIDE; |
93 virtual void AddObserver(Observer* observer) OVERRIDE; | 109 virtual void AddObserver(Observer* observer) OVERRIDE; |
94 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 110 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
95 virtual SyncStatus GetDetailedStatus() const OVERRIDE; | 111 virtual SyncStatus GetDetailedStatus() const OVERRIDE; |
96 virtual bool IsUsingExplicitPassphrase() OVERRIDE; | 112 virtual bool IsUsingExplicitPassphrase() OVERRIDE; |
97 virtual void SaveChanges() OVERRIDE; | 113 virtual void SaveChanges() OVERRIDE; |
98 virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE; | 114 virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE; |
99 virtual void ShutdownOnSyncThread() OVERRIDE; | 115 virtual void ShutdownOnSyncThread() OVERRIDE; |
100 virtual UserShare* GetUserShare() OVERRIDE; | 116 virtual UserShare* GetUserShare() OVERRIDE; |
101 virtual void RefreshNigori(const std::string& chrome_version, | 117 virtual void RefreshNigori(const std::string& chrome_version, |
102 const base::Closure& done_callback) OVERRIDE; | 118 const base::Closure& done_callback) OVERRIDE; |
103 virtual void EnableEncryptEverything() OVERRIDE; | 119 virtual void EnableEncryptEverything() OVERRIDE; |
104 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; | 120 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; |
105 virtual bool HasUnsyncedItems() OVERRIDE; | 121 virtual bool HasUnsyncedItems() OVERRIDE; |
106 | 122 |
107 private: | 123 private: |
| 124 void InvalidateOnSyncThread( |
| 125 const ObjectIdPayloadMap& id_payloads, |
| 126 IncomingNotificationSource source); |
| 127 void EnableNotificationsOnSyncThread(); |
| 128 void DisableNotificationsOnSyncThread(NotificationsDisabledReason reason); |
| 129 |
| 130 scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; |
| 131 |
108 ObserverList<SyncManager::Observer> observers_; | 132 ObserverList<SyncManager::Observer> observers_; |
109 | 133 |
110 // Faked directory state. | 134 // Faked directory state. |
111 ModelTypeSet initial_sync_ended_types_; | 135 ModelTypeSet initial_sync_ended_types_; |
112 ModelTypeSet progress_marker_types_; | 136 ModelTypeSet progress_marker_types_; |
113 | 137 |
114 // Test specific state. | 138 // Test specific state. |
115 // The types that should fail configuration attempts. These types will not | 139 // The types that should fail configuration attempts. These types will not |
116 // have their progress markers or initial_sync_ended bits set. | 140 // have their progress markers or initial_sync_ended bits set. |
117 ModelTypeSet configure_fail_types_; | 141 ModelTypeSet configure_fail_types_; |
118 // The set of types that have been cleaned up. | 142 // The set of types that have been cleaned up. |
119 ModelTypeSet cleaned_types_; | 143 ModelTypeSet cleaned_types_; |
120 // The set of types that have been downloaded. | 144 // The set of types that have been downloaded. |
121 ModelTypeSet downloaded_types_; | 145 ModelTypeSet downloaded_types_; |
122 // The set of types that have been enabled. | 146 // The set of types that have been enabled. |
123 ModelTypeSet enabled_types_; | 147 ModelTypeSet enabled_types_; |
124 | 148 |
125 // For StopSyncingForShutdown's callback. | 149 // Faked notifier state. |
126 MessageLoop* sync_loop_; | 150 SyncNotifierHelper notifier_helper_; |
127 | 151 |
128 DISALLOW_COPY_AND_ASSIGN(FakeSyncManager); | 152 DISALLOW_COPY_AND_ASSIGN(FakeSyncManager); |
129 }; | 153 }; |
130 | 154 |
131 } // namespace syncer | 155 } // namespace syncer |
132 | 156 |
133 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ | 157 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_ |
OLD | NEW |