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; | 32 virtual void Initialize() OVERRIDE; |
29 virtual void RegisterMessages() OVERRIDE; | 33 virtual void RegisterMessages() OVERRIDE; |
30 | 34 |
31 // SyncSetupFlowHandler implementation. | 35 // 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; | 36 virtual void ShowConfigure(const base::DictionaryValue& args) OVERRIDE; |
37 virtual void ShowFatalError() OVERRIDE; | |
37 virtual void ShowPassphraseEntry(const base::DictionaryValue& args) OVERRIDE; | 38 virtual void ShowPassphraseEntry(const base::DictionaryValue& args) OVERRIDE; |
38 virtual void ShowSettingUp() OVERRIDE; | 39 virtual void ShowSettingUp() OVERRIDE; |
39 virtual void ShowSetupDone(const string16& user) OVERRIDE; | 40 virtual void ShowSetupDone(const string16& user) OVERRIDE; |
40 virtual void SetFlow(SyncSetupFlow* flow) OVERRIDE; | 41 virtual void SetFlow(SyncSetupFlow* flow) OVERRIDE; |
41 virtual void Focus() OVERRIDE; | 42 virtual void Focus() OVERRIDE; |
42 | 43 |
43 // GaiaOAuthConsumer implementation. | 44 // GaiaOAuthConsumer implementation. |
44 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 45 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; |
45 virtual void OnGetOAuthTokenFailure( | 46 virtual void OnGetOAuthTokenFailure( |
46 const GoogleServiceAuthError& error) OVERRIDE; | 47 const GoogleServiceAuthError& error) OVERRIDE; |
47 | 48 |
49 // SigninTracker::Observer implementation | |
50 virtual void GaiaCredentialsValid() OVERRIDE; | |
51 virtual void SigninFailed() OVERRIDE; | |
52 virtual void SigninSuccess() OVERRIDE; | |
53 | |
48 static void GetStaticLocalizedValues( | 54 static void GetStaticLocalizedValues( |
49 base::DictionaryValue* localized_strings, | 55 base::DictionaryValue* localized_strings, |
50 content::WebUI* web_ui); | 56 content::WebUI* web_ui); |
51 | 57 |
52 // Initializes the sync setup flow and shows the setup UI. | 58 // Initializes the sync setup flow and shows the setup UI. |
53 void OpenSyncSetup(); | 59 void OpenSyncSetup(); |
54 | 60 |
55 // Terminates the sync setup flow. | 61 // Terminates the sync setup flow. |
56 void CloseSyncSetup(); | 62 void CloseSyncSetup(); |
57 | 63 |
(...skipping 16 matching lines...) Expand all Loading... | |
74 void HandleSubmitAuth(const base::ListValue* args); | 80 void HandleSubmitAuth(const base::ListValue* args); |
75 void HandleConfigure(const base::ListValue* args); | 81 void HandleConfigure(const base::ListValue* args); |
76 void HandlePassphraseEntry(const base::ListValue* args); | 82 void HandlePassphraseEntry(const base::ListValue* args); |
77 void HandlePassphraseCancel(const base::ListValue* args); | 83 void HandlePassphraseCancel(const base::ListValue* args); |
78 void HandleAttachHandler(const base::ListValue* args); | 84 void HandleAttachHandler(const base::ListValue* args); |
79 void HandleShowErrorUI(const base::ListValue* args); | 85 void HandleShowErrorUI(const base::ListValue* args); |
80 void HandleShowSetupUI(const base::ListValue* args); | 86 void HandleShowSetupUI(const base::ListValue* args); |
81 | 87 |
82 SyncSetupFlow* flow() { return flow_; } | 88 SyncSetupFlow* flow() { return flow_; } |
83 | 89 |
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 | 90 // Subclasses must implement this to show the setup UI that's appropriate |
89 // for the page this is contained in. | 91 // for the page this is contained in. |
90 virtual void ShowSetupUI() = 0; | 92 virtual void ShowSetupUI() = 0; |
91 | 93 |
94 // Overridden by subclasses to log stats about the 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 | |
131 // Returns true if the user is already logged in. | |
132 bool IsUserLoggedIn() const; | |
133 | |
93 // If a wizard already exists, focus it and return true. | 134 // If a wizard already exists, focus it and return true. |
94 bool FocusExistingWizard(); | 135 bool FocusExistingWizard(); |
95 | 136 |
96 // Invokes the javascript call to close the setup overlay. | 137 // Invokes the javascript call to close the setup overlay. |
97 void CloseOverlay(); | 138 void CloseOverlay(); |
98 | 139 |
99 // Returns true if the given login data is valid, false otherwise. If the | 140 // 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 | 141 // 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. | 142 // localized error message. Note, |error_message| must not be NULL. |
102 bool IsLoginAuthDataValid(const std::string& username, | 143 bool IsLoginAuthDataValid(const std::string& username, |
103 string16* error_message); | 144 string16* error_message); |
104 | 145 |
105 // Displays the given error message in the login UI. | 146 // Returns the SigninManager for the parent profile. Overridden by tests. |
106 void ShowLoginErrorMessage(const string16& error_message); | 147 virtual SigninManager* GetSignin() const; |
148 | |
149 // Returns the LoginUIService for the parent profile. Overridden by tests. | |
150 virtual LoginUIService* GetLoginUIService() const; | |
151 | |
152 scoped_ptr<SigninTracker> signin_tracker_; | |
James Hawkins
2012/02/10 23:08:01
Document var.
Andrew T Wilson (Slow)
2012/02/11 01:50:45
Done.
| |
107 | 153 |
108 // Weak reference. | 154 // Weak reference. |
109 SyncSetupFlow* flow_; | 155 SyncSetupFlow* flow_; |
110 scoped_ptr<GaiaOAuthFetcher> oauth_login_; | |
111 // Weak reference to the profile manager. | 156 // Weak reference to the profile manager. |
112 ProfileManager* const profile_manager_; | 157 ProfileManager* const profile_manager_; |
113 | 158 |
159 // Cache of the last name the client attempted to authenticate. | |
160 std::string last_attempted_user_email_; | |
161 | |
114 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); | 162 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); |
115 }; | 163 }; |
116 | 164 |
117 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 165 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
OLD | NEW |