Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / sync / sync_setup_service.h
blob491a09bdc27509aa4255c5539e0e5f18aea7dd77
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.
5 #ifndef IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_
6 #define IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_
8 #include <map>
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"
16 namespace sync_driver {
17 class SyncService;
20 class PrefService;
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;
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;
47 SyncSetupService(sync_driver::SyncService* sync_service, PrefService* prefs);
48 ~SyncSetupService() override;
50 // Returns the |syncer::ModelType| associated to the given
51 // |SyncableDatatypes|.
52 syncer::ModelType GetModelType(SyncableDatatype datatype);
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);
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);
70 // Returns whether the user needs to enter a passphrase or enable sync to make
71 // sync work.
72 bool UserActionIsRequiredToHaveSyncWork();
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);
80 // Returns the current sync service state.
81 virtual SyncServiceState GetSyncServiceState();
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();
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();
92 // Commit the current state of the configuration to the sync backend.
93 void CommitChanges();
95 // Returns true if there are uncommitted sync changes;
96 bool HasUncommittedChanges();
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);
104 sync_driver::SyncService* const sync_service_;
105 PrefService* const prefs_;
106 syncer::ModelTypeSet user_selectable_types_;
108 DISALLOW_COPY_AND_ASSIGN(SyncSetupService);
111 #endif // IOS_CHROME_BROWSER_SYNC_SYNC_SETUP_SERVICE_H_