OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_ |
| 6 #define IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/strings/string16.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "sync/internal_api/public/base/model_type.h" |
| 14 #include "sync/internal_api/public/util/syncer_error.h" |
| 15 |
| 16 namespace sync_driver { |
| 17 class SyncService; |
| 18 } |
| 19 |
| 20 class PrefService; |
| 21 |
| 22 // Class that allows configuring sync. It handles enabling and disabling it, as |
| 23 // well as choosing datatypes. Most actions are delayed until a commit is done, |
| 24 // to allow the complex sync setup flow on iOS. |
| 25 class SyncSetupService : public KeyedService { |
| 26 public: |
| 27 typedef enum { |
| 28 kNoSyncServiceError, |
| 29 kSyncServiceSignInNeedsUpdate, |
| 30 kSyncServiceCouldNotConnect, |
| 31 kSyncServiceServiceUnavailable, |
| 32 kSyncServiceNeedsPassphrase, |
| 33 kSyncServiceUnrecoverableError, |
| 34 kLastSyncServiceError = kSyncServiceUnrecoverableError |
| 35 } SyncServiceState; |
| 36 |
| 37 // The set of user-selectable datatypes handled by Chrome for iOS. |
| 38 typedef enum { |
| 39 kSyncBookmarks, |
| 40 kSyncOmniboxHistory, |
| 41 kSyncPasswords, |
| 42 kSyncOpenTabs, |
| 43 kSyncAutofill, |
| 44 kNumberOfSyncableDatatypes |
| 45 } SyncableDatatype; |
| 46 |
| 47 SyncSetupService(sync_driver::SyncService* sync_service, PrefService* prefs); |
| 48 ~SyncSetupService() override; |
| 49 |
| 50 // Returns the |syncer::ModelType| associated to the given |
| 51 // |SyncableDatatypes|. |
| 52 syncer::ModelType GetModelType(SyncableDatatype datatype); |
| 53 |
| 54 // Returns whether sync is enabled. |
| 55 virtual bool IsSyncEnabled() const; |
| 56 // Enables or disables sync. Changes won't take effect in the sync backend |
| 57 // before the next call to |CommitChanges|. |
| 58 virtual void SetSyncEnabled(bool sync_enabled); |
| 59 |
| 60 // Returns all currently enabled datatypes. |
| 61 syncer::ModelTypeSet GetDataTypes() const; |
| 62 // Returns whether the given datatype is enabled. |
| 63 virtual bool IsDataTypeEnabled(syncer::ModelType datatype) const; |
| 64 // Enables or disables the given datatype. To be noted: this can be called at |
| 65 // any time, but will only be meaningful if |IsSyncEnabled| is true and |
| 66 // |IsSyncingAllDataTypes| is false. Changes won't take effect in the sync |
| 67 // backend before the next call to |CommitChanges|. |
| 68 void SetDataTypeEnabled(syncer::ModelType datatype, bool enabled); |
| 69 |
| 70 // Returns whether the user needs to enter a passphrase or enable sync to make |
| 71 // sync work. |
| 72 bool UserActionIsRequiredToHaveSyncWork(); |
| 73 |
| 74 // Returns whether all datatypes are being synced. |
| 75 virtual bool IsSyncingAllDataTypes() const; |
| 76 // Sets whether all datatypes should be synced or not. Changes won't take |
| 77 // effect before the next call to |CommitChanges|. |
| 78 virtual void SetSyncingAllDataTypes(bool sync_all); |
| 79 |
| 80 // Returns the current sync service state. |
| 81 virtual SyncServiceState GetSyncServiceState(); |
| 82 |
| 83 // Returns true if the user has gone through the initial sync configuration. |
| 84 // This method is guaranteed not to start the sync backend so it can be |
| 85 // called at start-up. |
| 86 bool HasFinishedInitialSetup(); |
| 87 |
| 88 // Pauses sync allowing the user to configure what data to sync before |
| 89 // actually starting to sync data with the server. |
| 90 void PrepareForFirstSyncSetup(); |
| 91 |
| 92 // Commit the current state of the configuration to the sync backend. |
| 93 void CommitChanges(); |
| 94 |
| 95 // Returns true if there are uncommitted sync changes; |
| 96 bool HasUncommittedChanges(); |
| 97 |
| 98 private: |
| 99 // Enables or disables sync. Changes won't take effect in the sync backend |
| 100 // before the next call to |CommitChanges|. No changes are made to the |
| 101 // currently selected datatypes. |
| 102 void SetSyncEnabledWithoutChangingDatatypes(bool sync_enabled); |
| 103 |
| 104 sync_driver::SyncService* const sync_service_; |
| 105 PrefService* const prefs_; |
| 106 syncer::ModelTypeSet user_selectable_types_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(SyncSetupService); |
| 109 }; |
| 110 |
| 111 #endif // IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_ |
OLD | NEW |