Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / sync_setup_handler.h
blob4ed025a7c9a5057d6929675687e30bdd7bc61acd
1 // Copyright (c) 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 CHROME_BROWSER_UI_WEBUI_OPTIONS_SYNC_SETUP_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_SYNC_SETUP_HANDLER_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/timer.h"
11 #include "chrome/browser/sync/sync_startup_tracker.h"
12 #include "chrome/browser/ui/webui/options/options_ui.h"
13 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
15 class LoginUIService;
16 class ProfileSyncService;
17 class SigninManagerBase;
19 namespace content {
20 class WebContents;
23 class SyncSetupHandler : public options::OptionsPageUIHandler,
24 public SyncStartupTracker::Observer,
25 public LoginUIService::LoginUI {
26 public:
27 SyncSetupHandler();
28 ~SyncSetupHandler() override;
30 // OptionsPageUIHandler implementation.
31 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
32 void RegisterMessages() override;
34 // SyncStartupTracker::Observer implementation;
35 void SyncStartupCompleted() override;
36 void SyncStartupFailed() override;
38 // LoginUIService::LoginUI implementation.
39 void FocusUI() override;
40 void CloseUI() override;
42 static void GetStaticLocalizedValues(
43 base::DictionaryValue* localized_strings,
44 content::WebUI* web_ui);
46 // Initializes the sync setup flow and shows the setup UI.
47 void OpenSyncSetup();
49 // Shows advanced configuration dialog without going through sign in dialog.
50 // Kicks the sync backend if necessary with showing spinner dialog until it
51 // gets ready.
52 void OpenConfigureSync();
54 // Terminates the sync setup flow.
55 void CloseSyncSetup();
57 protected:
58 friend class SyncSetupHandlerTest;
59 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest,
60 DisplayConfigureWithBackendDisabledAndCancel);
61 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled);
62 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption);
63 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn);
64 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase);
65 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncEverything);
66 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncNothing);
67 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncAllManually);
68 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestPassphraseStillRequired);
69 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncIndividualTypes);
70 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TurnOnEncryptAll);
71 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TurnOnEncryptAllDisallowed);
72 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, UnsuccessfullySetPassphrase);
73 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
74 UnrecoverableErrorInitializingSync);
75 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
76 GaiaErrorInitializingSync);
77 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleCaptcha);
78 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure);
79 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
80 SubmitAuthWithInvalidUsername);
81 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin);
83 bool is_configuring_sync() const { return configuring_sync_; }
85 // Called when configuring sync is done to close the dialog and start syncing.
86 void ConfigureSyncDone();
88 // Helper routine that gets the ProfileSyncService associated with the parent
89 // profile.
90 ProfileSyncService* GetSyncService() const;
92 // Returns the LoginUIService for the parent profile.
93 LoginUIService* GetLoginUIService() const;
95 private:
96 // Callbacks from the page.
97 void OnDidClosePage(const base::ListValue* args);
98 void HandleConfigure(const base::ListValue* args);
99 void HandlePassphraseEntry(const base::ListValue* args);
100 void HandlePassphraseCancel(const base::ListValue* args);
101 void HandleShowSetupUI(const base::ListValue* args);
102 void HandleDoSignOutOnAuthError(const base::ListValue* args);
103 void HandleStartSignin(const base::ListValue* args);
104 void HandleStopSyncing(const base::ListValue* args);
105 void HandleCloseTimeout(const base::ListValue* args);
106 #if !defined(OS_CHROMEOS)
107 // Displays the GAIA login form.
108 void DisplayGaiaLogin();
110 // When web-flow is enabled, displays the Gaia login form in a new tab.
111 // This function is virtual so that tests can override.
112 virtual void DisplayGaiaLoginInNewTabOrWindow();
113 #endif
115 // Helper routine that gets the Profile associated with this object (virtual
116 // so tests can override).
117 virtual Profile* GetProfile() const;
119 // A utility function to call before actually showing setup dialog. Makes sure
120 // that a new dialog can be shown and sets flag that setup is in progress.
121 bool PrepareSyncSetup();
123 // Displays spinner-only UI indicating that something is going on in the
124 // background.
125 // TODO(kochi): better to show some message that the user can understand what
126 // is running in the background.
127 void DisplaySpinner();
129 // Displays an error dialog which shows timeout of starting the sync backend.
130 void DisplayTimeout();
132 // Returns true if this object is the active login object.
133 bool IsActiveLogin() const;
135 // If a wizard already exists, return true. Otherwise, return false.
136 bool IsExistingWizardPresent();
138 // If a wizard already exists, focus it and return true.
139 bool FocusExistingWizardIfPresent();
141 // Display the configure sync UI. If |passphrase_failed| is true, the account
142 // requires a passphrase and one hasn't been provided or it was invalid.
143 void DisplayConfigureSync(bool passphrase_failed);
145 // Helper object used to wait for the sync backend to startup.
146 scoped_ptr<SyncStartupTracker> sync_startup_tracker_;
148 // Set to true whenever the sync configure UI is visible. This is used to tell
149 // what stage of the setup wizard the user was in and to update the UMA
150 // histograms in the case that the user cancels out.
151 bool configuring_sync_;
153 // The OneShotTimer object used to timeout of starting the sync backend
154 // service.
155 scoped_ptr<base::OneShotTimer<SyncSetupHandler> > backend_start_timer_;
157 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler);
160 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_SYNC_SETUP_HANDLER_H_