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

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: Moved one if 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 OneClickSigninSyncStarter::StartSyncMode start_mode) { 143 OneClickSigninSyncStarter::StartSyncMode start_mode) {
139 // The starter deletes itself once its done. 144 // The starter deletes itself once its done.
140 Browser* browser = browser::FindBrowserWithWebContents(web_contents); 145 Browser* browser = browser::FindBrowserWithWebContents(web_contents);
141 new OneClickSigninSyncStarter(browser, session_index, email, password, 146 new OneClickSigninSyncStarter(browser, session_index, email, password,
142 start_mode); 147 start_mode);
143 } 148 }
144 149
145 } // namespace 150 } // namespace
146 151
147 bool OneClickLoginInfoBarDelegate::Accept() { 152 bool OneClickLoginInfoBarDelegate::Accept() {
153 // User has accepted one-click sign-in for this account. Never ask again for
154 // this profile.
148 DisableOneClickSignIn(); 155 DisableOneClickSignIn();
149 content::WebContents* web_contents = owner()->web_contents(); 156 content::WebContents* web_contents = owner()->web_contents();
150 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); 157 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED);
151 browser::FindBrowserWithWebContents(web_contents)->window()-> 158 browser::FindBrowserWithWebContents(web_contents)->window()->
152 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents, 159 ShowOneClickSigninBubble(base::Bind(&StartSync, web_contents,
153 session_index_, email_, password_)); 160 session_index_, email_, password_));
154 button_pressed_ = true; 161 button_pressed_ = true;
155 return true; 162 return true;
156 } 163 }
157 164
158 bool OneClickLoginInfoBarDelegate::Cancel() { 165 bool OneClickLoginInfoBarDelegate::Cancel() {
159 DisableOneClickSignIn(); 166 AddEmailToOneClickRejectedList(email_);
160 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); 167 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED);
161 button_pressed_ = true; 168 button_pressed_ = true;
162 return true; 169 return true;
163 } 170 }
164 171
165 string16 OneClickLoginInfoBarDelegate::GetLinkText() const { 172 string16 OneClickLoginInfoBarDelegate::GetLinkText() const {
166 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 173 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
167 } 174 }
168 175
169 bool OneClickLoginInfoBarDelegate::LinkClicked( 176 bool OneClickLoginInfoBarDelegate::LinkClicked(
(...skipping 12 matching lines...) Expand all
182 return ONE_CLICK_LOGIN_INFOBAR; 189 return ONE_CLICK_LOGIN_INFOBAR;
183 } 190 }
184 191
185 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() { 192 void OneClickLoginInfoBarDelegate::DisableOneClickSignIn() {
186 PrefService* pref_service = 193 PrefService* pref_service =
187 TabContents::FromWebContents(owner()->web_contents())-> 194 TabContents::FromWebContents(owner()->web_contents())->
188 profile()->GetPrefs(); 195 profile()->GetPrefs();
189 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); 196 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false);
190 } 197 }
191 198
199 void OneClickLoginInfoBarDelegate::AddEmailToOneClickRejectedList(
200 const std::string& email) {
201 PrefService* pref_service =
202 TabContents::FromWebContents(owner()->web_contents())->
203 profile()->GetPrefs();
204 ListPrefUpdate updater(pref_service,
205 prefs::kReverseAutologinRejectedEmailList);
206 updater->AppendIfNotPresent(base::Value::CreateStringValue(email));
207 }
208
192 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { 209 void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) {
193 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, 210 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action,
194 one_click_signin::HISTOGRAM_MAX); 211 one_click_signin::HISTOGRAM_MAX);
195 } 212 }
196 213
197 // static 214 // static
198 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, 215 bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents,
216 const std::string& email,
199 bool check_connected) { 217 bool check_connected) {
200 if (!web_contents) 218 if (!web_contents)
201 return false; 219 return false;
202 220
203 if (web_contents->GetBrowserContext()->IsOffTheRecord()) 221 if (web_contents->GetBrowserContext()->IsOffTheRecord())
204 return false; 222 return false;
205 223
206 if (!ProfileSyncService::IsSyncEnabled()) 224 if (!ProfileSyncService::IsSyncEnabled())
207 return false; 225 return false;
208 226
209 Profile* profile = 227 Profile* profile =
210 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 228 Profile::FromBrowserContext(web_contents->GetBrowserContext());
211 if (!profile) 229 if (!profile)
212 return false; 230 return false;
213 231
214 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled)) 232 if (!profile->GetPrefs()->GetBoolean(prefs::kReverseAutologinEnabled))
215 return false; 233 return false;
216 234
217 if (!SigninManager::AreSigninCookiesAllowed(profile)) 235 if (!SigninManager::AreSigninCookiesAllowed(profile))
218 return false; 236 return false;
219 237
220 if (check_connected) { 238 if (check_connected) {
221 SigninManager* manager = 239 SigninManager* manager =
222 SigninManagerFactory::GetForProfile(profile); 240 SigninManagerFactory::GetForProfile(profile);
223 if (!manager) 241 if (!manager)
224 return false; 242 return false;
225 243
226 if (!manager->GetAuthenticatedUsername().empty()) 244 if (!manager->GetAuthenticatedUsername().empty())
227 return false; 245 return false;
246
247 // Make sure this username is not prohibited by policy.
248 if (!manager->IsAllowedUsername(email))
249 return false;
250
251 // If some profile, not just the current one, is already connected to this
252 // account, don't show the infobar.
253 if (g_browser_process) {
254 ProfileManager* manager = g_browser_process->profile_manager();
255 if (manager) {
256 string16 email16 = UTF8ToUTF16(email);
257 ProfileInfoCache& cache = manager->GetProfileInfoCache();
258
259 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
260 VLOG(1) << cache.GetUserNameOfProfileAtIndex(i);
Roger Tawa OOO till Jul 10th 2012/06/29 14:33:44 do we need to leave the VLOG in before commit?
mathp 2012/06/29 14:36:16 Done.
261 if (email16 == cache.GetUserNameOfProfileAtIndex(i))
262 return false;
263 }
264 }
265 }
266
267 // If email was already rejected by this profile for one-click sign-in.
268 if (!email.empty()) {
269 const ListValue* rejected_emails = profile->GetPrefs()->GetList(
270 prefs::kReverseAutologinRejectedEmailList);
271 if (!rejected_emails->empty()) {
272 const Value* email_value = Value::CreateStringValue(email);
273 ListValue::const_iterator iter = rejected_emails->Find(
274 *email_value);
275 if (iter != rejected_emails->end())
276 return false;
277 }
278 }
228 } 279 }
229 280
230 return true; 281 return true;
231 } 282 }
232 283
233 // static 284 // static
234 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request, 285 void OneClickSigninHelper::ShowInfoBarIfPossible(net::URLRequest* request,
235 int child_id, 286 int child_id,
236 int route_id) { 287 int route_id) {
237 // See if the response contains the Google-Accounts-SignIn header. 288 // See if the response contains the Google-Accounts-SignIn header.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // static 326 // static
276 void OneClickSigninHelper::ShowInfoBarUIThread( 327 void OneClickSigninHelper::ShowInfoBarUIThread(
277 const std::string& session_index, 328 const std::string& session_index,
278 const std::string& email, 329 const std::string& email,
279 int child_id, 330 int child_id,
280 int route_id) { 331 int route_id) {
281 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 332 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
282 333
283 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, 334 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id,
284 route_id); 335 route_id);
285 if (!web_contents || !CanOffer(web_contents, true)) 336 if (!web_contents || !CanOffer(web_contents, email, true))
286 return;
287
288 // If some profile, not just the current one, is already connected to this
289 // account, don't show the infobar.
290 if (g_browser_process) {
291 ProfileManager* manager = g_browser_process->profile_manager();
292 if (manager) {
293 string16 email16 = UTF8ToUTF16(email);
294 ProfileInfoCache& cache = manager->GetProfileInfoCache();
295
296 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
297 if (email16 == cache.GetUserNameOfProfileAtIndex(i))
298 return;
299 }
300 }
301 }
302
303 // Make sure this username is not prohibited by policy.
304 Profile* profile =
305 Profile::FromBrowserContext(web_contents->GetBrowserContext());
306 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
307 if (!signin->IsAllowedUsername(email))
308 return; 337 return;
309 338
310 TabContents* tab_contents = TabContents::FromWebContents(web_contents); 339 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
311 if (!tab_contents) 340 if (!tab_contents)
312 return; 341 return;
313 342
314 // 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
315 // 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
316 // connected to a Google account. 345 // connected to a Google account.
317 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper(); 346 OneClickSigninHelper* helper = tab_contents->one_click_signin_helper();
(...skipping 28 matching lines...) Expand all
346 session_index_ = session_index; 375 session_index_ = session_index;
347 email_ = email; 376 email_ = email;
348 } 377 }
349 378
350 void OneClickSigninHelper::SavePassword(const std::string& password) { 379 void OneClickSigninHelper::SavePassword(const std::string& password) {
351 // 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
352 // challenge, its possible for the user to never complete the signin. 381 // challenge, its possible for the user to never complete the signin.
353 // 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.
354 password_ = password; 383 password_ = password;
355 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | chrome/browser/ui/sync/one_click_signin_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698