Switch to using the new app install flow
[chromium-blink-merge.git] / components / sync_driver / sync_service.h
blob3a810fa53ab980036dc4b30a5287563d5a3cc610
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 sync_driver {
20 class SyncService : public sync_driver::DataTypeEncryptionHandler {
21 public:
22 // Used to specify the kind of passphrase with which sync data is encrypted.
23 enum PassphraseType {
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 SyncActive below for checking whether sync
35 // is actually running.
36 virtual bool HasSyncSetupCompleted() const = 0;
38 // Returns true if sync is fully initialized and active. This implies that
39 // an initial configuration has successfully completed, although there may
40 // be datatype specific, auth, or other transient errors. To see which
41 // datetypes are actually syncing, see GetActiveTypes() below.
42 // Note that if sync is in backup or rollback mode, SyncActive() will be
43 // false.
44 virtual bool SyncActive() const = 0;
46 // Get the set of current active data types (those chosen or configured by
47 // the user which have not also encountered a runtime error).
48 // Note that if the Sync engine is in the middle of a configuration, this
49 // will the the empty set. Once the configuration completes the set will
50 // be updated.
51 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0;
53 // Adds/removes an observer. SyncService does not take ownership of the
54 // observer.
55 virtual void AddObserver(SyncServiceObserver* observer) = 0;
56 virtual void RemoveObserver(SyncServiceObserver* observer) = 0;
58 // Returns true if |observer| has already been added as an observer.
59 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0;
61 // ---------------------------------------------------------------------------
62 // TODO(sync): The methods below were pulled from ProfileSyncService, and
63 // should be evaluated to see if they should stay.
65 // Returns true if sync is enabled/not suppressed and the user is logged in.
66 // (being logged in does not mean that tokens are available - tokens may
67 // be missing because they have not loaded yet, or because they were deleted
68 // due to http://crbug.com/121755).
69 // Virtual to enable mocking in tests.
70 // TODO(tim): Remove this? Nothing in ProfileSyncService uses it, and outside
71 // callers use a seemingly arbitrary / redundant / bug prone combination of
72 // this method, IsSyncAccessible, and others.
73 virtual bool IsSyncEnabledAndLoggedIn() = 0;
75 // Disables sync for user. Use ShowLoginDialog to enable.
76 virtual void DisableForUser() = 0;
78 // Stops the sync backend and sets the flag for suppressing sync startup.
79 virtual void StopAndSuppress() = 0;
81 // Resets the flag for suppressing sync startup and starts the sync backend.
82 virtual void UnsuppressAndStart() = 0;
84 // Returns the set of types which are preferred for enabling. This is a
85 // superset of the active types (see GetActiveDataTypes()).
86 virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0;
88 // Called when a user chooses which data types to sync as part of the sync
89 // setup wizard. |sync_everything| represents whether they chose the
90 // "keep everything synced" option; if true, |chosen_types| will be ignored
91 // and all data types will be synced. |sync_everything| means "sync all
92 // current and future data types."
93 virtual void OnUserChoseDatatypes(bool sync_everything,
94 syncer::ModelTypeSet chosen_types) = 0;
96 // Called whe Sync has been setup by the user and can be started.
97 virtual void SetSyncSetupCompleted() = 0;
99 // Returns true if initial sync setup is in progress (does not return true
100 // if the user is customizing sync after already completing setup once).
101 // SyncService uses this to determine if it's OK to start syncing, or if the
102 // user is still setting up the initial sync configuration.
103 virtual bool FirstSetupInProgress() const = 0;
105 // Called by the UI to notify the SyncService that UI is visible so it will
106 // not start syncing. This tells sync whether it's safe to start downloading
107 // data types yet (we don't start syncing until after sync setup is complete).
108 // The UI calls this as soon as any part of the signin wizard is displayed
109 // (even just the login UI).
110 // If |setup_in_progress| is false, this also kicks the sync engine to ensure
111 // that data download starts. In this case, |ReconfigureDatatypeManager| will
112 // get triggered.
113 virtual void SetSetupInProgress(bool setup_in_progress) = 0;
115 // Used by tests.
116 virtual bool setup_in_progress() const = 0;
118 // Whether the data types active for the current mode have finished
119 // configuration.
120 virtual bool ConfigurationDone() const = 0;
122 virtual const GoogleServiceAuthError& GetAuthError() const = 0;
123 virtual bool HasUnrecoverableError() const = 0;
125 // Returns true if the SyncBackendHost has told us it's ready to accept
126 // changes. This should only be used for sync's internal configuration logic
127 // (such as deciding when to prompt for an encryption passphrase).
128 virtual bool backend_initialized() const = 0;
130 // Returns true if OnPassphraseRequired has been called for decryption and
131 // we have an encrypted data type enabled.
132 virtual bool IsPassphraseRequiredForDecryption() const = 0;
134 // Returns the time the current explicit passphrase (if any), was set.
135 // If no secondary passphrase is in use, or no time is available, returns an
136 // unset base::Time.
137 virtual base::Time GetExplicitPassphraseTime() const = 0;
139 // Returns true if a secondary (explicit) passphrase is being used. It is not
140 // legal to call this method before the backend is initialized.
141 virtual bool IsUsingSecondaryPassphrase() const = 0;
143 // Turns on encryption for all data. Callers must call OnUserChoseDatatypes()
144 // after calling this to force the encryption to occur.
145 virtual void EnableEncryptEverything() = 0;
147 // Asynchronously sets the passphrase to |passphrase| for encryption. |type|
148 // specifies whether the passphrase is a custom passphrase or the GAIA
149 // password being reused as a passphrase.
150 // TODO(atwilson): Change this so external callers can only set an EXPLICIT
151 // passphrase with this API.
152 virtual void SetEncryptionPassphrase(const std::string& passphrase,
153 PassphraseType type) = 0;
155 // Asynchronously decrypts pending keys using |passphrase|. Returns false
156 // immediately if the passphrase could not be used to decrypt a locally cached
157 // copy of encrypted keys; returns true otherwise.
158 virtual bool SetDecryptionPassphrase(const std::string& passphrase)
159 WARN_UNUSED_RESULT = 0;
161 protected:
162 SyncService() {}
164 private:
165 DISALLOW_COPY_AND_ASSIGN(SyncService);
168 } // namespace sync_driver
170 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_