fake_sync_manager.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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/test_user_share.h"
14#include "sync/notifier/invalidator_registrar.h"
15
16namespace base {
17class SequencedTaskRunner;
18}
19
20namespace syncer {
21
22class FakeSyncEncryptionHandler;
23
24class 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  void Invalidate(const ObjectIdInvalidationMap& invalidation_map);
66
67  // Posts a method to update the invalidator state on the sync thread.
68  void UpdateInvalidatorState(InvalidatorState state);
69
70  // Block until the sync thread has finished processing any pending messages.
71  void WaitForSyncThread();
72
73  // SyncManager implementation.
74  // Note: we treat whatever message loop this is called from as the sync
75  // loop for purposes of callbacks.
76  virtual void Init(
77      const base::FilePath& database_location,
78      const WeakHandle<JsEventHandler>& event_handler,
79      const std::string& sync_server_and_path,
80      int sync_server_port,
81      bool use_ssl,
82      scoped_ptr<HttpPostProviderFactory> post_factory,
83      const std::vector<ModelSafeWorker*>& workers,
84      ExtensionsActivityMonitor* extensions_activity_monitor,
85      ChangeDelegate* change_delegate,
86      const SyncCredentials& credentials,
87      scoped_ptr<Invalidator> invalidator,
88      const std::string& invalidator_client_id,
89      const std::string& restored_key_for_bootstrapping,
90      const std::string& restored_keystore_key_for_bootstrapping,
91      scoped_ptr<InternalComponentsFactory> internal_components_factory,
92      Encryptor* encryptor,
93      UnrecoverableErrorHandler* unrecoverable_error_handler,
94      ReportUnrecoverableErrorFunction
95          report_unrecoverable_error_function,
96      bool use_oauth2_token) OVERRIDE;
97  virtual void ThrowUnrecoverableError() OVERRIDE;
98  virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
99  virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
100      ModelTypeSet types) OVERRIDE;
101  virtual bool PurgePartiallySyncedTypes() OVERRIDE;
102  virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
103  virtual void UpdateEnabledTypes(ModelTypeSet types) OVERRIDE;
104  virtual void RegisterInvalidationHandler(
105      InvalidationHandler* handler) OVERRIDE;
106  virtual void UpdateRegisteredInvalidationIds(
107      InvalidationHandler* handler,
108      const ObjectIdSet& ids) OVERRIDE;
109  virtual void UnregisterInvalidationHandler(
110      InvalidationHandler* handler) OVERRIDE;
111  virtual void AcknowledgeInvalidation(
112      const invalidation::ObjectId& id,
113      const syncer::AckHandle& ack_handle) OVERRIDE;
114  virtual void StartSyncingNormally(
115      const ModelSafeRoutingInfo& routing_info) OVERRIDE;
116  virtual void ConfigureSyncer(
117      ConfigureReason reason,
118      ModelTypeSet to_download,
119      ModelTypeSet to_journal,
120      ModelTypeSet to_unapply,
121      ModelTypeSet to_ignore,
122      const ModelSafeRoutingInfo& new_routing_info,
123      const base::Closure& ready_task,
124      const base::Closure& retry_task) OVERRIDE;
125  virtual void AddObserver(Observer* observer) OVERRIDE;
126  virtual void RemoveObserver(Observer* observer) OVERRIDE;
127  virtual SyncStatus GetDetailedStatus() const OVERRIDE;
128  virtual void SaveChanges() OVERRIDE;
129  virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE;
130  virtual void ShutdownOnSyncThread() OVERRIDE;
131  virtual UserShare* GetUserShare() OVERRIDE;
132  virtual const std::string cache_guid() OVERRIDE;
133  virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE;
134  virtual bool HasUnsyncedItems() OVERRIDE;
135  virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE;
136  virtual void RefreshTypes(ModelTypeSet types) OVERRIDE;
137
138 private:
139  void InvalidateOnSyncThread(
140      const ObjectIdInvalidationMap& invalidation_map);
141  void UpdateInvalidatorStateOnSyncThread(InvalidatorState state);
142
143  scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
144
145  ObserverList<SyncManager::Observer> observers_;
146
147  // Faked directory state.
148  ModelTypeSet initial_sync_ended_types_;
149  ModelTypeSet progress_marker_types_;
150
151  // Test specific state.
152  // The types that should fail configuration attempts. These types will not
153  // have their progress markers or initial_sync_ended bits set.
154  ModelTypeSet configure_fail_types_;
155  // The set of types that have been cleaned up.
156  ModelTypeSet cleaned_types_;
157  // The set of types that have been downloaded.
158  ModelTypeSet downloaded_types_;
159  // The set of types that have been enabled.
160  ModelTypeSet enabled_types_;
161
162  // Faked invalidator state.
163  InvalidatorRegistrar registrar_;
164
165  // The types for which a refresh was most recently requested.
166  ModelTypeSet last_refresh_request_types_;
167
168  // The most recent configure reason.
169  ConfigureReason last_configure_reason_;
170
171  scoped_ptr<FakeSyncEncryptionHandler> fake_encryption_handler_;
172
173  TestUserShare test_user_share_;
174
175  DISALLOW_COPY_AND_ASSIGN(FakeSyncManager);
176};
177
178}  // namespace syncer
179
180#endif  // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_MANAGER_H_
181