Index: chrome/browser/ui/sync/one_click_signin_helper.cc |
=================================================================== |
--- chrome/browser/ui/sync/one_click_signin_helper.cc (revision 144169) |
+++ chrome/browser/ui/sync/one_click_signin_helper.cc (working copy) |
@@ -12,6 +12,7 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/infobars/infobar_tab_helper.h" |
#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/prefs/scoped_user_pref_update.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/profiles/profile_manager.h" |
@@ -71,6 +72,10 @@ |
// show again in this profile. |
void DisableOneClickSignIn(); |
+ // Add a specific email to the list of emails rejected for one-click |
+ // sign-in, for this profile. |
+ void AddEmailToOneClickRejectedList(const std::string& email); |
+ |
// Record the specified action in the histogram for one-click sign in. |
void RecordHistogramAction(int action); |
@@ -146,6 +151,8 @@ |
} // namespace |
bool OneClickLoginInfoBarDelegate::Accept() { |
+ // User has accepted one-click sign-in for this account. Never ask again for |
+ // this profile. |
DisableOneClickSignIn(); |
content::WebContents* web_contents = owner()->web_contents(); |
RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
@@ -157,7 +164,7 @@ |
} |
bool OneClickLoginInfoBarDelegate::Cancel() { |
- DisableOneClickSignIn(); |
+ AddEmailToOneClickRejectedList(email_); |
RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
button_pressed_ = true; |
return true; |
@@ -190,6 +197,16 @@ |
pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); |
} |
+void OneClickLoginInfoBarDelegate::AddEmailToOneClickRejectedList( |
+ const std::string& email) { |
+ PrefService* pref_service = |
+ TabContents::FromWebContents(owner()->web_contents())-> |
+ profile()->GetPrefs(); |
+ ListPrefUpdate updater(pref_service, |
+ prefs::kReverseAutologinRejectedEmailList); |
+ updater->AppendIfNotPresent(base::Value::CreateStringValue(email)); |
+} |
+ |
void OneClickLoginInfoBarDelegate::RecordHistogramAction(int action) { |
UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
one_click_signin::HISTOGRAM_MAX); |
@@ -197,6 +214,7 @@ |
// static |
bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
+ const std::string& email, |
bool check_connected) { |
if (!web_contents) |
return false; |
@@ -226,6 +244,23 @@ |
if (!manager->GetAuthenticatedUsername().empty()) |
return false; |
+ |
+ // Make sure this username is not prohibited by policy. |
+ if (!manager->IsAllowedUsername(email)) |
+ return false; |
+ |
+ // If email was already rejected by this profile for one-click sign-in. |
+ if (!email.empty()) { |
+ const ListValue* rejected_emails = profile->GetPrefs()->GetList( |
+ prefs::kReverseAutologinRejectedEmailList); |
+ if (!rejected_emails->empty()) { |
+ const Value* email_value = Value::CreateStringValue(email); |
+ ListValue::const_iterator iter = rejected_emails->Find( |
+ *email_value); |
+ if (iter != rejected_emails->end()) |
+ return false; |
+ } |
+ } |
} |
return true; |
@@ -283,7 +318,7 @@ |
content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
route_id); |
- if (!web_contents || !CanOffer(web_contents, true)) |
+ if (!web_contents || !CanOffer(web_contents, email, true)) |
return; |
// If some profile, not just the current one, is already connected to this |
@@ -301,13 +336,6 @@ |
} |
} |
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.
|
- // Make sure this username is not prohibited by policy. |
- Profile* profile = |
- Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
- SigninManager* signin = SigninManagerFactory::GetForProfile(profile); |
- if (!signin->IsAllowedUsername(email)) |
- return; |
- |
TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
if (!tab_contents) |
return; |