Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: sync/internal_api/sync_manager_impl.h

Issue 10704214: [Sync] Refactor sync manager into interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_SYNC_MANAGER_H_
6 #define SYNC_INTERNAL_API_SYNC_MANAGER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "sync/internal_api/public/sync_manager.h"
12
13 namespace syncer {
14
15 // SyncManager encapsulates syncable::Directory and serves as the parent of all
16 // other objects in the sync API. If multiple threads interact with the same
17 // local sync repository (i.e. the same sqlite database), they should share a
18 // single SyncManager instance. The caller should typically create one
19 // SyncManager for the lifetime of a user session.
20 //
21 // Unless stated otherwise, all methods of SyncManager should be called on the
22 // same thread.
23 class SyncManagerImpl : public SyncManager {
24 public:
25 // SyncInternal contains the implementation of SyncManager, while abstracting
26 // internal types from clients of the interface.
27 class SyncInternal;
28
29 // Create an uninitialized SyncManager. Callers must Init() before using.
30 explicit SyncManagerImpl(const std::string& name);
31 virtual ~SyncManagerImpl();
32
33 // SyncManager implementation.
34 virtual bool Init(
35 const FilePath& database_location,
36 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
37 const std::string& sync_server_and_path,
38 int sync_server_port,
39 bool use_ssl,
40 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
41 scoped_ptr<HttpPostProviderFactory> post_factory,
42 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
43 const std::vector<syncer::ModelSafeWorker*>& workers,
44 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
45 SyncManager::ChangeDelegate* change_delegate,
46 const SyncCredentials& credentials,
47 scoped_ptr<syncer::SyncNotifier> sync_notifier,
48 const std::string& restored_key_for_bootstrapping,
49 TestingMode testing_mode,
50 syncer::Encryptor* encryptor,
51 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler,
52 syncer::ReportUnrecoverableErrorFunction
53 report_unrecoverable_error_function) OVERRIDE;
54 virtual void ThrowUnrecoverableError() OVERRIDE;
55 virtual syncer::ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
56 virtual syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
57 syncer::ModelTypeSet types) OVERRIDE;
58 virtual bool PurgePartiallySyncedTypes() OVERRIDE;
59 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
60 virtual void UpdateEnabledTypes(
61 const syncer::ModelTypeSet& enabled_types) OVERRIDE;
62 virtual void StartSyncingNormally(
63 const syncer::ModelSafeRoutingInfo& routing_info) OVERRIDE;
64 virtual void SetEncryptionPassphrase(const std::string& passphrase,
65 bool is_explicit) OVERRIDE;
66 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE;
67 virtual void ConfigureSyncer(
68 ConfigureReason reason,
69 const syncer::ModelTypeSet& types_to_config,
70 const syncer::ModelSafeRoutingInfo& new_routing_info,
71 const base::Closure& ready_task,
72 const base::Closure& retry_task) OVERRIDE;
73 virtual void AddObserver(Observer* observer) OVERRIDE;
74 virtual void RemoveObserver(Observer* observer) OVERRIDE;
75 virtual SyncStatus GetDetailedStatus() const OVERRIDE;
76 virtual bool IsUsingExplicitPassphrase() OVERRIDE;
77 virtual void SaveChanges() OVERRIDE;
78 virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE;
79 virtual void ShutdownOnSyncThread() OVERRIDE;
80 virtual UserShare* GetUserShare() const OVERRIDE;
81 virtual void RefreshNigori(const std::string& chrome_version,
82 const base::Closure& done_callback) OVERRIDE;
83 virtual void EnableEncryptEverything() OVERRIDE;
84 virtual bool ReceivedExperiment(
85 syncer::Experiments* experiments) const OVERRIDE;
86 virtual bool HasUnsyncedItems() const OVERRIDE;
87
88 // Functions used for testing.
89
90 // Returns true if we are currently encrypting all sync data. May
91 // be called on any thread.
92 bool EncryptEverythingEnabledForTest() const;
93
94 // Gets the set of encrypted types from the cryptographer
95 // Note: opens a transaction. May be called from any thread.
96 syncer::ModelTypeSet GetEncryptedDataTypesForTest() const;
97
98 void SimulateEnableNotificationsForTest();
99 void SimulateDisableNotificationsForTest(int reason);
100 void TriggerOnIncomingNotificationForTest(syncer::ModelTypeSet model_types);
101
102 static int GetDefaultNudgeDelay();
103 static int GetPreferencesNudgeDelay();
104
105 private:
106 friend class SyncManagerTest;
107 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest);
108 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, OnNotificationStateChange);
109 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, OnIncomingNotification);
110
111 base::TimeDelta GetNudgeDelayTimeDelta(const syncer::ModelType& model_type);
112
113 // Set the internal scheduler for testing purposes.
114 // TODO(sync): Use dependency injection instead. crbug.com/133061
115 void SetSyncSchedulerForTest(
116 scoped_ptr<syncer::SyncScheduler> scheduler);
117
118 base::ThreadChecker thread_checker_;
119
120 // An opaque pointer to the nested private class.
121 SyncInternal* data_;
122
123 DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl);
124 };
125
126 } // namespace syncer
127
128 #endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698