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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 10555005: Address bug where the one-click sign-in bar would never show again once (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: lint Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 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 #include "chrome/browser/ui/sync/one_click_signin_helper.h" 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/infobars/infobar_tab_helper.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_info_cache.h" 17 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/signin/signin_manager.h" 19 #include "chrome/browser/signin/signin_manager.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/sync/profile_sync_service.h" 21 #include "chrome/browser/sync/profile_sync_service.h"
21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
22 #include "chrome/browser/tab_contents/tab_util.h" 23 #include "chrome/browser/tab_contents/tab_util.h"
23 #include "chrome/browser/ui/browser_finder.h" 24 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 virtual bool Cancel() OVERRIDE; 65 virtual bool Cancel() OVERRIDE;
65 virtual string16 GetLinkText() const OVERRIDE; 66 virtual string16 GetLinkText() const OVERRIDE;
66 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; 67 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
67 68
68 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE; 69 virtual InfoBarAutomationType GetInfoBarAutomationType() const OVERRIDE;
69 70
70 // Set the profile preference to turn off one-click sign in so that it won't 71 // Set the profile preference to turn off one-click sign in so that it won't
71 // show again in this profile. 72 // show again in this profile.
72 void DisableOneClickSignIn(); 73 void DisableOneClickSignIn();
73 74
75 // Add a specific email to the list of emails rejected for one-click
76 // sign-in, for this profile.
77 void AddEmailToOneClickRejectedList(const std::string& email);
78
74 // Record the specified action in the histogram for one-click sign in. 79 // Record the specified action in the histogram for one-click sign in.
75 void RecordHistogramAction(int action); 80 void RecordHistogramAction(int action);
76 81
77 // Information about the account that has just logged in. 82 // Information about the account that has just logged in.
78 std::string session_index_; 83 std::string session_index_;
79 std::string email_; 84 std::string email_;
80 std::string password_; 85 std::string password_;
81 86
82 // Whether any UI controls in the infobar were pressed or not. 87 // Whether any UI controls in the infobar were pressed or not.
83 bool button_pressed_; 88 bool button_pressed_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // The starter deletes itself once its done. 144 // The starter deletes itself once its done.
140 Profile* profile = 145 Profile* profile =
141 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 146 Profile::FromBrowserContext(web_contents->GetBrowserContext());
142 new OneClickSigninSyncStarter(profile, session_index, email, password, 147 new OneClickSigninSyncStarter(profile, session_index, email, password,
143 start_mode); 148 start_mode);
144 } 149 }
145 150
146 } // namespace 151 } // namespace
147 152
148 bool OneClickLoginInfoBarDelegate::Accept() { 153 bool OneClickLoginInfoBarDelegate::Accept() {
154 // User has accepted one-click sign-in for this account. Never ask again for
155 // this profile.
149 DisableOneClickSignIn(); 156 DisableOneClickSignIn();
150 content::WebContents* web_contents = owner()->web_contents(); 157 content::WebContents* web_contents = owner()->web_contents();
151 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); 158 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED);
152 browser::FindBrowserWithWebContents(web_contents)->window()-> 159 browser::FindBrowserWithWebContents(web_contents)->window()->
153 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, 160 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents,
154 session_index_, email_, password_)); 161 session_index_, email_, password_));
155 button_pressed_ = true; 162 button_pressed_ = true;
156 return true; 163 return true;
157 } 164 }
158 165
159 bool OneClickLoginInfoBarDelegate::Cancel() { 166 bool OneClickLoginInfoBarDelegate::Cancel() {
160 DisableOneClickSignIn(); 167 AddEmailToOneClickRejectedList(email_);
161 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); 168 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED);
162 button_pressed_ = true; 169 button_pressed_ = true;
163 return true; 170 return true;
164 } 171 }
165 172
166 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { 173 string16 OneClickLoginInfoBarDelegate::GetLinkText() const {
167 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 174 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
168 } 175 }
169 176
170 bool OneClickLoginInfoBarDelegate::LinkClicked( 177 bool OneClickLoginInfoBarDelegate::LinkClicked(
(...skipping 12 matching lines...) Expand all
183 return ONE_CLICK_LOGIN_INFOBAR; 190 return ONE_CLICK_LOGIN_INFOBAR;
184 } 191 }
185 192
186 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { 193 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() {
187 PrefService* pref_service = 194 PrefService* pref_service =
188 TabContents::FromWebContents(owner()->web_contents())-> 195 TabContents::FromWebContents(owner()->web_contents())->
189 profile()->GetPrefs(); 196 profile()->GetPrefs();
190 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); 197 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false);
191 } 198 }
192 199
200 void OneClickLoginInfoBarDelegate::AddEmailToOneClickRejectedList(
201 const std::string& email) {
202 PrefService* pref_service =
203 TabContents::FromWebContents(owner()->web_contents())->
204 profile()->GetPrefs();
205 ListPrefUpdate updater(pref_service,
206 prefs::kReverseAutologinRejectedEmailList);
207 updater->AppendIfNotPresent(base::Value::CreateStringValue(email));
208 }
209
193 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { 210 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) {
194 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, 211 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action,
195 one_click_signin::HISTOGRAM_MAX); 212 one_click_signin::HISTOGRAM_MAX);
196 } 213 }
197 214
198 // static 215 // static
199 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, 216 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents,
217 const std::string& email,
200 bool check_connected) { 218 bool check_connected) {
201 if (!web_contents) 219 if (!web_contents)
202 return false; 220 return false;
203 221
204 if (web_contents->GetBrowserContext()->IsOffTheRecord()) 222 if (web_contents->GetBrowserContext()->IsOffTheRecord())
205 return false; 223 return false;
206 224
207 if (!ProfileSyncService::IsSyncEnabled()) 225 if (!ProfileSyncService::IsSyncEnabled())
208 return false; 226 return false;
209 227
210 Profile* profile = 228 Profile* profile =
211 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 229 Profile::FromBrowserContext(web_contents->GetBrowserContext());
212 if (!profile) 230 if (!profile)
213 return false; 231 return false;
214 232
215 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled)) 233 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled))
216 return false; 234 return false;
217 235
218 if (!SigninManager::AreSigninCookiesAllowed(profile)) 236 if (!SigninManager::AreSigninCookiesAllowed(profile))
219 return false; 237 return false;
220 238
221 if (check_connected) { 239 if (check_connected) {
222 SigninManager* manager = 240 SigninManager* manager =
223 SigninManagerFactory::GetForProfile(profile); 241 SigninManagerFactory::GetForProfile(profile);
224 if (!manager) 242 if (!manager)
225 return false; 243 return false;
226 244
227 if (!manager->GetAuthenticatedUsername().empty()) 245 if (!manager->GetAuthenticatedUsername().empty())
228 return false; 246 return false;
247
248 // Make sure this username is not prohibited by policy.
249 if (!manager->IsAllowedUsername(email))
250 return false;
251
252 // If email was already rejected by this profile for one-click sign-in.
253 if (!email.empty()) {
254 const ListValue* rejected_emails = profile->GetPrefs()->GetList(
255 prefs::kReverseAutologinRejectedEmailList);
256 if (!rejected_emails->empty()) {
257 const Value* email_value = Value::CreateStringValue(email);
258 ListValue::const_iterator iter = rejected_emails->Find(
259 *email_value);
260 if (iter != rejected_emails->end())
261 return false;
262 }
263 }
229 } 264 }
230 265
231 return true; 266 return true;
232 } 267 }
233 268
234 // static 269 // static
235 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, 270 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request,
236 int child_id, 271 int child_id,
237 int route_id) { 272 int route_id) {
238 // See if the response contains the Google-Accounts-SignIn header. 273 // See if the response contains the Google-Accounts-SignIn header.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // static 311 // static
277 void OneClickSigninHelper::ShowInfoBarUIThread( 312 void OneClickSigninHelper::ShowInfoBarUIThread(
278 const std::string& session_index, 313 const std::string& session_index,
279 const std::string& email, 314 const std::string& email,
280 int child_id, 315 int child_id,
281 int route_id) { 316 int route_id) {
282 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 317 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
283 318
284 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, 319 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id,
285 route_id); 320 route_id);
286 if (!web_contents || !CanOffer(web_contents, true)) 321 if (!web_contents || !CanOffer(web_contents, email, true))
287 return; 322 return;
288 323
289 // If some profile, not just the current one, is already connected to this 324 // If some profile, not just the current one, is already connected to this
290 // account, don't show the infobar. 325 // account, don't show the infobar.
291 if (g_browser_process) { 326 if (g_browser_process) {
292 ProfileManager* manager = g_browser_process->profile_manager(); 327 ProfileManager* manager = g_browser_process->profile_manager();
293 if (manager) { 328 if (manager) {
294 string16 email16 = UTF8ToUTF16(email); 329 string16 email16 = UTF8ToUTF16(email);
295 ProfileInfoCache& cache = manager->GetProfileInfoCache(); 330 ProfileInfoCache& cache = manager->GetProfileInfoCache();
296 331
297 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 332 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
298 if (email16 == cache.GetUserNameOfProfileAtIndex(i)) 333 if (email16 == cache.GetUserNameOfProfileAtIndex(i))
299 return; 334 return;
300 } 335 }
301 } 336 }
302 } 337 }
Roger Tawa OOO till Jul 10th 2012/06/27 21:17:08 how about this if block? Can it be moved to CanOf
mathp 2012/06/29 13:44:00 Done.
303 338
304 // Make sure this username is not prohibited by policy.
305 Profile* profile =
306 Profile::FromBrowserContext(web_contents->GetBrowserContext());
307 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
308 if (!signin->IsAllowedUsername(email))
309 return;
310
311 TabContents* tab_contents = TabContents::FromWebContents(web_contents); 339 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
312 if (!tab_contents) 340 if (!tab_contents)
313 return; 341 return;
314 342
315 // Save the email in the one-click signin manager. The manager may 343 // Save the email in the one-click signin manager. The manager may
316 // not exist if the contents is incognito or if the profile is already 344 // not exist if the contents is incognito or if the profile is already
317 // connected to a Google account. 345 // connected to a Google account.
318 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper(); 346 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper();
319 if (helper) 347 if (helper)
320 helper->SaveSessionIndexAndEmail(session_index, email); 348 helper->SaveSessionIndexAndEmail(session_index, email);
(...skipping 26 matching lines...) Expand all
347 session_index_ = session_index; 375 session_index_ = session_index;
348 email_ = email; 376 email_ = email;
349 } 377 }
350 378
351 void OneClickSigninHelper::SavePassword(const std::string& password) { 379 void OneClickSigninHelper::SavePassword(const std::string& password) {
352 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of 380 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of
353 // challenge, its possible for the user to never complete the signin. 381 // challenge, its possible for the user to never complete the signin.
354 // Should have a way to detect this and clear the password member. 382 // Should have a way to detect this and clear the password member.
355 password_ = password; 383 password_ = password;
356 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698