summaryrefslogtreecommitdiffstats
path: root/chrome/browser/signin
diff options
context:
space:
mode:
authorcaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 02:02:57 +0000
committercaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 02:02:57 +0000
commit864791522f9833e0a70479a70549e0b5b56e9fa0 (patch)
treefd8c906c6b151ea548ee0ed372a0d9140213b385 /chrome/browser/signin
parent4ed2c4163d1316c171f750cdea6362080582366a (diff)
downloadchromium_src-864791522f9833e0a70479a70549e0b5b56e9fa0.zip
chromium_src-864791522f9833e0a70479a70549e0b5b56e9fa0.tar.gz
chromium_src-864791522f9833e0a70479a70549e0b5b56e9fa0.tar.bz2
This pref would be used in deciding whether or not to promote G+-related extension etc. to the user.
Unit tests to follow if this is the correct approach. Review URL: http://codereview.chromium.org/9316099 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/signin')
-rw-r--r--chrome/browser/signin/signin_manager.cc47
-rw-r--r--chrome/browser/signin/signin_manager.h8
-rw-r--r--chrome/browser/signin/signin_manager_factory.cc2
-rw-r--r--chrome/browser/signin/signin_manager_unittest.cc30
4 files changed, 67 insertions, 20 deletions
diff --git a/chrome/browser/signin/signin_manager.cc b/chrome/browser/signin/signin_manager.cc
index 47c0c85..5f6c987 100644
--- a/chrome/browser/signin/signin_manager.cc
+++ b/chrome/browser/signin/signin_manager.cc
@@ -4,7 +4,11 @@
#include "chrome/browser/signin/signin_manager.h"
+#include <string>
+#include <vector>
+
#include "base/command_line.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -18,6 +22,8 @@
#include "content/public/browser/notification_service.h"
const char kGetInfoEmailKey[] = "email";
+const char kGetInfoServicesKey[] = "allServices";
+const char kGooglePlusServiceKey[] = "googleme";
SigninManager::SigninManager()
: profile_(NULL),
@@ -188,6 +194,7 @@ void SigninManager::SignOut() {
authenticated_username_.clear();
profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
profile_->GetPrefs()->ClearPref(prefs::kSyncUsingOAuth);
+ profile_->GetPrefs()->ClearPref(prefs::kIsGooglePlusUser);
profile_->GetTokenService()->ResetCredentialsInMemory();
profile_->GetTokenService()->EraseTokensFromDB();
}
@@ -203,22 +210,40 @@ bool SigninManager::AuthInProgress() const {
void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) {
DCHECK(!browser_sync::IsUsingOAuth());
last_result_ = result;
- // Make a request for the canonical email address.
- client_login_->StartGetUserInfo(result.lsid, kGetInfoEmailKey);
+ // Make a request for the canonical email address and services.
+ client_login_->StartGetUserInfo(result.lsid);
}
// NOTE: GetUserInfo is a ClientLogin request similar to OAuth's userinfo
-void SigninManager::OnGetUserInfoSuccess(const std::string& key,
- const std::string& value) {
+void SigninManager::OnGetUserInfoSuccess(const UserInfoMap& data) {
DCHECK(!browser_sync::IsUsingOAuth());
- DCHECK(key == kGetInfoEmailKey);
- last_login_auth_error_ = GoogleServiceAuthError::None();
- SetAuthenticatedUsername(value);
- possibly_invalid_username_.clear();
- profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
- authenticated_username_);
- profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false);
+ UserInfoMap::const_iterator email_iter = data.find(kGetInfoEmailKey);
+ if (email_iter == data.end()) {
+ OnGetUserInfoKeyNotFound(kGetInfoEmailKey);
+ return;
+ } else {
+ DCHECK(email_iter->first == kGetInfoEmailKey);
+ last_login_auth_error_ = GoogleServiceAuthError::None();
+ SetAuthenticatedUsername(email_iter->second);
+ possibly_invalid_username_.clear();
+ profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
+ authenticated_username_);
+ profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false);
+ }
+ UserInfoMap::const_iterator service_iter = data.find(kGetInfoServicesKey);
+ if (service_iter == data.end()) {
+ DLOG(WARNING) << "Could not retrieve services for account with email: "
+ << authenticated_username_ <<".";
+ } else {
+ DCHECK(service_iter->first == kGetInfoServicesKey);
+ std::vector<std::string> services;
+ base::SplitStringUsingSubstr(service_iter->second, ", ", &services);
+ std::vector<std::string>::const_iterator iter =
+ std::find(services.begin(), services.end(), kGooglePlusServiceKey);
+ bool isGPlusUser = (iter != services.end());
+ profile_->GetPrefs()->SetBoolean(prefs::kIsGooglePlusUser, isGPlusUser);
+ }
GoogleServiceSigninSuccessDetails details(authenticated_username_,
password_);
content::NotificationService::current()->Notify(
diff --git a/chrome/browser/signin/signin_manager.h b/chrome/browser/signin/signin_manager.h
index 5f4e806..6224463 100644
--- a/chrome/browser/signin/signin_manager.h
+++ b/chrome/browser/signin/signin_manager.h
@@ -100,13 +100,15 @@ class SigninManager : public GaiaAuthConsumer,
// Returns true if there's a signin in progress.
bool AuthInProgress() const;
+ // Handles errors if a required user info key is not returned from the
+ // GetUserInfo call.
+ void OnGetUserInfoKeyNotFound(const std::string& key);
+
// GaiaAuthConsumer
virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE;
virtual void OnClientLoginFailure(
const GoogleServiceAuthError& error) OVERRIDE;
- virtual void OnGetUserInfoSuccess(const std::string& key,
- const std::string& value) OVERRIDE;
- virtual void OnGetUserInfoKeyNotFound(const std::string& key) OVERRIDE;
+ virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE;
virtual void OnGetUserInfoFailure(
const GoogleServiceAuthError& error) OVERRIDE;
virtual void OnTokenAuthFailure(const GoogleServiceAuthError& error) OVERRIDE;
diff --git a/chrome/browser/signin/signin_manager_factory.cc b/chrome/browser/signin/signin_manager_factory.cc
index 2a307fe..659eee4 100644
--- a/chrome/browser/signin/signin_manager_factory.cc
+++ b/chrome/browser/signin/signin_manager_factory.cc
@@ -39,6 +39,8 @@ void SigninManagerFactory::RegisterUserPrefs(PrefService* user_prefs) {
PrefService::UNSYNCABLE_PREF);
user_prefs->RegisterBooleanPref(prefs::kReverseAutologinEnabled, true,
PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterBooleanPref(prefs::kIsGooglePlusUser, false,
+ PrefService::UNSYNCABLE_PREF);
}
ProfileKeyedService* SigninManagerFactory::BuildServiceInstanceFor(
diff --git a/chrome/browser/signin/signin_manager_unittest.cc b/chrome/browser/signin/signin_manager_unittest.cc
index 68d3bfb..e5626dc 100644
--- a/chrome/browser/signin/signin_manager_unittest.cc
+++ b/chrome/browser/signin/signin_manager_unittest.cc
@@ -65,9 +65,12 @@ class SigninManagerTest : public TokenServiceTestHarness {
browser_sync::SetIsUsingOAuthForTest(originally_using_oauth_);
}
- void SimulateValidResponseClientLogin() {
+ void SimulateValidResponseClientLogin(bool isGPlusUser) {
DCHECK(!browser_sync::IsUsingOAuth());
// Simulate the correct ClientLogin response.
+ std::string respons_string = isGPlusUser ?
+ "email=user@gmail.com\nallServices=googleme" :
+ "email=user@gmail.com\nallServices=";
TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
DCHECK(fetcher);
DCHECK(fetcher->delegate());
@@ -86,7 +89,7 @@ class SigninManagerTest : public TokenServiceTestHarness {
fetcher->set_url(GURL(GaiaUrls::GetInstance()->get_user_info_url()));
fetcher->set_status(net::URLRequestStatus());
fetcher->set_response_code(200);
- fetcher->SetResponseString("email=user@gmail.com");
+ fetcher->SetResponseString(respons_string);
fetcher->delegate()->OnURLFetchComplete(fetcher);
}
@@ -136,8 +139,9 @@ TEST_F(SigninManagerTest, SignInClientLogin) {
manager_->StartSignIn("username", "password", "", "");
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
- SimulateValidResponseClientLogin();
+ SimulateValidResponseClientLogin(true);
EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
// Should go into token service and stop.
EXPECT_EQ(1U, google_login_success_.size());
@@ -149,6 +153,19 @@ TEST_F(SigninManagerTest, SignInClientLogin) {
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
}
+TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) {
+ browser_sync::SetIsUsingOAuthForTest(false);
+ manager_->Initialize(profile_.get());
+ EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+
+ manager_->StartSignIn("username", "password", "", "");
+ EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+
+ SimulateValidResponseClientLogin(false);
+ EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
+}
+
TEST_F(SigninManagerTest, ClearTransientSigninData) {
browser_sync::SetIsUsingOAuthForTest(false);
manager_->Initialize(profile_.get());
@@ -157,7 +174,7 @@ TEST_F(SigninManagerTest, ClearTransientSigninData) {
manager_->StartSignIn("username", "password", "", "");
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
- SimulateValidResponseClientLogin();
+ SimulateValidResponseClientLogin(false);
// Should go into token service and stop.
EXPECT_EQ(1U, google_login_success_.size());
@@ -206,12 +223,13 @@ TEST_F(SigninManagerTest, SignOutClientLogin) {
browser_sync::SetIsUsingOAuthForTest(false);
manager_->Initialize(profile_.get());
manager_->StartSignIn("username", "password", "", "");
- SimulateValidResponseClientLogin();
+ SimulateValidResponseClientLogin(false);
manager_->OnClientLoginSuccess(credentials_);
EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
manager_->SignOut();
EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
+ EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
// Should not be persisted anymore
manager_.reset(new SigninManager());
manager_->Initialize(profile_.get());
@@ -267,7 +285,7 @@ TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
EXPECT_FALSE(manager_->possibly_invalid_username_.empty());
manager_->ProvideSecondFactorAccessCode("access");
- SimulateValidResponseClientLogin();
+ SimulateValidResponseClientLogin(false);
EXPECT_EQ(1U, google_login_success_.size());
EXPECT_EQ(1U, google_login_failure_.size());