Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / sync_setup_handler.h
blob9ae3f0f54fd012b150cd7b861888aaf4adbf4638
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_SYNC_SETUP_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_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 ProfileManager;
17 class ProfileSyncService;
18 class SigninManagerBase;
20 namespace content {
21 class WebContents;
24 class SyncSetupHandler : public options::OptionsPageUIHandler,
25 public SyncStartupTracker::Observer,
26 public LoginUIService::LoginUI {
27 public:
28 // Constructs a new SyncSetupHandler. |profile_manager| may be NULL.
29 explicit SyncSetupHandler(ProfileManager* profile_manager);
30 virtual ~SyncSetupHandler();
32 // OptionsPageUIHandler implementation.
33 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings)
34 OVERRIDE;
35 virtual void RegisterMessages() OVERRIDE;
37 // SyncStartupTracker::Observer implementation;
38 virtual void SyncStartupCompleted() OVERRIDE;
39 virtual void SyncStartupFailed() OVERRIDE;
41 // LoginUIService::LoginUI implementation.
42 virtual void FocusUI() OVERRIDE;
43 virtual void CloseUI() OVERRIDE;
45 static void GetStaticLocalizedValues(
46 base::DictionaryValue* localized_strings,
47 content::WebUI* web_ui);
49 // Initializes the sync setup flow and shows the setup UI.
50 void OpenSyncSetup();
52 // Shows advanced configuration dialog without going through sign in dialog.
53 // Kicks the sync backend if necessary with showing spinner dialog until it
54 // gets ready.
55 void OpenConfigureSync();
57 // Terminates the sync setup flow.
58 void CloseSyncSetup();
60 protected:
61 friend class SyncSetupHandlerTest;
62 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, DisplayBasicLogin);
63 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest,
64 DisplayConfigureWithBackendDisabledAndCancel);
65 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption);
66 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn);
67 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase);
68 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncEverything);
69 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncNothing);
70 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncAllManually);
71 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestPassphraseStillRequired);
72 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncIndividualTypes);
73 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TurnOnEncryptAll);
74 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, UnsuccessfullySetPassphrase);
75 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
76 UnrecoverableErrorInitializingSync);
77 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
78 GaiaErrorInitializingSync);
79 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleCaptcha);
80 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure);
81 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest,
82 SubmitAuthWithInvalidUsername);
84 bool is_configuring_sync() const { return configuring_sync_; }
86 // Display the configure sync UI. If |show_advanced| is true, skip directly
87 // to the "advanced settings" dialog, otherwise give the user the simpler
88 // "Sync Everything" dialog. Overridden by subclasses to allow them to skip
89 // the sync setup dialog if desired.
90 // If |passphrase_failed| is true, then the user previously tried to enter an
91 // invalid passphrase.
92 virtual void DisplayConfigureSync(bool show_advanced, bool passphrase_failed);
94 // Called when configuring sync is done to close the dialog and start syncing.
95 void ConfigureSyncDone();
97 // Helper routine that gets the ProfileSyncService associated with the parent
98 // profile.
99 ProfileSyncService* GetSyncService() const;
101 // Returns the LoginUIService for the parent profile.
102 LoginUIService* GetLoginUIService() const;
104 private:
105 // Callbacks from the page.
106 void OnDidClosePage(const base::ListValue* args);
107 void HandleConfigure(const base::ListValue* args);
108 void HandlePassphraseEntry(const base::ListValue* args);
109 void HandlePassphraseCancel(const base::ListValue* args);
110 void HandleShowSetupUI(const base::ListValue* args);
111 void HandleDoSignOutOnAuthError(const base::ListValue* args);
112 void HandleStartSignin(const base::ListValue* args);
113 void HandleStopSyncing(const base::ListValue* args);
114 void HandleCloseTimeout(const base::ListValue* args);
115 #if !defined(OS_CHROMEOS)
116 // Displays the GAIA login form.
117 void DisplayGaiaLogin();
119 // When web-flow is enabled, displays the Gaia login form in a new tab.
120 // This function is virtual so that tests can override.
121 virtual void DisplayGaiaLoginInNewTabOrWindow();
122 #endif
124 // Helper routine that gets the Profile associated with this object (virtual
125 // so tests can override).
126 virtual Profile* GetProfile() const;
128 // A utility function to call before actually showing setup dialog. Makes sure
129 // that a new dialog can be shown and sets flag that setup is in progress.
130 bool PrepareSyncSetup();
132 // Displays spinner-only UI indicating that something is going on in the
133 // background.
134 // TODO(kochi): better to show some message that the user can understand what
135 // is running in the background.
136 void DisplaySpinner();
138 // Displays an error dialog which shows timeout of starting the sync backend.
139 void DisplayTimeout();
141 // Returns true if this object is the active login object.
142 bool IsActiveLogin() const;
144 // If a wizard already exists, return true. Otherwise, return false.
145 bool IsExistingWizardPresent();
147 // If a wizard already exists, focus it and return true.
148 bool FocusExistingWizardIfPresent();
150 // Helper object used to wait for the sync backend to startup.
151 scoped_ptr<SyncStartupTracker> sync_startup_tracker_;
153 // Set to true whenever the sync configure UI is visible. This is used to tell
154 // what stage of the setup wizard the user was in and to update the UMA
155 // histograms in the case that the user cancels out.
156 bool configuring_sync_;
158 // Weak reference to the profile manager.
159 ProfileManager* const profile_manager_;
161 // The OneShotTimer object used to timeout of starting the sync backend
162 // service.
163 scoped_ptr<base::OneShotTimer<SyncSetupHandler> > backend_start_timer_;
165 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler);
168 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_