[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / components / sync_driver / sync_service.h
blob264d024c5d2b868ee20587c33ca6f9b72b3f19bd
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 // Passed as an argument to RequestStop to control whether or not the sync
31 // backend should clear its data directory when it shuts down. See
32 // RequestStop for more information.
33 enum SyncStopDataFate {
34 KEEP_DATA,
35 CLEAR_DATA,
38 ~SyncService() override {}
40 // Whether sync is enabled by user or not. This does not necessarily mean
41 // that sync is currently running (due to delayed startup, unrecoverable
42 // errors, or shutdown). See IsSyncActive below for checking whether sync
43 // is actually running.
44 virtual bool HasSyncSetupCompleted() const = 0;
46 // Whether sync is allowed to start. Command line flags, platform-level
47 // overrides, and account-level overrides are examples of reasons this
48 // might be false.
49 virtual bool IsSyncAllowed() const = 0;
51 // Returns true if sync is fully initialized and active. This implies that
52 // an initial configuration has successfully completed, although there may
53 // be datatype specific, auth, or other transient errors. To see which
54 // datetypes are actually syncing, see GetActiveTypes() below.
55 // Note that if sync is in backup or rollback mode, IsSyncActive() will be
56 // false.
57 virtual bool IsSyncActive() const = 0;
59 // Get the set of current active data types (those chosen or configured by
60 // the user which have not also encountered a runtime error).
61 // Note that if the Sync engine is in the middle of a configuration, this
62 // will the the empty set. Once the configuration completes the set will
63 // be updated.
64 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0;
66 // Adds/removes an observer. SyncService does not take ownership of the
67 // observer.
68 virtual void AddObserver(SyncServiceObserver* observer) = 0;
69 virtual void RemoveObserver(SyncServiceObserver* observer) = 0;
71 // Returns true if |observer| has already been added as an observer.
72 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0;
74 // ---------------------------------------------------------------------------
75 // TODO(sync): The methods below were pulled from ProfileSyncService, and
76 // should be evaluated to see if they should stay.
78 // Returns true if sync is allowed, requested, and the user is logged in.
79 // (being logged in does not mean that tokens are available - tokens may
80 // be missing because they have not loaded yet, or because they were deleted
81 // due to http://crbug.com/121755).
82 virtual bool CanSyncStart() const = 0;
84 // Stops sync at the user's request. |data_fate| controls whether the sync
85 // backend should clear its data directory when it shuts down. Generally
86 // KEEP_DATA is used when the user just stops sync, and CLEAR_DATA is used
87 // when they sign out of the profile entirely.
88 virtual void RequestStop(SyncStopDataFate data_fate) = 0;
90 // The user requests that sync start. This only actually starts sync if
91 // IsSyncAllowed is true and the user is signed in. Once sync starts,
92 // other things such as HasSyncSetupCompleted being false can still prevent
93 // it from moving into the "active" state.
94 virtual void RequestStart() = 0;
96 // Returns the set of types which are preferred for enabling. This is a
97 // superset of the active types (see GetActiveDataTypes()).
98 virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0;
100 // Called when a user chooses which data types to sync as part of the sync
101 // setup wizard. |sync_everything| represents whether they chose the
102 // "keep everything synced" option; if true, |chosen_types| will be ignored
103 // and all data types will be synced. |sync_everything| means "sync all
104 // current and future data types."
105 virtual void OnUserChoseDatatypes(bool sync_everything,
106 syncer::ModelTypeSet chosen_types) = 0;
108 // Called whe Sync has been setup by the user and can be started.
109 virtual void SetSyncSetupCompleted() = 0;
111 // Returns true if initial sync setup is in progress (does not return true
112 // if the user is customizing sync after already completing setup once).
113 // SyncService uses this to determine if it's OK to start syncing, or if the
114 // user is still setting up the initial sync configuration.
115 virtual bool FirstSetupInProgress() const = 0;
117 // Called by the UI to notify the SyncService that UI is visible so it will
118 // not start syncing. This tells sync whether it's safe to start downloading
119 // data types yet (we don't start syncing until after sync setup is complete).
120 // The UI calls this as soon as any part of the signin wizard is displayed
121 // (even just the login UI).
122 // If |setup_in_progress| is false, this also kicks the sync engine to ensure
123 // that data download starts. In this case, |ReconfigureDatatypeManager| will
124 // get triggered.
125 virtual void SetSetupInProgress(bool setup_in_progress) = 0;
127 // Used by tests.
128 virtual bool setup_in_progress() const = 0;
130 // Whether the data types active for the current mode have finished
131 // configuration.
132 virtual bool ConfigurationDone() const = 0;
134 virtual const GoogleServiceAuthError& GetAuthError() const = 0;
135 virtual bool HasUnrecoverableError() const = 0;
137 // Returns true if the SyncBackendHost has told us it's ready to accept
138 // changes. This should only be used for sync's internal configuration logic
139 // (such as deciding when to prompt for an encryption passphrase).
140 virtual bool backend_initialized() const = 0;
142 // Returns true if OnPassphraseRequired has been called for decryption and
143 // we have an encrypted data type enabled.
144 virtual bool IsPassphraseRequiredForDecryption() const = 0;
146 // Returns the time the current explicit passphrase (if any), was set.
147 // If no secondary passphrase is in use, or no time is available, returns an
148 // unset base::Time.
149 virtual base::Time GetExplicitPassphraseTime() const = 0;
151 // Returns true if a secondary (explicit) passphrase is being used. It is not
152 // legal to call this method before the backend is initialized.
153 virtual bool IsUsingSecondaryPassphrase() const = 0;
155 // Turns on encryption for all data. Callers must call OnUserChoseDatatypes()
156 // after calling this to force the encryption to occur.
157 virtual void EnableEncryptEverything() = 0;
159 // Asynchronously sets the passphrase to |passphrase| for encryption. |type|
160 // specifies whether the passphrase is a custom passphrase or the GAIA
161 // password being reused as a passphrase.
162 // TODO(atwilson): Change this so external callers can only set an EXPLICIT
163 // passphrase with this API.
164 virtual void SetEncryptionPassphrase(const std::string& passphrase,
165 PassphraseType type) = 0;
167 // Asynchronously decrypts pending keys using |passphrase|. Returns false
168 // immediately if the passphrase could not be used to decrypt a locally cached
169 // copy of encrypted keys; returns true otherwise.
170 virtual bool SetDecryptionPassphrase(const std::string& passphrase)
171 WARN_UNUSED_RESULT = 0;
173 protected:
174 SyncService() {}
176 private:
177 DISALLOW_COPY_AND_ASSIGN(SyncService);
180 } // namespace sync_driver
182 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_