• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/ref_counted.h"
11 #include "base/observer_list.h"
12 #include "sync/internal_api/public/sync_manager.h"
13 #include "sync/internal_api/public/test/null_sync_core_proxy.h"
14 #include "sync/internal_api/public/test/test_user_share.h"
15 
16 namespace base {
17 class SequencedTaskRunner;
18 }
19 
20 namespace syncer {
21 
22 class FakeSyncEncryptionHandler;
23 
24 class FakeSyncManager : public SyncManager {
25  public:
26   // |initial_sync_ended_types|: The set of types that have initial_sync_ended
27   // set to true. This value will be used by InitialSyncEndedTypes() until the
28   // next configuration is performed.
29   //
30   // |progress_marker_types|: The set of types that have valid progress
31   // markers. This will be used by GetTypesWithEmptyProgressMarkerToken() until
32   // the next configuration is performed.
33   //
34   // |configure_fail_types|: The set of types that will fail
35   // configuration. Once ConfigureSyncer is called, the
36   // |initial_sync_ended_types_| and |progress_marker_types_| will be updated
37   // to include those types that didn't fail.
38   FakeSyncManager(ModelTypeSet initial_sync_ended_types,
39                   ModelTypeSet progress_marker_types,
40                   ModelTypeSet configure_fail_types);
41   virtual ~FakeSyncManager();
42 
43   // Returns those types that have been cleaned (purged from the directory)
44   // since the last call to GetAndResetCleanedTypes(), or since startup if never
45   // called.
46   ModelTypeSet GetAndResetCleanedTypes();
47 
48   // Returns those types that have been downloaded since the last call to
49   // GetAndResetDownloadedTypes(), or since startup if never called.
50   ModelTypeSet GetAndResetDownloadedTypes();
51 
52   // Returns those types that have been marked as enabled since the
53   // last call to GetAndResetEnabledTypes(), or since startup if never
54   // called.
55   ModelTypeSet GetAndResetEnabledTypes();
56 
57   // Returns the types that have most recently received a refresh request.
58   ModelTypeSet GetLastRefreshRequestTypes();
59 
60   // Returns the most recent configuration reason since the last call to
61   // GetAndResetConfigureReason, or since startup if never called.
62   ConfigureReason GetAndResetConfigureReason();
63 
64   // Posts a method to invalidate the given IDs on the sync thread.
65   virtual void OnIncomingInvalidation(
66       const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
67 
68   // Posts a method to update the invalidator state on the sync thread.
69   virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
70 
71   // Returns this class name for logging purposes.
72   virtual std::string GetOwnerName() const OVERRIDE;
73 
74   // Block until the sync thread has finished processing any pending messages.
75   void WaitForSyncThread();
76 
77   // SyncManager implementation.
78   // Note: we treat whatever message loop this is called from as the sync
79   // loop for purposes of callbacks.
80   virtual void Init(
81       const base::FilePath& database_location,
82       const WeakHandle<JsEventHandler>& event_handler,
83       const std::string& sync_server_and_path,
84       int sync_server_port,
85       bool use_ssl,
86       scoped_ptr<HttpPostProviderFactory> post_factory,
87       const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
88       ExtensionsActivity* extensions_activity,
89       ChangeDelegate* change_delegate,
90       const SyncCredentials& credentials,
91       const std::string& invalidator_client_id,
92       const std::string& restored_key_for_bootstrapping,
93       const std::string& restored_keystore_key_for_bootstrapping,
94       InternalComponentsFactory* internal_components_factory,
95       Encryptor* encryptor,
96       scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
97       ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
98       CancelationSignal* cancelation_signal) OVERRIDE;
99   virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
100   virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
101       ModelTypeSet types) OVERRIDE;
102   virtual bool PurgePartiallySyncedTypes() OVERRIDE;
103   virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
104   virtual void StartSyncingNormally(
105       const ModelSafeRoutingInfo& routing_info) OVERRIDE;
106   virtual void ConfigureSyncer(
107       ConfigureReason reason,
108       ModelTypeSet to_download,
109       ModelTypeSet to_purge,
110       ModelTypeSet to_journal,
111       ModelTypeSet to_unapply,
112       const ModelSafeRoutingInfo& new_routing_info,
113       const base::Closure& ready_task,
114       const base::Closure& retry_task) OVERRIDE;
115   virtual void AddObserver(Observer* observer) OVERRIDE;
116   virtual void RemoveObserver(Observer* observer) OVERRIDE;
117   virtual SyncStatus GetDetailedStatus() const OVERRIDE;
118   virtual void SaveChanges() OVERRIDE;
119   virtual void ShutdownOnSyncThread() OVERRIDE;
120   virtual UserShare* GetUserShare() OVERRIDE;
121   virtual syncer::SyncCoreProxy* GetSyncCoreProxy() OVERRIDE;
122   virtual const std::string cache_guid() OVERRIDE;
123   virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE;
124   virtual bool HasUnsyncedItems() OVERRIDE;
125   virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE;
126   virtual ScopedVector<syncer::ProtocolEvent>
127       GetBufferedProtocolEvents() OVERRIDE;
128   virtual scoped_ptr<base::ListValue> GetAllNodesForType(
129       syncer::ModelType type) OVERRIDE;
130   virtual void RefreshTypes(ModelTypeSet types) OVERRIDE;
131   virtual void RegisterDirectoryTypeDebugInfoObserver(
132       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
133   virtual void UnregisterDirectoryTypeDebugInfoObserver(
134       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
135   virtual bool HasDirectoryTypeDebugInfoObserver(
136       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
137   virtual void RequestEmitDebugInfo() OVERRIDE;
138 
139  private:
140   scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
141 
142   ObserverList<SyncManager::Observer> observers_;
143 
144   // Faked directory state.
145   ModelTypeSet initial_sync_ended_types_;
146   ModelTypeSet progress_marker_types_;
147 
148   // Test specific state.
149   // The types that should fail configuration attempts. These types will not
150   // have their progress markers or initial_sync_ended bits set.
151   ModelTypeSet configure_fail_types_;
152   // The set of types that have been cleaned up.
153   ModelTypeSet cleaned_types_;
154   // The set of types that have been downloaded.
155   ModelTypeSet downloaded_types_;
156   // The set of types that have been enabled.
157   ModelTypeSet enabled_types_;
158 
159   // The types for which a refresh was most recently requested.
160   ModelTypeSet last_refresh_request_types_;
161 
162   // The most recent configure reason.
163   ConfigureReason last_configure_reason_;
164 
165   scoped_ptr<FakeSyncEncryptionHandler> fake_encryption_handler_;
166 
167   TestUserShare test_user_share_;
168 
169   NullSyncCoreProxy null_sync_core_proxy_;
170 
171   DISALLOW_COPY_AND_ASSIGN(FakeSyncManager);
172 };
173 
174 }  // namespace syncer
175 
176 #endif  // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_
177