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 |
(...skipping 10 matching lines...) Expand all Loading... |
37 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; | 51 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; |
38 | 52 |
39 // Adds/removes an observer. SyncService does not take ownership of the | 53 // Adds/removes an observer. SyncService does not take ownership of the |
40 // observer. | 54 // observer. |
41 virtual void AddObserver(SyncServiceObserver* observer) = 0; | 55 virtual void AddObserver(SyncServiceObserver* observer) = 0; |
42 virtual void RemoveObserver(SyncServiceObserver* observer) = 0; | 56 virtual void RemoveObserver(SyncServiceObserver* observer) = 0; |
43 | 57 |
44 // Returns true if |observer| has already been added as an observer. | 58 // Returns true if |observer| has already been added as an observer. |
45 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0; | 59 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0; |
46 | 60 |
| 61 // --------------------------------------------------------------------------- |
| 62 // TODO(sync): The methods below were pulled from ProfileSyncService, and |
| 63 // should be evaluated to see if they should stay. |
| 64 |
| 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; |
| 74 |
| 75 // Disables sync for user. Use ShowLoginDialog to enable. |
| 76 virtual void DisableForUser() = 0; |
| 77 |
| 78 // Stops the sync backend and sets the flag for suppressing sync startup. |
| 79 virtual void StopAndSuppress() = 0; |
| 80 |
| 81 // Resets the flag for suppressing sync startup and starts the sync backend. |
| 82 virtual void UnsuppressAndStart() = 0; |
| 83 |
| 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; |
| 87 |
| 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; |
| 95 |
| 96 // Called whe Sync has been setup by the user and can be started. |
| 97 virtual void SetSyncSetupCompleted() = 0; |
| 98 |
| 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; |
| 104 |
| 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; |
| 114 |
| 115 // Used by tests. |
| 116 virtual bool setup_in_progress() const = 0; |
| 117 |
| 118 // Whether the data types active for the current mode have finished |
| 119 // configuration. |
| 120 virtual bool ConfigurationDone() const = 0; |
| 121 |
| 122 virtual const GoogleServiceAuthError& GetAuthError() const = 0; |
| 123 virtual bool HasUnrecoverableError() const = 0; |
| 124 |
| 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; |
| 129 |
| 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; |
| 133 |
| 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; |
| 138 |
| 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; |
| 142 |
| 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; |
| 146 |
| 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; |
| 154 |
| 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; |
| 160 |
47 protected: | 161 protected: |
48 SyncService() {} | 162 SyncService() {} |
49 | 163 |
50 private: | 164 private: |
51 DISALLOW_COPY_AND_ASSIGN(SyncService); | 165 DISALLOW_COPY_AND_ASSIGN(SyncService); |
52 }; | 166 }; |
53 | 167 |
54 } // namespace sync_driver | 168 } // namespace sync_driver |
55 | 169 |
56 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ | 170 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ |
OLD | NEW |