Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 #include "content/public/browser/web_ui.h" | 41 #include "content/public/browser/web_ui.h" |
| 42 #include "google_apis/gaia/gaia_auth_consumer.h" | 42 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 43 #include "google_apis/gaia/gaia_auth_fetcher.h" | 43 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 44 #include "google_apis/gaia/gaia_auth_util.h" | 44 #include "google_apis/gaia/gaia_auth_util.h" |
| 45 #include "google_apis/gaia/gaia_constants.h" | 45 #include "google_apis/gaia/gaia_constants.h" |
| 46 #include "google_apis/gaia/gaia_urls.h" | 46 #include "google_apis/gaia/gaia_urls.h" |
| 47 #include "net/base/url_util.h" | 47 #include "net/base/url_util.h" |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 class InlineSigninHelper : public GaiaAuthConsumer { | 51 class InlineSigninHelper : public GaiaAuthConsumer, |
| 52 public MergeSessionHelper::Observer { | |
| 52 public: | 53 public: |
| 53 InlineSigninHelper( | 54 InlineSigninHelper( |
| 54 base::WeakPtr<InlineLoginHandlerImpl> handler, | 55 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 55 net::URLRequestContextGetter* getter, | 56 net::URLRequestContextGetter* getter, |
| 56 Profile* profile, | 57 Profile* profile, |
| 57 const GURL& current_url, | 58 const GURL& current_url, |
| 58 const std::string& email, | 59 const std::string& email, |
| 59 const std::string& gaia_id, | 60 const std::string& gaia_id, |
| 60 const std::string& password, | 61 const std::string& password, |
| 61 const std::string& session_index, | 62 const std::string& session_index, |
| 62 const std::string& signin_scoped_device_id, | 63 const std::string& signin_scoped_device_id, |
| 63 bool choose_what_to_sync, | 64 bool choose_what_to_sync, |
| 64 bool confirm_untrusted_signin); | 65 bool confirm_untrusted_signin); |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 // Overridden from GaiaAuthConsumer. | 68 // Overridden from GaiaAuthConsumer. |
| 68 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; | 69 void OnClientOAuthSuccess(const ClientOAuthResult& result) override; |
| 69 void OnClientOAuthFailure(const GoogleServiceAuthError& error) | 70 void OnClientOAuthFailure(const GoogleServiceAuthError& error) |
| 70 override; | 71 override; |
| 71 | 72 |
| 73 // Overridden from MergeSessionHelper::Observer. | |
| 74 void MergeSessionCompleted(const std::string& account_id, | |
| 75 const GoogleServiceAuthError& error) override; | |
| 76 | |
| 72 GaiaAuthFetcher gaia_auth_fetcher_; | 77 GaiaAuthFetcher gaia_auth_fetcher_; |
| 73 base::WeakPtr<InlineLoginHandlerImpl> handler_; | 78 base::WeakPtr<InlineLoginHandlerImpl> handler_; |
| 74 Profile* profile_; | 79 Profile* profile_; |
| 75 GURL current_url_; | 80 GURL current_url_; |
| 76 std::string email_; | 81 std::string email_; |
| 77 std::string gaia_id_; | 82 std::string gaia_id_; |
| 78 std::string password_; | 83 std::string password_; |
| 79 std::string session_index_; | 84 std::string session_index_; |
| 80 bool choose_what_to_sync_; | 85 bool choose_what_to_sync_; |
| 81 bool confirm_untrusted_signin_; | 86 bool confirm_untrusted_signin_; |
| 87 // Helper to merge signed in account into the content area. | |
| 88 scoped_ptr<MergeSessionHelper> merge_session_helper_; | |
| 82 | 89 |
| 83 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); | 90 DISALLOW_COPY_AND_ASSIGN(InlineSigninHelper); |
| 84 }; | 91 }; |
| 85 | 92 |
| 86 InlineSigninHelper::InlineSigninHelper( | 93 InlineSigninHelper::InlineSigninHelper( |
| 87 base::WeakPtr<InlineLoginHandlerImpl> handler, | 94 base::WeakPtr<InlineLoginHandlerImpl> handler, |
| 88 net::URLRequestContextGetter* getter, | 95 net::URLRequestContextGetter* getter, |
| 89 Profile* profile, | 96 Profile* profile, |
| 90 const GURL& current_url, | 97 const GURL& current_url, |
| 91 const std::string& email, | 98 const std::string& email, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 if (gaia::AreEmailsSame(email_, primary_email) && | 145 if (gaia::AreEmailsSame(email_, primary_email) && |
| 139 source == signin_metrics::SOURCE_REAUTH && | 146 source == signin_metrics::SOURCE_REAUTH && |
| 140 switches::IsNewProfileManagement() && | 147 switches::IsNewProfileManagement() && |
| 141 !password_.empty() && | 148 !password_.empty() && |
| 142 profiles::IsLockAvailable(profile_)) { | 149 profiles::IsLockAvailable(profile_)) { |
| 143 LocalAuth::SetLocalAuthCredentials(profile_, password_); | 150 LocalAuth::SetLocalAuthCredentials(profile_, password_); |
| 144 } | 151 } |
| 145 | 152 |
| 146 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 153 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || |
| 147 source == signin_metrics::SOURCE_REAUTH) { | 154 source == signin_metrics::SOURCE_REAUTH) { |
| 148 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 155 ProfileOAuth2TokenService* token_service = |
| 149 UpdateCredentials(account_id, result.refresh_token); | 156 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 157 token_service->UpdateCredentials(account_id, result.refresh_token); | |
| 150 | 158 |
| 151 if (signin::IsAutoCloseEnabledInURL(current_url_)) { | 159 if (signin::IsAutoCloseEnabledInURL(current_url_)) { |
| 152 // Close the gaia sign in tab via a task to make sure we aren't in the | 160 // Close the gaia sign in tab via a task to make sure we aren't in the |
| 153 // middle of any webui handler code. | 161 // middle of any webui handler code. |
| 154 base::MessageLoop::current()->PostTask( | 162 base::MessageLoop::current()->PostTask( |
| 155 FROM_HERE, | 163 FROM_HERE, |
| 156 base::Bind(&InlineLoginHandlerImpl::CloseTab, | 164 base::Bind(&InlineLoginHandlerImpl::CloseTab, |
| 157 handler_, | 165 handler_, |
| 158 signin::ShouldShowAccountManagement(current_url_))); | 166 signin::ShouldShowAccountManagement(current_url_))); |
| 159 } | 167 } |
| 168 | |
| 169 SigninClient* signin_client = | |
| 170 ChromeSigninClientFactory::GetForProfile(profile_); | |
| 171 if (signin_client->ShouldMergeSigninCredentialsIntoCookieJar()) { | |
| 172 merge_session_helper_.reset(new MergeSessionHelper( | |
| 173 token_service, GaiaConstants::kChromeSource, | |
| 174 signin_client->GetURLRequestContext(), NULL)); | |
| 175 merge_session_helper_->LogIn(account_id); | |
| 176 } else { | |
| 177 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 178 } | |
|
Roger Tawa OOO till Jul 10th
2015/02/12 14:54:38
As discussed offline, it would be better to refact
Mike Lerman
2015/02/13 19:17:06
Done.
| |
| 160 } else { | 179 } else { |
| 161 ProfileSyncService* sync_service = | 180 ProfileSyncService* sync_service = |
| 162 ProfileSyncServiceFactory::GetForProfile(profile_); | 181 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 163 SigninErrorController* error_controller = | 182 SigninErrorController* error_controller = |
| 164 SigninErrorControllerFactory::GetForProfile(profile_); | 183 SigninErrorControllerFactory::GetForProfile(profile_); |
| 165 | 184 |
| 166 bool is_new_avatar_menu = switches::IsNewAvatarMenu(); | 185 bool is_new_avatar_menu = switches::IsNewAvatarMenu(); |
| 167 | 186 |
| 168 OneClickSigninSyncStarter::StartSyncMode start_mode; | 187 OneClickSigninSyncStarter::StartSyncMode start_mode; |
| 169 if (source == signin_metrics::SOURCE_SETTINGS || choose_what_to_sync_) { | 188 if (source == signin_metrics::SOURCE_SETTINGS || choose_what_to_sync_) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // OneClickSigninSyncStarter will delete itself once the job is done. | 226 // OneClickSigninSyncStarter will delete itself once the job is done. |
| 208 new OneClickSigninSyncStarter( | 227 new OneClickSigninSyncStarter( |
| 209 profile_, browser, | 228 profile_, browser, |
| 210 email_, password_, result.refresh_token, | 229 email_, password_, result.refresh_token, |
| 211 start_mode, | 230 start_mode, |
| 212 contents, | 231 contents, |
| 213 confirmation_required, | 232 confirmation_required, |
| 214 signin::GetNextPageURLForPromoURL(current_url_), | 233 signin::GetNextPageURLForPromoURL(current_url_), |
| 215 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 234 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
| 216 } | 235 } |
| 236 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 217 } | 237 } |
| 218 | |
| 219 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 220 } | 238 } |
| 221 | 239 |
| 222 void InlineSigninHelper::OnClientOAuthFailure( | 240 void InlineSigninHelper::OnClientOAuthFailure( |
| 223 const GoogleServiceAuthError& error) { | 241 const GoogleServiceAuthError& error) { |
| 224 if (handler_) | 242 if (handler_) |
| 225 handler_->HandleLoginError(error.ToString()); | 243 handler_->HandleLoginError(error.ToString()); |
| 226 | 244 |
| 227 AboutSigninInternals* about_signin_internals = | 245 AboutSigninInternals* about_signin_internals = |
| 228 AboutSigninInternalsFactory::GetForProfile(profile_); | 246 AboutSigninInternalsFactory::GetForProfile(profile_); |
| 229 about_signin_internals->OnRefreshTokenReceived("Failure"); | 247 about_signin_internals->OnRefreshTokenReceived("Failure"); |
| 230 | 248 |
| 231 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 249 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 232 } | 250 } |
| 233 | 251 |
| 252 void InlineSigninHelper::MergeSessionCompleted( | |
| 253 const std::string& account_id, | |
| 254 const GoogleServiceAuthError& error) { | |
| 255 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | |
| 256 } | |
| 257 | |
| 234 } // namespace | 258 } // namespace |
| 235 | 259 |
| 236 InlineLoginHandlerImpl::InlineLoginHandlerImpl() | 260 InlineLoginHandlerImpl::InlineLoginHandlerImpl() |
| 237 : confirm_untrusted_signin_(false), | 261 : confirm_untrusted_signin_(false), |
| 238 weak_factory_(this) { | 262 weak_factory_(this) { |
| 239 } | 263 } |
| 240 | 264 |
| 241 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} | 265 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} |
| 242 | 266 |
| 243 // This method is not called with webview sign in enabled. | 267 // This method is not called with webview sign in enabled. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 } | 481 } |
| 458 } | 482 } |
| 459 | 483 |
| 460 if (show_account_management) { | 484 if (show_account_management) { |
| 461 browser->window()->ShowAvatarBubbleFromAvatarButton( | 485 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 462 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 486 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 463 signin::ManageAccountsParams()); | 487 signin::ManageAccountsParams()); |
| 464 } | 488 } |
| 465 } | 489 } |
| 466 } | 490 } |
| OLD | NEW |