Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/ui/webui/settings/sync_handler.h

Issue 1503333003: Settings People Rewrite: Make Sync/Sign-in naming consistent to People. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_SYNC_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_SYNC_HANDLER_H_
7
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/scoped_observer.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/timer/timer.h"
15 #include "chrome/browser/sync/sync_startup_tracker.h"
16 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
17 #include "components/signin/core/browser/signin_manager_base.h"
18 #include "components/sync_driver/sync_service_observer.h"
19 #include "content/public/browser/web_ui_message_handler.h"
20
21 class LoginUIService;
22 class ProfileSyncService;
23 class SigninManagerBase;
24
25 namespace content {
26 class WebContents;
27 class WebUI;
28 }
29
30 namespace signin_metrics {
31 enum class AccessPoint;
32 }
33
34 namespace settings {
35
36 class SyncHandler : public content::WebUIMessageHandler,
37 public SigninManagerBase::Observer,
38 public SyncStartupTracker::Observer,
39 public LoginUIService::LoginUI,
40 public sync_driver::SyncServiceObserver {
41 public:
42 explicit SyncHandler(Profile* profile);
43 ~SyncHandler() override;
44
45 // content::WebUIMessageHandler implementation.
46 void RegisterMessages() override;
47
48 // SyncStartupTracker::Observer implementation.
49 void SyncStartupCompleted() override;
50 void SyncStartupFailed() override;
51
52 // LoginUIService::LoginUI implementation.
53 void FocusUI() override;
54 void CloseUI() override;
55
56 // SigninManagerBase::Observer implementation.
57 void GoogleSigninSucceeded(const std::string& account_id,
58 const std::string& username,
59 const std::string& password) override;
60 void GoogleSignedOut(const std::string& account_id,
61 const std::string& username) override;
62
63 // sync_driver::SyncServiceObserver implementation.
64 void OnStateChanged() override;
65
66 // Initializes the sync setup flow and shows the setup UI.
67 void OpenSyncSetup(const base::ListValue* args);
68
69 // Shows advanced configuration dialog without going through sign in dialog.
70 // Kicks the sync backend if necessary with showing spinner dialog until it
71 // gets ready.
72 void OpenConfigureSync();
73
74 // Terminates the sync setup flow.
75 void CloseSyncSetup();
76
77 // Returns a newly created dictionary with a number of properties that
78 // correspond to the status of sync.
79 scoped_ptr<base::DictionaryValue> GetSyncStateDictionary();
80
81 protected:
82 friend class SyncHandlerTest;
83 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest,
84 DisplayConfigureWithBackendDisabledAndCancel);
85 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, HandleSetupUIWhenSyncDisabled);
86 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, SelectCustomEncryption);
87 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, ShowSyncSetupWhenNotSignedIn);
88 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, SuccessfullySetPassphrase);
89 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TestSyncEverything);
90 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TestSyncNothing);
91 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TestSyncAllManually);
92 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TestPassphraseStillRequired);
93 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TestSyncIndividualTypes);
94 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TurnOnEncryptAll);
95 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, TurnOnEncryptAllDisallowed);
96 FRIEND_TEST_ALL_PREFIXES(SyncHandlerTest, UnsuccessfullySetPassphrase);
97 FRIEND_TEST_ALL_PREFIXES(SyncHandlerNonCrosTest,
98 UnrecoverableErrorInitializingSync);
99 FRIEND_TEST_ALL_PREFIXES(SyncHandlerNonCrosTest,
100 GaiaErrorInitializingSync);
101 FRIEND_TEST_ALL_PREFIXES(SyncHandlerNonCrosTest, HandleCaptcha);
102 FRIEND_TEST_ALL_PREFIXES(SyncHandlerNonCrosTest, HandleGaiaAuthFailure);
103 FRIEND_TEST_ALL_PREFIXES(SyncHandlerNonCrosTest,
104 SubmitAuthWithInvalidUsername);
105 FRIEND_TEST_ALL_PREFIXES(SyncHandlerFirstSigninTest, DisplayBasicLogin);
106
107 bool is_configuring_sync() const { return configuring_sync_; }
108
109 // Called when configuring sync is done to close the dialog and start syncing.
110 void ConfigureSyncDone();
111
112 // Helper routine that gets the ProfileSyncService associated with the parent
113 // profile.
114 ProfileSyncService* GetSyncService() const;
115
116 // Returns the LoginUIService for the parent profile.
117 LoginUIService* GetLoginUIService() const;
118
119 private:
120 // Callbacks from the page.
121 void OnDidClosePage(const base::ListValue* args);
122 void HandleConfigure(const base::ListValue* args);
123 void HandlePassphraseEntry(const base::ListValue* args);
124 void HandlePassphraseCancel(const base::ListValue* args);
125 void HandleShowSetupUI(const base::ListValue* args);
126 void HandleDoSignOutOnAuthError(const base::ListValue* args);
127 void HandleStartSignin(const base::ListValue* args);
128 void HandleStopSyncing(const base::ListValue* args);
129 void HandleCloseTimeout(const base::ListValue* args);
130 void HandleGetSyncStatus(const base::ListValue* args);
131 void HandleManageOtherPeople(const base::ListValue* args);
132
133 #if !defined(OS_CHROMEOS)
134 // Displays the GAIA login form.
135 void DisplayGaiaLogin(signin_metrics::AccessPoint access_point);
136
137 // When web-flow is enabled, displays the Gaia login form in a new tab.
138 // This function is virtual so that tests can override.
139 virtual void DisplayGaiaLoginInNewTabOrWindow(
140 signin_metrics::AccessPoint access_point);
141 #endif
142
143 // A utility function to call before actually showing setup dialog. Makes sure
144 // that a new dialog can be shown and sets flag that setup is in progress.
145 bool PrepareSyncSetup();
146
147 // Displays spinner-only UI indicating that something is going on in the
148 // background.
149 // TODO(kochi): better to show some message that the user can understand what
150 // is running in the background.
151 void DisplaySpinner();
152
153 // Displays an error dialog which shows timeout of starting the sync backend.
154 void DisplayTimeout();
155
156 // Returns true if this object is the active login object.
157 bool IsActiveLogin() const;
158
159 // If a wizard already exists, return true. Otherwise, return false.
160 bool IsExistingWizardPresent();
161
162 // If a wizard already exists, focus it and return true.
163 bool FocusExistingWizardIfPresent();
164
165 // Display the configure sync UI. If |passphrase_failed| is true, the account
166 // requires a passphrase and one hasn't been provided or it was invalid.
167 void DisplayConfigureSync(bool passphrase_failed);
168
169 // Sends the current sync status to the JavaScript WebUI code.
170 void UpdateSyncState();
171
172 // Will be called when the kSigninAllowed pref has changed.
173 void OnSigninAllowedPrefChange();
174
175 // Weak pointer.
176 Profile* profile_;
177
178 // Helper object used to wait for the sync backend to startup.
179 scoped_ptr<SyncStartupTracker> sync_startup_tracker_;
180
181 // Set to true whenever the sync configure UI is visible. This is used to tell
182 // what stage of the setup wizard the user was in and to update the UMA
183 // histograms in the case that the user cancels out.
184 bool configuring_sync_;
185
186 // The OneShotTimer object used to timeout of starting the sync backend
187 // service.
188 scoped_ptr<base::OneShotTimer> backend_start_timer_;
189
190 // Used to listen for pref changes to allow or disallow signin.
191 PrefChangeRegistrar profile_pref_registrar_;
192
193 // Manages observer lifetime.
194 ScopedObserver<ProfileSyncService, SyncHandler> sync_service_observer_;
195
196 DISALLOW_COPY_AND_ASSIGN(SyncHandler);
197 };
198
199 } // namespace settings
200
201 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_SYNC_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698