Index: chrome/browser/ui/sync/one_click_signin_helper.cc |
=================================================================== |
--- chrome/browser/ui/sync/one_click_signin_helper.cc (revision 144800) |
+++ 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); |
@@ -145,6 +150,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); |
@@ -156,7 +163,7 @@ |
} |
bool OneClickLoginInfoBarDelegate::Cancel() { |
- DisableOneClickSignIn(); |
+ AddEmailToOneClickRejectedList(email_); |
RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
button_pressed_ = true; |
return true; |
@@ -189,6 +196,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); |
@@ -196,6 +213,7 @@ |
// static |
bool OneClickSigninHelper::CanOffer(content::WebContents* web_contents, |
+ const std::string& email, |
bool check_connected) { |
if (!web_contents) |
return false; |
@@ -225,6 +243,39 @@ |
if (!manager->GetAuthenticatedUsername().empty()) |
return false; |
+ |
+ // Make sure this username is not prohibited by policy. |
+ if (!manager->IsAllowedUsername(email)) |
+ return false; |
+ |
+ // If some profile, not just the current one, is already connected to this |
+ // account, don't show the infobar. |
+ if (g_browser_process) { |
+ ProfileManager* manager = g_browser_process->profile_manager(); |
+ if (manager) { |
+ string16 email16 = UTF8ToUTF16(email); |
+ ProfileInfoCache& cache = manager->GetProfileInfoCache(); |
+ |
+ for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
+ 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.
|
+ if (email16 == cache.GetUserNameOfProfileAtIndex(i)) |
+ 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; |
@@ -282,31 +333,9 @@ |
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 |
- // account, don't show the infobar. |
- if (g_browser_process) { |
- ProfileManager* manager = g_browser_process->profile_manager(); |
- if (manager) { |
- string16 email16 = UTF8ToUTF16(email); |
- ProfileInfoCache& cache = manager->GetProfileInfoCache(); |
- |
- for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
- if (email16 == cache.GetUserNameOfProfileAtIndex(i)) |
- return; |
- } |
- } |
- } |
- |
- // 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; |