Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / sync_driver / sync_service.h
blob2d416cce304cdfb57178c1679c7c8505cb4db056
1 // Copyright 2015 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.
5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_
6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/time/time.h"
12 #include "components/sync_driver/data_type_encryption_handler.h"
13 #include "components/sync_driver/sync_service_observer.h"
14 #include "sync/internal_api/public/base/model_type.h"
16 class GoogleServiceAuthError;
18 namespace syncer {
19 class BaseTransaction;
20 struct UserShare;
23 namespace sync_driver {
25 class DataTypeController;
26 class LocalDeviceInfoProvider;
27 class OpenTabsUIDelegate;
29 class SyncService : public DataTypeEncryptionHandler {
30 public:
31 // Used to specify the kind of passphrase with which sync data is encrypted.
32 enum PassphraseType {
33 IMPLICIT, // The user did not provide a custom passphrase for encryption.
34 // We implicitly use the GAIA password in such cases.
35 EXPLICIT, // The user selected the "use custom passphrase" radio button
36 // during sync setup and provided a passphrase.
39 // Passed as an argument to RequestStop to control whether or not the sync
40 // backend should clear its data directory when it shuts down. See
41 // RequestStop for more information.
42 enum SyncStopDataFate {
43 KEEP_DATA,
44 CLEAR_DATA,
47 ~SyncService() override {}
49 // Whether sync is enabled by user or not. This does not necessarily mean
50 // that sync is currently running (due to delayed startup, unrecoverable
51 // errors, or shutdown). See IsSyncActive below for checking whether sync
52 // is actually running.
53 virtual bool HasSyncSetupCompleted() const = 0;
55 // Whether sync is allowed to start. Command line flags, platform-level
56 // overrides, and account-level overrides are examples of reasons this
57 // might be false.
58 virtual bool IsSyncAllowed() const = 0;
60 // Returns true if sync is fully initialized and active. This implies that
61 // an initial configuration has successfully completed, although there may
62 // be datatype specific, auth, or other transient errors. To see which
63 // datetypes are actually syncing, see GetActiveTypes() below.
64 // Note that if sync is in backup or rollback mode, IsSyncActive() will be
65 // false.
66 virtual bool IsSyncActive() const = 0;
68 // Get the set of current active data types (those chosen or configured by
69 // the user which have not also encountered a runtime error).
70 // Note that if the Sync engine is in the middle of a configuration, this
71 // will the the empty set. Once the configuration completes the set will
72 // be updated.
73 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0;
75 // Adds/removes an observer. SyncService does not take ownership of the
76 // observer.
77 virtual void AddObserver(SyncServiceObserver* observer) = 0;
78 virtual void RemoveObserver(SyncServiceObserver* observer) = 0;
80 // Returns true if |observer| has already been added as an observer.
81 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0;
83 // ---------------------------------------------------------------------------
84 // TODO(sync): The methods below were pulled from ProfileSyncService, and
85 // should be evaluated to see if they should stay.
87 // Called when a datatype (SyncableService) has a need for sync to start
88 // ASAP, presumably because a local change event has occurred but we're
89 // still in deferred start mode, meaning the SyncableService hasn't been
90 // told to MergeDataAndStartSyncing yet.
91 virtual void OnDataTypeRequestsSyncStartup(syncer::ModelType type) = 0;
93 // Returns true if sync is allowed, requested, and the user is logged in.
94 // (being logged in does not mean that tokens are available - tokens may
95 // be missing because they have not loaded yet, or because they were deleted
96 // due to http://crbug.com/121755).
97 virtual bool CanSyncStart() const = 0;
99 // Stops sync at the user's request. |data_fate| controls whether the sync
100 // backend should clear its data directory when it shuts down. Generally
101 // KEEP_DATA is used when the user just stops sync, and CLEAR_DATA is used
102 // when they sign out of the profile entirely.
103 virtual void RequestStop(SyncStopDataFate data_fate) = 0;
105 // The user requests that sync start. This only actually starts sync if
106 // IsSyncAllowed is true and the user is signed in. Once sync starts,
107 // other things such as HasSyncSetupCompleted being false can still prevent
108 // it from moving into the "active" state.
109 virtual void RequestStart() = 0;
111 // Returns the set of types which are preferred for enabling. This is a
112 // superset of the active types (see GetActiveDataTypes()).
113 virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0;
115 // Called when a user chooses which data types to sync as part of the sync
116 // setup wizard. |sync_everything| represents whether they chose the
117 // "keep everything synced" option; if true, |chosen_types| will be ignored
118 // and all data types will be synced. |sync_everything| means "sync all
119 // current and future data types."
120 virtual void OnUserChoseDatatypes(bool sync_everything,
121 syncer::ModelTypeSet chosen_types) = 0;
123 // Called whe Sync has been setup by the user and can be started.
124 virtual void SetSyncSetupCompleted() = 0;
126 // Returns true if initial sync setup is in progress (does not return true
127 // if the user is customizing sync after already completing setup once).
128 // SyncService uses this to determine if it's OK to start syncing, or if the
129 // user is still setting up the initial sync configuration.
130 virtual bool FirstSetupInProgress() const = 0;
132 // Called by the UI to notify the SyncService that UI is visible so it will
133 // not start syncing. This tells sync whether it's safe to start downloading
134 // data types yet (we don't start syncing until after sync setup is complete).
135 // The UI calls this as soon as any part of the signin wizard is displayed
136 // (even just the login UI).
137 // If |setup_in_progress| is false, this also kicks the sync engine to ensure
138 // that data download starts. In this case, |ReconfigureDatatypeManager| will
139 // get triggered.
140 virtual void SetSetupInProgress(bool setup_in_progress) = 0;
142 // Used by tests.
143 virtual bool setup_in_progress() const = 0;
145 // Whether the data types active for the current mode have finished
146 // configuration.
147 virtual bool ConfigurationDone() const = 0;
149 virtual const GoogleServiceAuthError& GetAuthError() const = 0;
150 virtual bool HasUnrecoverableError() const = 0;
152 // Returns true if the SyncBackendHost has told us it's ready to accept
153 // changes. This should only be used for sync's internal configuration logic
154 // (such as deciding when to prompt for an encryption passphrase).
155 virtual bool backend_initialized() const = 0;
157 // Return the active OpenTabsUIDelegate. If sessions is not enabled or not
158 // currently syncing, returns nullptr.
159 virtual OpenTabsUIDelegate* GetOpenTabsUIDelegate() = 0;
161 // Returns true if OnPassphraseRequired has been called for decryption and
162 // we have an encrypted data type enabled.
163 virtual bool IsPassphraseRequiredForDecryption() const = 0;
165 // Returns the time the current explicit passphrase (if any), was set.
166 // If no secondary passphrase is in use, or no time is available, returns an
167 // unset base::Time.
168 virtual base::Time GetExplicitPassphraseTime() const = 0;
170 // Returns true if a secondary (explicit) passphrase is being used. It is not
171 // legal to call this method before the backend is initialized.
172 virtual bool IsUsingSecondaryPassphrase() const = 0;
174 // Turns on encryption for all data. Callers must call OnUserChoseDatatypes()
175 // after calling this to force the encryption to occur.
176 virtual void EnableEncryptEverything() = 0;
178 // Returns true if we are currently set to encrypt all the sync data.
179 virtual bool EncryptEverythingEnabled() const = 0;
181 // Asynchronously sets the passphrase to |passphrase| for encryption. |type|
182 // specifies whether the passphrase is a custom passphrase or the GAIA
183 // password being reused as a passphrase.
184 // TODO(atwilson): Change this so external callers can only set an EXPLICIT
185 // passphrase with this API.
186 virtual void SetEncryptionPassphrase(const std::string& passphrase,
187 PassphraseType type) = 0;
189 // Asynchronously decrypts pending keys using |passphrase|. Returns false
190 // immediately if the passphrase could not be used to decrypt a locally cached
191 // copy of encrypted keys; returns true otherwise.
192 virtual bool SetDecryptionPassphrase(const std::string& passphrase)
193 WARN_UNUSED_RESULT = 0;
195 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
196 // for sensitive data types. Caller must be holding a
197 // syncapi::BaseTransaction to ensure thread safety.
198 virtual bool IsCryptographerReady(
199 const syncer::BaseTransaction* trans) const = 0;
201 // TODO(akalin): This is called mostly by ModelAssociators and
202 // tests. Figure out how to pass the handle to the ModelAssociators
203 // directly, figure out how to expose this to tests, and remove this
204 // function.
205 virtual syncer::UserShare* GetUserShare() const = 0;
207 // Returns DeviceInfo provider for the local device.
208 virtual LocalDeviceInfoProvider* GetLocalDeviceInfoProvider() const = 0;
210 // Registers a data type controller with the sync service. This
211 // makes the data type controller available for use, it does not
212 // enable or activate the synchronization of the data type (see
213 // ActivateDataType). Takes ownership of the pointer.
214 virtual void RegisterDataTypeController(
215 DataTypeController* data_type_controller) = 0;
217 // Called to re-enable a type disabled by DisableDatatype(..). Note, this does
218 // not change the preferred state of a datatype, and is not persisted across
219 // restarts.
220 virtual void ReenableDatatype(syncer::ModelType type) = 0;
222 // TODO(zea): Remove these and have the dtc's call directly into the SBH.
223 virtual void DeactivateDataType(syncer::ModelType type) = 0;
225 protected:
226 SyncService() {}
228 private:
229 DISALLOW_COPY_AND_ASSIGN(SyncService);
232 } // namespace sync_driver
234 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_