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_
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 sync_driver
{
20 class SyncService
: public sync_driver::DataTypeEncryptionHandler
{
22 // Used to specify the kind of passphrase with which sync data is encrypted.
24 IMPLICIT
, // The user did not provide a custom passphrase for encryption.
25 // We implicitly use the GAIA password in such cases.
26 EXPLICIT
, // The user selected the "use custom passphrase" radio button
27 // during sync setup and provided a passphrase.
30 ~SyncService() override
{}
32 // Whether sync is enabled by user or not. This does not necessarily mean
33 // that sync is currently running (due to delayed startup, unrecoverable
34 // errors, or shutdown). See IsSyncActive below for checking whether sync
35 // is actually running.
36 virtual bool HasSyncSetupCompleted() const = 0;
38 // Whether sync is allowed to start. Command line flags, platform-level
39 // overrides, and account-level overrides are examples of reasons this
41 virtual bool IsSyncAllowed() const = 0;
43 // Returns true if sync is fully initialized and active. This implies that
44 // an initial configuration has successfully completed, although there may
45 // be datatype specific, auth, or other transient errors. To see which
46 // datetypes are actually syncing, see GetActiveTypes() below.
47 // Note that if sync is in backup or rollback mode, IsSyncActive() will be
49 virtual bool IsSyncActive() const = 0;
51 // Get the set of current active data types (those chosen or configured by
52 // the user which have not also encountered a runtime error).
53 // Note that if the Sync engine is in the middle of a configuration, this
54 // will the the empty set. Once the configuration completes the set will
56 virtual syncer::ModelTypeSet
GetActiveDataTypes() const = 0;
58 // Adds/removes an observer. SyncService does not take ownership of the
60 virtual void AddObserver(SyncServiceObserver
* observer
) = 0;
61 virtual void RemoveObserver(SyncServiceObserver
* observer
) = 0;
63 // Returns true if |observer| has already been added as an observer.
64 virtual bool HasObserver(const SyncServiceObserver
* observer
) const = 0;
66 // ---------------------------------------------------------------------------
67 // TODO(sync): The methods below were pulled from ProfileSyncService, and
68 // should be evaluated to see if they should stay.
70 // Returns true if sync is enabled/not suppressed and the user is logged in.
71 // (being logged in does not mean that tokens are available - tokens may
72 // be missing because they have not loaded yet, or because they were deleted
73 // due to http://crbug.com/121755).
74 // Virtual to enable mocking in tests.
75 // TODO(tim): Remove this? Nothing in ProfileSyncService uses it, and outside
76 // callers use a seemingly arbitrary / redundant / bug prone combination of
77 // this method, IsSyncAllowed, and others.
78 virtual bool IsSyncEnabledAndLoggedIn() = 0;
80 // Disables sync for user. Use ShowLoginDialog to enable.
81 virtual void DisableForUser() = 0;
83 // Stops sync at the user's request.
84 virtual void RequestStop() = 0;
86 // The user requests that sync start. This only actually starts sync if
87 // IsSyncAllowed is true and the user is signed in. Once sync starts,
88 // other things such as HasSyncSetupCompleted being false can still prevent
89 // it from moving into the "active" state.
90 virtual void RequestStart() = 0;
92 // Returns the set of types which are preferred for enabling. This is a
93 // superset of the active types (see GetActiveDataTypes()).
94 virtual syncer::ModelTypeSet
GetPreferredDataTypes() const = 0;
96 // Called when a user chooses which data types to sync as part of the sync
97 // setup wizard. |sync_everything| represents whether they chose the
98 // "keep everything synced" option; if true, |chosen_types| will be ignored
99 // and all data types will be synced. |sync_everything| means "sync all
100 // current and future data types."
101 virtual void OnUserChoseDatatypes(bool sync_everything
,
102 syncer::ModelTypeSet chosen_types
) = 0;
104 // Called whe Sync has been setup by the user and can be started.
105 virtual void SetSyncSetupCompleted() = 0;
107 // Returns true if initial sync setup is in progress (does not return true
108 // if the user is customizing sync after already completing setup once).
109 // SyncService uses this to determine if it's OK to start syncing, or if the
110 // user is still setting up the initial sync configuration.
111 virtual bool FirstSetupInProgress() const = 0;
113 // Called by the UI to notify the SyncService that UI is visible so it will
114 // not start syncing. This tells sync whether it's safe to start downloading
115 // data types yet (we don't start syncing until after sync setup is complete).
116 // The UI calls this as soon as any part of the signin wizard is displayed
117 // (even just the login UI).
118 // If |setup_in_progress| is false, this also kicks the sync engine to ensure
119 // that data download starts. In this case, |ReconfigureDatatypeManager| will
121 virtual void SetSetupInProgress(bool setup_in_progress
) = 0;
124 virtual bool setup_in_progress() const = 0;
126 // Whether the data types active for the current mode have finished
128 virtual bool ConfigurationDone() const = 0;
130 virtual const GoogleServiceAuthError
& GetAuthError() const = 0;
131 virtual bool HasUnrecoverableError() const = 0;
133 // Returns true if the SyncBackendHost has told us it's ready to accept
134 // changes. This should only be used for sync's internal configuration logic
135 // (such as deciding when to prompt for an encryption passphrase).
136 virtual bool backend_initialized() const = 0;
138 // Returns true if OnPassphraseRequired has been called for decryption and
139 // we have an encrypted data type enabled.
140 virtual bool IsPassphraseRequiredForDecryption() const = 0;
142 // Returns the time the current explicit passphrase (if any), was set.
143 // If no secondary passphrase is in use, or no time is available, returns an
145 virtual base::Time
GetExplicitPassphraseTime() const = 0;
147 // Returns true if a secondary (explicit) passphrase is being used. It is not
148 // legal to call this method before the backend is initialized.
149 virtual bool IsUsingSecondaryPassphrase() const = 0;
151 // Turns on encryption for all data. Callers must call OnUserChoseDatatypes()
152 // after calling this to force the encryption to occur.
153 virtual void EnableEncryptEverything() = 0;
155 // Asynchronously sets the passphrase to |passphrase| for encryption. |type|
156 // specifies whether the passphrase is a custom passphrase or the GAIA
157 // password being reused as a passphrase.
158 // TODO(atwilson): Change this so external callers can only set an EXPLICIT
159 // passphrase with this API.
160 virtual void SetEncryptionPassphrase(const std::string
& passphrase
,
161 PassphraseType type
) = 0;
163 // Asynchronously decrypts pending keys using |passphrase|. Returns false
164 // immediately if the passphrase could not be used to decrypt a locally cached
165 // copy of encrypted keys; returns true otherwise.
166 virtual bool SetDecryptionPassphrase(const std::string
& passphrase
)
167 WARN_UNUSED_RESULT
= 0;
173 DISALLOW_COPY_AND_ASSIGN(SyncService
);
176 } // namespace sync_driver
178 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_