OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ |
6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ | 6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ |
7 | 7 |
8 #include <string> | |
9 | |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/time/time.h" | |
12 #include "components/sync_driver/data_type_encryption_handler.h" | |
9 #include "components/sync_driver/sync_service_observer.h" | 13 #include "components/sync_driver/sync_service_observer.h" |
10 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
11 | 15 |
16 class GoogleServiceAuthError; | |
17 | |
12 namespace sync_driver { | 18 namespace sync_driver { |
13 | 19 |
14 class SyncService { | 20 class SyncService : public sync_driver::DataTypeEncryptionHandler { |
15 public: | 21 public: |
16 virtual ~SyncService() {} | 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. | |
28 }; | |
29 | |
30 ~SyncService() override {} | |
17 | 31 |
18 // Whether sync is enabled by user or not. This does not necessarily mean | 32 // Whether sync is enabled by user or not. This does not necessarily mean |
19 // that sync is currently running (due to delayed startup, unrecoverable | 33 // that sync is currently running (due to delayed startup, unrecoverable |
20 // errors, or shutdown). See SyncActive below for checking whether sync | 34 // errors, or shutdown). See SyncActive below for checking whether sync |
21 // is actually running. | 35 // is actually running. |
22 virtual bool HasSyncSetupCompleted() const = 0; | 36 virtual bool HasSyncSetupCompleted() const = 0; |
23 | 37 |
24 // Returns true if sync is fully initialized and active. This implies that | 38 // Returns true if sync is fully initialized and active. This implies that |
25 // an initial configuration has successfully completed, although there may | 39 // an initial configuration has successfully completed, although there may |
26 // be datatype specific, auth, or other transient errors. To see which | 40 // be datatype specific, auth, or other transient errors. To see which |
27 // datetypes are actually syncing, see GetActiveTypes() below. | 41 // datetypes are actually syncing, see GetActiveTypes() below. |
28 // Note that if sync is in backup or rollback mode, SyncActive() will be | 42 // Note that if sync is in backup or rollback mode, SyncActive() will be |
29 // false. | 43 // false. |
30 virtual bool SyncActive() const = 0; | 44 virtual bool SyncActive() const = 0; |
31 | 45 |
46 // Returns true if sync is enabled/not suppressed and the user is logged in. | |
47 // (being logged in does not mean that tokens are available - tokens may | |
48 // be missing because they have not loaded yet, or because they were deleted | |
49 // due to http://crbug.com/121755). | |
50 // Virtual to enable mocking in tests. | |
51 // TODO(tim): Remove this? Nothing in ProfileSyncService uses it, and outside | |
52 // callers use a seemingly arbitrary / redundant / bug prone combination of | |
53 // this method, IsSyncAccessible, and others. | |
54 virtual bool IsSyncEnabledAndLoggedIn() = 0; | |
Nicolas Zea
2015/04/07 16:57:31
Could you organize all these at the bottom of the
| |
55 | |
56 // Disables sync for user. Use ShowLoginDialog to enable. | |
57 virtual void DisableForUser() = 0; | |
58 | |
59 // Stops the sync backend and sets the flag for suppressing sync startup. | |
60 virtual void StopAndSuppress() = 0; | |
61 | |
62 // Resets the flag for suppressing sync startup and starts the sync backend. | |
63 virtual void UnsuppressAndStart() = 0; | |
64 | |
32 // Get the set of current active data types (those chosen or configured by | 65 // Get the set of current active data types (those chosen or configured by |
33 // the user which have not also encountered a runtime error). | 66 // the user which have not also encountered a runtime error). |
34 // Note that if the Sync engine is in the middle of a configuration, this | 67 // Note that if the Sync engine is in the middle of a configuration, this |
35 // will the the empty set. Once the configuration completes the set will | 68 // will the the empty set. Once the configuration completes the set will |
36 // be updated. | 69 // be updated. |
37 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; | 70 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; |
38 | 71 |
72 // Returns the set of types which are preferred for enabling. This is a | |
73 // superset of the active types (see GetActiveDataTypes()). | |
74 virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0; | |
75 | |
76 // Called when a user chooses which data types to sync as part of the sync | |
77 // setup wizard. |sync_everything| represents whether they chose the | |
78 // "keep everything synced" option; if true, |chosen_types| will be ignored | |
79 // and all data types will be synced. |sync_everything| means "sync all | |
80 // current and future data types." | |
81 virtual void OnUserChoseDatatypes(bool sync_everything, | |
82 syncer::ModelTypeSet chosen_types) = 0; | |
83 | |
84 // Called whe Sync has been setup by the user and can be started. | |
85 virtual void SetSyncSetupCompleted() = 0; | |
86 | |
87 // Returns true if initial sync setup is in progress (does not return true | |
88 // if the user is customizing sync after already completing setup once). | |
89 // SyncService uses this to determine if it's OK to start syncing, or if the | |
90 // user is still setting up the initial sync configuration. | |
91 virtual bool FirstSetupInProgress() const = 0; | |
92 | |
93 // Called by the UI to notify the SyncService that UI is visible so it will | |
94 // not start syncing. This tells sync whether it's safe to start downloading | |
95 // data types yet (we don't start syncing until after sync setup is complete). | |
96 // The UI calls this as soon as any part of the signin wizard is displayed | |
97 // (even just the login UI). | |
98 // If |setup_in_progress| is false, this also kicks the sync engine to ensure | |
99 // that data download starts. In this case, |ReconfigureDatatypeManager| will | |
100 // get triggered. | |
101 virtual void SetSetupInProgress(bool setup_in_progress) = 0; | |
102 | |
103 // Used by tests. | |
104 virtual bool setup_in_progress() const = 0; | |
105 | |
106 // Whether the data types active for the current mode have finished | |
107 // configuration. | |
108 virtual bool ConfigurationDone() const = 0; | |
109 | |
110 virtual const GoogleServiceAuthError& GetAuthError() const = 0; | |
111 virtual bool HasUnrecoverableError() const = 0; | |
112 | |
113 // Returns true if the SyncBackendHost has told us it's ready to accept | |
114 // changes. This should only be used for sync's internal configuration logic | |
115 // (such as deciding when to prompt for an encryption passphrase). | |
116 virtual bool backend_initialized() const = 0; | |
117 | |
118 // Returns true if OnPassphraseRequired has been called for decryption and | |
119 // we have an encrypted data type enabled. | |
120 virtual bool IsPassphraseRequiredForDecryption() const = 0; | |
121 | |
122 // Returns the time the current explicit passphrase (if any), was set. | |
123 // If no secondary passphrase is in use, or no time is available, returns an | |
124 // unset base::Time. | |
125 virtual base::Time GetExplicitPassphraseTime() const = 0; | |
126 | |
127 // Returns true if a secondary (explicit) passphrase is being used. It is not | |
128 // legal to call this method before the backend is initialized. | |
129 virtual bool IsUsingSecondaryPassphrase() const = 0; | |
130 | |
131 // Turns on encryption for all data. Callers must call OnUserChoseDatatypes() | |
132 // after calling this to force the encryption to occur. | |
133 virtual void EnableEncryptEverything() = 0; | |
134 | |
135 // Asynchronously sets the passphrase to |passphrase| for encryption. |type| | |
136 // specifies whether the passphrase is a custom passphrase or the GAIA | |
137 // password being reused as a passphrase. | |
138 // TODO(atwilson): Change this so external callers can only set an EXPLICIT | |
139 // passphrase with this API. | |
140 virtual void SetEncryptionPassphrase(const std::string& passphrase, | |
141 PassphraseType type) = 0; | |
142 | |
143 // Asynchronously decrypts pending keys using |passphrase|. Returns false | |
144 // immediately if the passphrase could not be used to decrypt a locally cached | |
145 // copy of encrypted keys; returns true otherwise. | |
146 virtual bool SetDecryptionPassphrase(const std::string& passphrase) | |
147 WARN_UNUSED_RESULT = 0; | |
148 | |
39 // Adds/removes an observer. SyncService does not take ownership of the | 149 // Adds/removes an observer. SyncService does not take ownership of the |
40 // observer. | 150 // observer. |
41 virtual void AddObserver(SyncServiceObserver* observer) = 0; | 151 virtual void AddObserver(SyncServiceObserver* observer) = 0; |
42 virtual void RemoveObserver(SyncServiceObserver* observer) = 0; | 152 virtual void RemoveObserver(SyncServiceObserver* observer) = 0; |
43 | 153 |
44 // Returns true if |observer| has already been added as an observer. | 154 // Returns true if |observer| has already been added as an observer. |
45 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0; | 155 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0; |
46 | 156 |
47 protected: | 157 protected: |
48 SyncService() {} | 158 SyncService() {} |
49 | 159 |
50 private: | 160 private: |
51 DISALLOW_COPY_AND_ASSIGN(SyncService); | 161 DISALLOW_COPY_AND_ASSIGN(SyncService); |
52 }; | 162 }; |
53 | 163 |
54 } // namespace sync_driver | 164 } // namespace sync_driver |
55 | 165 |
56 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ | 166 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ |
OLD | NEW |