Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 300523003: Fix some problems with new reauth: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/signin/about_signin_internals_factory.h" 15 #include "chrome/browser/signin/about_signin_internals_factory.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/browser/sync/profile_sync_service.h" 18 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 21 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
21 #include "chrome/browser/ui/sync/one_click_signin_histogram.h" 22 #include "chrome/browser/ui/sync/one_click_signin_histogram.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "components/signin/core/browser/about_signin_internals.h" 25 #include "components/signin/core/browser/about_signin_internals.h"
25 #include "components/signin/core/browser/profile_oauth2_token_service.h" 26 #include "components/signin/core/browser/profile_oauth2_token_service.h"
26 #include "components/signin/core/browser/signin_error_controller.h" 27 #include "components/signin/core/browser/signin_error_controller.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (handler_) { 100 if (handler_) {
100 contents = handler_->web_ui()->GetWebContents(); 101 contents = handler_->web_ui()->GetWebContents();
101 browser = handler_->GetDesktopBrowser(); 102 browser = handler_->GetDesktopBrowser();
102 } 103 }
103 104
104 AboutSigninInternals* about_signin_internals = 105 AboutSigninInternals* about_signin_internals =
105 AboutSigninInternalsFactory::GetForProfile(profile_); 106 AboutSigninInternalsFactory::GetForProfile(profile_);
106 about_signin_internals->OnRefreshTokenReceived("Successful"); 107 about_signin_internals->OnRefreshTokenReceived("Successful");
107 108
108 signin::Source source = signin::GetSourceForPromoURL(current_url_); 109 signin::Source source = signin::GetSourceForPromoURL(current_url_);
109 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT) { 110 if (source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
111 source == signin::SOURCE_REAUTH) {
110 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 112 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
111 UpdateCredentials(email, refresh_token); 113 UpdateCredentials(email, refresh_token);
112 114
113 if (signin::IsAutoCloseEnabledInURL(current_url_)) { 115 if (signin::IsAutoCloseEnabledInURL(current_url_)) {
114 // Close the gaia sign in tab via a task to make sure we aren't in the 116 // Close the gaia sign in tab via a task to make sure we aren't in the
115 // middle of any webui handler code. 117 // middle of any webui handler code.
116 base::MessageLoop::current()->PostTask( 118 base::MessageLoop::current()->PostTask(
117 FROM_HERE, 119 FROM_HERE,
118 base::Bind(&InlineLoginHandlerImpl::CloseTab, 120 base::Bind(&InlineLoginHandlerImpl::CloseTab,
119 handler_)); 121 handler_));
(...skipping 10 matching lines...) Expand all
130 sync_service && sync_service->HasSyncSetupCompleted()) ? 132 sync_service && sync_service->HasSyncSetupCompleted()) ?
131 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : 133 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE :
132 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : 134 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST :
133 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; 135 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;
134 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = 136 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required =
135 source == signin::SOURCE_SETTINGS || 137 source == signin::SOURCE_SETTINGS ||
136 source == signin::SOURCE_WEBSTORE_INSTALL || 138 source == signin::SOURCE_WEBSTORE_INSTALL ||
137 choose_what_to_sync_ ? 139 choose_what_to_sync_ ?
138 OneClickSigninSyncStarter::NO_CONFIRMATION : 140 OneClickSigninSyncStarter::NO_CONFIRMATION :
139 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; 141 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN;
140 bool start_signin = true;
141 142
142 if (source != signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT) { 143 bool start_signin =
143 start_signin = !OneClickSigninHelper::HandleCrossAccountError( 144 !OneClickSigninHelper::HandleCrossAccountError(
144 contents, "", 145 contents, "",
145 email, password_, refresh_token, 146 email, password_, refresh_token,
146 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT, 147 OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT,
147 source, start_mode, 148 source, start_mode,
148 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, 149 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback,
149 handler_)); 150 handler_));
150 }
151
152 if (start_signin) { 151 if (start_signin) {
153 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. 152 // Call OneClickSigninSyncStarter to exchange oauth code for tokens.
154 // OneClickSigninSyncStarter will delete itself once the job is done. 153 // OneClickSigninSyncStarter will delete itself once the job is done.
155 new OneClickSigninSyncStarter( 154 new OneClickSigninSyncStarter(
156 profile_, browser, 155 profile_, browser,
157 email, password_, refresh_token, 156 email, password_, refresh_token,
158 start_mode, 157 start_mode,
159 contents, 158 contents,
160 confirmation_required, 159 confirmation_required,
161 signin::GetNextPageURLForPromoURL(current_url_), 160 signin::GetNextPageURLForPromoURL(current_url_),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 OneClickSigninHelper::LogHistogramValue( 244 OneClickSigninHelper::LogHistogramValue(
246 source, one_click_signin::HISTOGRAM_ACCEPTED); 245 source, one_click_signin::HISTOGRAM_ACCEPTED);
247 bool switch_to_advanced = 246 bool switch_to_advanced =
248 choose_what_to_sync_ && (source != signin::SOURCE_SETTINGS); 247 choose_what_to_sync_ && (source != signin::SOURCE_SETTINGS);
249 OneClickSigninHelper::LogHistogramValue( 248 OneClickSigninHelper::LogHistogramValue(
250 source, 249 source,
251 switch_to_advanced ? one_click_signin::HISTOGRAM_WITH_ADVANCED : 250 switch_to_advanced ? one_click_signin::HISTOGRAM_WITH_ADVANCED :
252 one_click_signin::HISTOGRAM_WITH_DEFAULTS); 251 one_click_signin::HISTOGRAM_WITH_DEFAULTS);
253 252
254 OneClickSigninHelper::CanOfferFor can_offer_for = 253 OneClickSigninHelper::CanOfferFor can_offer_for =
255 source == signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ?
256 OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT :
257 OneClickSigninHelper::CAN_OFFER_FOR_ALL; 254 OneClickSigninHelper::CAN_OFFER_FOR_ALL;
255 switch (source) {
256 case signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT:
257 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT;
258 break;
259 case signin::SOURCE_REAUTH: {
260 std::string primary_username =
261 SigninManagerFactory::GetForProfile(
262 Profile::FromWebUI(web_ui()))->GetAuthenticatedUsername();
263 if (!gaia::AreEmailsSame(default_email, primary_username))
264 can_offer_for = OneClickSigninHelper::CAN_OFFER_FOR_SECONDARY_ACCOUNT;
265 break;
266 }
267 default:
268 // No need to change |can_offer_for|.
269 break;
270 }
271
258 std::string error_msg; 272 std::string error_msg;
259 bool can_offer = OneClickSigninHelper::CanOffer( 273 bool can_offer = OneClickSigninHelper::CanOffer(
260 contents, can_offer_for, email_, &error_msg); 274 contents, can_offer_for, email_, &error_msg);
261 if (!can_offer) { 275 if (!can_offer) {
262 HandleLoginError(error_msg); 276 HandleLoginError(error_msg);
263 return; 277 return;
264 } 278 }
265 279
266 AboutSigninInternals* about_signin_internals = 280 AboutSigninInternals* about_signin_internals =
267 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui())); 281 AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui()));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 TabStripModel* tab_strip_model = browser->tab_strip_model(); 358 TabStripModel* tab_strip_model = browser->tab_strip_model();
345 if (tab_strip_model) { 359 if (tab_strip_model) {
346 int index = tab_strip_model->GetIndexOfWebContents(tab); 360 int index = tab_strip_model->GetIndexOfWebContents(tab);
347 if (index != TabStripModel::kNoTab) { 361 if (index != TabStripModel::kNoTab) {
348 tab_strip_model->ExecuteContextMenuCommand( 362 tab_strip_model->ExecuteContextMenuCommand(
349 index, TabStripModel::CommandCloseTab); 363 index, TabStripModel::CommandCloseTab);
350 } 364 }
351 } 365 }
352 } 366 }
353 } 367 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698