summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/sync_manager_impl.h
diff options
context:
space:
mode:
authorzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-17 20:12:15 +0000
committerzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-17 20:12:15 +0000
commitceffdf01e68f732b0aa5731274dbf3d32a27ffde (patch)
tree22976ce293d7bdfd20871a2d1f28524d441157cf /sync/internal_api/sync_manager_impl.h
parent3cf1e5d278ee73b5c3365b35614091858b9f5d1a (diff)
downloadchromium_src-ceffdf01e68f732b0aa5731274dbf3d32a27ffde.zip
chromium_src-ceffdf01e68f732b0aa5731274dbf3d32a27ffde.tar.gz
chromium_src-ceffdf01e68f732b0aa5731274dbf3d32a27ffde.tar.bz2
[Sync] Refactor sync manager into interface.
sync_manager.h now defines a pure interface. The actual implementation is in sync_manager_impl.h/cc. In order to support this, we also create a SyncManagerFactory, which allows us to dependency inject a SyncManager implementation into the SyncBackendHost. Follow up patches will make use of this injection, as well as split the SyncManager tests out of syncapi_unittest. R=akalin@chromium.org BUG=133061 TEST= Review URL: https://chromiumcodereview.appspot.com/10704214 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/sync_manager_impl.h')
-rw-r--r--sync/internal_api/sync_manager_impl.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h
new file mode 100644
index 0000000..783822d
--- /dev/null
+++ b/sync/internal_api/sync_manager_impl.h
@@ -0,0 +1,128 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_INTERNAL_API_SYNC_MANAGER_H_
+#define SYNC_INTERNAL_API_SYNC_MANAGER_H_
+
+#include <string>
+#include <vector>
+
+#include "sync/internal_api/public/sync_manager.h"
+
+namespace syncer {
+
+// SyncManager encapsulates syncable::Directory and serves as the parent of all
+// other objects in the sync API. If multiple threads interact with the same
+// local sync repository (i.e. the same sqlite database), they should share a
+// single SyncManager instance. The caller should typically create one
+// SyncManager for the lifetime of a user session.
+//
+// Unless stated otherwise, all methods of SyncManager should be called on the
+// same thread.
+class SyncManagerImpl : public SyncManager {
+ public:
+ // SyncInternal contains the implementation of SyncManager, while abstracting
+ // internal types from clients of the interface.
+ class SyncInternal;
+
+ // Create an uninitialized SyncManager. Callers must Init() before using.
+ explicit SyncManagerImpl(const std::string& name);
+ virtual ~SyncManagerImpl();
+
+ // SyncManager implementation.
+ virtual bool Init(
+ const FilePath& database_location,
+ const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
+ const std::string& sync_server_and_path,
+ int sync_server_port,
+ bool use_ssl,
+ const scoped_refptr<base::TaskRunner>& blocking_task_runner,
+ scoped_ptr<HttpPostProviderFactory> post_factory,
+ const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
+ const std::vector<syncer::ModelSafeWorker*>& workers,
+ syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
+ SyncManager::ChangeDelegate* change_delegate,
+ const SyncCredentials& credentials,
+ scoped_ptr<syncer::SyncNotifier> sync_notifier,
+ const std::string& restored_key_for_bootstrapping,
+ TestingMode testing_mode,
+ syncer::Encryptor* encryptor,
+ syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
+ syncer::ReportUnrecoverableErrorFunction
+ report_unrecoverable_error_function) OVERRIDE;
+ virtual void ThrowUnrecoverableError() OVERRIDE;
+ virtual syncer::ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
+ virtual syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
+ syncer::ModelTypeSet types) OVERRIDE;
+ virtual bool PurgePartiallySyncedTypes() OVERRIDE;
+ virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
+ virtual void UpdateEnabledTypes(
+ const syncer::ModelTypeSet& enabled_types) OVERRIDE;
+ virtual void StartSyncingNormally(
+ const syncer::ModelSafeRoutingInfo& routing_info) OVERRIDE;
+ virtual void SetEncryptionPassphrase(const std::string& passphrase,
+ bool is_explicit) OVERRIDE;
+ virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE;
+ virtual void ConfigureSyncer(
+ ConfigureReason reason,
+ const syncer::ModelTypeSet& types_to_config,
+ const syncer::ModelSafeRoutingInfo& new_routing_info,
+ const base::Closure& ready_task,
+ const base::Closure& retry_task) OVERRIDE;
+ virtual void AddObserver(Observer* observer) OVERRIDE;
+ virtual void RemoveObserver(Observer* observer) OVERRIDE;
+ virtual SyncStatus GetDetailedStatus() const OVERRIDE;
+ virtual bool IsUsingExplicitPassphrase() OVERRIDE;
+ virtual void SaveChanges() OVERRIDE;
+ virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE;
+ virtual void ShutdownOnSyncThread() OVERRIDE;
+ virtual UserShare* GetUserShare() const OVERRIDE;
+ virtual void RefreshNigori(const std::string& chrome_version,
+ const base::Closure& done_callback) OVERRIDE;
+ virtual void EnableEncryptEverything() OVERRIDE;
+ virtual bool ReceivedExperiment(
+ syncer::Experiments* experiments) const OVERRIDE;
+ virtual bool HasUnsyncedItems() const OVERRIDE;
+
+ // Functions used for testing.
+
+ // Returns true if we are currently encrypting all sync data. May
+ // be called on any thread.
+ bool EncryptEverythingEnabledForTest() const;
+
+ // Gets the set of encrypted types from the cryptographer
+ // Note: opens a transaction. May be called from any thread.
+ syncer::ModelTypeSet GetEncryptedDataTypesForTest() const;
+
+ void SimulateEnableNotificationsForTest();
+ void SimulateDisableNotificationsForTest(int reason);
+ void TriggerOnIncomingNotificationForTest(syncer::ModelTypeSet model_types);
+
+ static int GetDefaultNudgeDelay();
+ static int GetPreferencesNudgeDelay();
+
+ private:
+ friend class SyncManagerTest;
+ FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest);
+ FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, OnNotificationStateChange);
+ FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, OnIncomingNotification);
+
+ base::TimeDelta GetNudgeDelayTimeDelta(const syncer::ModelType& model_type);
+
+ // Set the internal scheduler for testing purposes.
+ // TODO(sync): Use dependency injection instead. crbug.com/133061
+ void SetSyncSchedulerForTest(
+ scoped_ptr<syncer::SyncScheduler> scheduler);
+
+ base::ThreadChecker thread_checker_;
+
+ // An opaque pointer to the nested private class.
+ SyncInternal* data_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl);
+};
+
+} // namespace syncer
+
+#endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_