OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 9 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
10 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | 10 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
11 #include "chrome/browser/sync/sync_setup_flow_handler.h" | 11 #include "chrome/browser/sync/sync_setup_flow_handler.h" |
12 #include "chrome/browser/ui/webui/options/options_ui.h" | 12 #include "chrome/browser/ui/webui/options/options_ui.h" |
| 13 #include "chrome/browser/ui/webui/signin/signin_tracker.h" |
13 | 14 |
| 15 class LoginUIService; |
| 16 class SigninManager; |
14 class SyncSetupFlow; | 17 class SyncSetupFlow; |
15 class ProfileManager; | 18 class ProfileManager; |
16 | 19 |
17 class SyncSetupHandler : public GaiaOAuthConsumer, | 20 class SyncSetupHandler : public GaiaOAuthConsumer, |
18 public OptionsPageUIHandler, | 21 public OptionsPageUIHandler, |
19 public SyncSetupFlowHandler { | 22 public SyncSetupFlowHandler, |
| 23 public SigninTracker::Observer { |
20 public: | 24 public: |
21 // Constructs a new SyncSetupHandler. |profile_manager| may be NULL. | 25 // Constructs a new SyncSetupHandler. |profile_manager| may be NULL. |
22 explicit SyncSetupHandler(ProfileManager* profile_manager); | 26 explicit SyncSetupHandler(ProfileManager* profile_manager); |
23 virtual ~SyncSetupHandler(); | 27 virtual ~SyncSetupHandler(); |
24 | 28 |
25 // OptionsPageUIHandler implementation. | 29 // OptionsPageUIHandler implementation. |
26 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) | 30 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) |
27 OVERRIDE; | 31 OVERRIDE; |
28 virtual void Initialize() OVERRIDE; | |
29 virtual void RegisterMessages() OVERRIDE; | 32 virtual void RegisterMessages() OVERRIDE; |
30 | 33 |
31 // SyncSetupFlowHandler implementation. | 34 // SyncSetupFlowHandler implementation. |
32 virtual void ShowOAuthLogin() OVERRIDE; | |
33 virtual void ShowGaiaLogin(const base::DictionaryValue& args) OVERRIDE; | |
34 virtual void ShowGaiaSuccessAndClose() OVERRIDE; | |
35 virtual void ShowGaiaSuccessAndSettingUp() OVERRIDE; | |
36 virtual void ShowConfigure(const base::DictionaryValue& args) OVERRIDE; | 35 virtual void ShowConfigure(const base::DictionaryValue& args) OVERRIDE; |
| 36 virtual void ShowFatalError() OVERRIDE; |
37 virtual void ShowPassphraseEntry(const base::DictionaryValue& args) OVERRIDE; | 37 virtual void ShowPassphraseEntry(const base::DictionaryValue& args) OVERRIDE; |
38 virtual void ShowSettingUp() OVERRIDE; | 38 virtual void ShowSettingUp() OVERRIDE; |
39 virtual void ShowSetupDone(const string16& user) OVERRIDE; | 39 virtual void ShowSetupDone(const string16& user) OVERRIDE; |
40 virtual void SetFlow(SyncSetupFlow* flow) OVERRIDE; | 40 virtual void SetFlow(SyncSetupFlow* flow) OVERRIDE; |
41 virtual void Focus() OVERRIDE; | 41 virtual void Focus() OVERRIDE; |
42 | 42 |
43 // GaiaOAuthConsumer implementation. | 43 // GaiaOAuthConsumer implementation. |
44 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 44 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; |
45 virtual void OnGetOAuthTokenFailure( | 45 virtual void OnGetOAuthTokenFailure( |
46 const GoogleServiceAuthError& error) OVERRIDE; | 46 const GoogleServiceAuthError& error) OVERRIDE; |
47 | 47 |
| 48 // SigninTracker::Observer implementation |
| 49 virtual void GaiaCredentialsValid() OVERRIDE; |
| 50 virtual void SigninFailed() OVERRIDE; |
| 51 virtual void SigninSuccess() OVERRIDE; |
| 52 |
48 static void GetStaticLocalizedValues( | 53 static void GetStaticLocalizedValues( |
49 base::DictionaryValue* localized_strings, | 54 base::DictionaryValue* localized_strings, |
50 content::WebUI* web_ui); | 55 content::WebUI* web_ui); |
51 | 56 |
52 // Initializes the sync setup flow and shows the setup UI. | 57 // Initializes the sync setup flow and shows the setup UI. |
53 void OpenSyncSetup(); | 58 void OpenSyncSetup(); |
54 | 59 |
55 // Terminates the sync setup flow. | 60 // Terminates the sync setup flow. |
56 void CloseSyncSetup(); | 61 void CloseSyncSetup(); |
57 | 62 |
(...skipping 16 matching lines...) Expand all Loading... |
74 void HandleSubmitAuth(const base::ListValue* args); | 79 void HandleSubmitAuth(const base::ListValue* args); |
75 void HandleConfigure(const base::ListValue* args); | 80 void HandleConfigure(const base::ListValue* args); |
76 void HandlePassphraseEntry(const base::ListValue* args); | 81 void HandlePassphraseEntry(const base::ListValue* args); |
77 void HandlePassphraseCancel(const base::ListValue* args); | 82 void HandlePassphraseCancel(const base::ListValue* args); |
78 void HandleAttachHandler(const base::ListValue* args); | 83 void HandleAttachHandler(const base::ListValue* args); |
79 void HandleShowErrorUI(const base::ListValue* args); | 84 void HandleShowErrorUI(const base::ListValue* args); |
80 void HandleShowSetupUI(const base::ListValue* args); | 85 void HandleShowSetupUI(const base::ListValue* args); |
81 | 86 |
82 SyncSetupFlow* flow() { return flow_; } | 87 SyncSetupFlow* flow() { return flow_; } |
83 | 88 |
84 // Subclasses must implement to step the SyncSetupWizard to the correct state | |
85 // before showing the Setup UI. | |
86 virtual void StepWizardForShowSetupUI() = 0; | |
87 | |
88 // Subclasses must implement this to show the setup UI that's appropriate | 89 // Subclasses must implement this to show the setup UI that's appropriate |
89 // for the page this is contained in. | 90 // for the page this is contained in. |
90 virtual void ShowSetupUI() = 0; | 91 virtual void ShowSetupUI() = 0; |
91 | 92 |
| 93 // Overridden by subclasses (like SyncPromoHandler) to log stats about the |
| 94 // user's signin activity. |
| 95 virtual void RecordSignin(); |
| 96 |
92 private: | 97 private: |
| 98 // Helper routine that gets the ProfileSyncService associated with the parent |
| 99 // profile. |
| 100 class ProfileSyncService* GetSyncService() const; |
| 101 |
| 102 // Start up the sync setup configuration wizard. |
| 103 void StartConfigureSync(); |
| 104 |
| 105 // Shows the GAIA login success page then exits. |
| 106 void DisplayGaiaSuccessAndClose(); |
| 107 |
| 108 // Displays the GAIA login success page then transitions to sync setup. |
| 109 void DisplayGaiaSuccessAndSettingUp(); |
| 110 |
| 111 // Displays the GAIA login form. If |fatal_error| is true, displays the fatal |
| 112 // error UI. |
| 113 void DisplayGaiaLogin(bool fatal_error); |
| 114 |
| 115 // Displays the GAIA login form with a custom error message (used for errors |
| 116 // like "email address already in use by another profile"). No message |
| 117 // displayed if |error_message| is empty. Displays fatal error UI if |
| 118 // |fatal_error| = true. |
| 119 void DisplayGaiaLoginWithErrorMessage(const string16& error_message, |
| 120 bool fatal_error); |
| 121 |
| 122 // Returns true if we're the active login object. |
| 123 bool IsActiveLogin() const; |
| 124 |
| 125 // Initiates a login via the signin manager. |
| 126 void TryLogin(const std::string& username, |
| 127 const std::string& password, |
| 128 const std::string& captcha, |
| 129 const std::string& access_code); |
| 130 |
93 // If a wizard already exists, focus it and return true. | 131 // If a wizard already exists, focus it and return true. |
94 bool FocusExistingWizard(); | 132 bool FocusExistingWizardIfPresent(); |
95 | 133 |
96 // Invokes the javascript call to close the setup overlay. | 134 // Invokes the javascript call to close the setup overlay. |
97 void CloseOverlay(); | 135 void CloseOverlay(); |
98 | 136 |
99 // Returns true if the given login data is valid, false otherwise. If the | 137 // Returns true if the given login data is valid, false otherwise. If the |
100 // login data is not valid then on return |error_message| will be set to a | 138 // login data is not valid then on return |error_message| will be set to a |
101 // localized error message. Note, |error_message| must not be NULL. | 139 // localized error message. Note, |error_message| must not be NULL. |
102 bool IsLoginAuthDataValid(const std::string& username, | 140 bool IsLoginAuthDataValid(const std::string& username, |
103 string16* error_message); | 141 string16* error_message); |
104 | 142 |
105 // Displays the given error message in the login UI. | 143 // Returns the SigninManager for the parent profile. Overridden by tests. |
106 void ShowLoginErrorMessage(const string16& error_message); | 144 virtual SigninManager* GetSignin() const; |
| 145 |
| 146 // Returns the LoginUIService for the parent profile. Overridden by tests. |
| 147 virtual LoginUIService* GetLoginUIService() const; |
| 148 |
| 149 // The SigninTracker object used to determine when the user has fully signed |
| 150 // in (this requires waiting for various services to initialize and tracking |
| 151 // errors from multiple sources). Should only be non-null while the login UI |
| 152 // is visible. |
| 153 scoped_ptr<SigninTracker> signin_tracker_; |
107 | 154 |
108 // Weak reference. | 155 // Weak reference. |
109 SyncSetupFlow* flow_; | 156 SyncSetupFlow* flow_; |
110 scoped_ptr<GaiaOAuthFetcher> oauth_login_; | |
111 // Weak reference to the profile manager. | 157 // Weak reference to the profile manager. |
112 ProfileManager* const profile_manager_; | 158 ProfileManager* const profile_manager_; |
113 | 159 |
| 160 // Cache of the last name the client attempted to authenticate. |
| 161 std::string last_attempted_user_email_; |
| 162 |
114 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); | 163 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); |
115 }; | 164 }; |
116 | 165 |
117 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 166 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
OLD | NEW |