Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / sync_setup_handler.h
blobe0b3ba3732d5af324273c6844c011b7029141958
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,
63 DisplayConfigureWithBackendDisabledAndCancel);
64 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, HandleSetupUIWhenSyncDisabled);
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);
83 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin);
85 bool is_configuring_sync() const { return configuring_sync_; }
87 // Display the configure sync UI. If |show_advanced| is true, skip directly
88 // to the "advanced settings" dialog, otherwise give the user the simpler
89 // "Sync Everything" dialog. Overridden by subclasses to allow them to skip
90 // the sync setup dialog if desired.
91 // If |passphrase_failed| is true, then the user previously tried to enter an
92 // invalid passphrase.
93 virtual void DisplayConfigureSync(bool show_advanced, bool passphrase_failed);
95 // Called when configuring sync is done to close the dialog and start syncing.
96 void ConfigureSyncDone();
98 // Helper routine that gets the ProfileSyncService associated with the parent
99 // profile.
100 ProfileSyncService* GetSyncService() const;
102 // Returns the LoginUIService for the parent profile.
103 LoginUIService* GetLoginUIService() const;
105 private:
106 // Callbacks from the page.
107 void OnDidClosePage(const base::ListValue* args);
108 void HandleConfigure(const base::ListValue* args);
109 void HandlePassphraseEntry(const base::ListValue* args);
110 void HandlePassphraseCancel(const base::ListValue* args);
111 void HandleShowSetupUI(const base::ListValue* args);
112 void HandleDoSignOutOnAuthError(const base::ListValue* args);
113 void HandleStartSignin(const base::ListValue* args);
114 void HandleStopSyncing(const base::ListValue* args);
115 void HandleCloseTimeout(const base::ListValue* args);
116 #if !defined(OS_CHROMEOS)
117 // Displays the GAIA login form.
118 void DisplayGaiaLogin();
120 // When web-flow is enabled, displays the Gaia login form in a new tab.
121 // This function is virtual so that tests can override.
122 virtual void DisplayGaiaLoginInNewTabOrWindow();
123 #endif
125 // Helper routine that gets the Profile associated with this object (virtual
126 // so tests can override).
127 virtual Profile* GetProfile() const;
129 // A utility function to call before actually showing setup dialog. Makes sure
130 // that a new dialog can be shown and sets flag that setup is in progress.
131 bool PrepareSyncSetup();
133 // Displays spinner-only UI indicating that something is going on in the
134 // background.
135 // TODO(kochi): better to show some message that the user can understand what
136 // is running in the background.
137 void DisplaySpinner();
139 // Displays an error dialog which shows timeout of starting the sync backend.
140 void DisplayTimeout();
142 // Returns true if this object is the active login object.
143 bool IsActiveLogin() const;
145 // If a wizard already exists, return true. Otherwise, return false.
146 bool IsExistingWizardPresent();
148 // If a wizard already exists, focus it and return true.
149 bool FocusExistingWizardIfPresent();
151 // Helper object used to wait for the sync backend to startup.
152 scoped_ptr<SyncStartupTracker> sync_startup_tracker_;
154 // Set to true whenever the sync configure UI is visible. This is used to tell
155 // what stage of the setup wizard the user was in and to update the UMA
156 // histograms in the case that the user cancels out.
157 bool configuring_sync_;
159 // Weak reference to the profile manager.
160 ProfileManager* const profile_manager_;
162 // The OneShotTimer object used to timeout of starting the sync backend
163 // service.
164 scoped_ptr<base::OneShotTimer<SyncSetupHandler> > backend_start_timer_;
166 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler);
169 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_