summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/signin/core/browser/account_tracker_service.cc92
-rw-r--r--components/signin/core/browser/account_tracker_service.h10
-rw-r--r--components/signin/core/browser/account_tracker_service_unittest.cc9
3 files changed, 102 insertions, 9 deletions
diff --git a/components/signin/core/browser/account_tracker_service.cc b/components/signin/core/browser/account_tracker_service.cc
index ec24462..d29adf1 100644
--- a/components/signin/core/browser/account_tracker_service.cc
+++ b/components/signin/core/browser/account_tracker_service.cc
@@ -10,6 +10,7 @@
#include "base/metrics/field_trial.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/profiler/scoped_tracker.h"
+#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "components/signin/core/browser/refresh_token_annotation_request.h"
@@ -17,6 +18,8 @@
#include "components/signin/core/browser/signin_manager.h"
#include "components/signin/core/common/signin_pref_names.h"
#include "components/signin/core/common/signin_switches.h"
+#include "google_apis/gaia/gaia_auth_consumer.h"
+#include "google_apis/gaia/gaia_auth_fetcher.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_oauth_client.h"
@@ -31,6 +34,7 @@ const char kAccountHostedDomainPath[] = "hd";
const char kAccountFullNamePath[] = "full_name";
const char kAccountGivenNamePath[] = "given_name";
const char kAccountLocalePath[] = "locale";
+const char kAccountServiceFlagsPath[] = "service_flags";
const base::TimeDelta kRefreshFromTokenServiceDelay =
base::TimeDelta::FromHours(24);
@@ -50,7 +54,8 @@ bool IsRefreshTokenDeviceIdExperimentEnabled() {
const char AccountTrackerService::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN";
class AccountInfoFetcher : public OAuth2TokenService::Consumer,
- public gaia::GaiaOAuthClient::Delegate {
+ public gaia::GaiaOAuthClient::Delegate,
+ public GaiaAuthConsumer {
public:
AccountInfoFetcher(OAuth2TokenService* token_service,
net::URLRequestContextGetter* request_context_getter,
@@ -61,6 +66,7 @@ class AccountInfoFetcher : public OAuth2TokenService::Consumer,
const std::string& account_id() { return account_id_; }
void Start();
+ void SendSuccessIfDoneFetching();
// OAuth2TokenService::Consumer implementation.
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
@@ -75,6 +81,12 @@ class AccountInfoFetcher : public OAuth2TokenService::Consumer,
void OnOAuthError() override;
void OnNetworkError(int response_code) override;
+ // Overridden from GaiaAuthConsumer:
+ void OnClientLoginSuccess(const ClientLoginResult& result) override;
+ void OnClientLoginFailure(const GoogleServiceAuthError& error) override;
+ void OnGetUserInfoSuccess(const UserInfoMap& data) override;
+ void OnGetUserInfoFailure(const GoogleServiceAuthError& error) override;
+
private:
OAuth2TokenService* token_service_;
net::URLRequestContextGetter* request_context_getter_;
@@ -83,6 +95,10 @@ class AccountInfoFetcher : public OAuth2TokenService::Consumer,
scoped_ptr<OAuth2TokenService::Request> login_token_request_;
scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_;
+ scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_;
+
+ scoped_ptr<base::DictionaryValue> fetched_user_info_;
+ scoped_ptr<std::vector<std::string> > fetched_service_flags_;
};
AccountInfoFetcher::AccountInfoFetcher(
@@ -108,10 +124,18 @@ void AccountInfoFetcher::Start() {
OAuth2TokenService::ScopeSet scopes;
scopes.insert(GaiaConstants::kGoogleUserInfoEmail);
scopes.insert(GaiaConstants::kGoogleUserInfoProfile);
+ scopes.insert(GaiaConstants::kOAuth1LoginScope);
login_token_request_ = token_service_->StartRequest(
account_id_, scopes, this);
}
+void AccountInfoFetcher::SendSuccessIfDoneFetching() {
+ if (fetched_user_info_ && fetched_service_flags_) {
+ service_->OnUserInfoFetchSuccess(
+ this, fetched_user_info_.get(), fetched_service_flags_.get());
+ }
+}
+
void AccountInfoFetcher::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
@@ -121,9 +145,14 @@ void AccountInfoFetcher::OnGetTokenSuccess(
DCHECK_EQ(request, login_token_request_.get());
gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(request_context_getter_));
-
const int kMaxRetries = 3;
gaia_oauth_client_->GetUserInfo(access_token, kMaxRetries, this);
+
+ gaia_auth_fetcher_.reset(
+ new GaiaAuthFetcher(
+ this, GaiaConstants::kChromeSource, request_context_getter_));
+ gaia_auth_fetcher_->StartOAuthLogin(
+ access_token, GaiaConstants::kGaiaService);
}
void AccountInfoFetcher::OnGetTokenFailure(
@@ -148,7 +177,36 @@ void AccountInfoFetcher::OnGetUserInfoResponse(
"OnGetUserInfoResponse",
"account_id",
account_id_);
- service_->OnUserInfoFetchSuccess(this, user_info.get());
+ fetched_user_info_ = user_info.Pass();
+ SendSuccessIfDoneFetching();
+}
+
+void AccountInfoFetcher::OnClientLoginSuccess(
+ const ClientLoginResult& result) {
+ gaia_auth_fetcher_->StartGetUserInfo(result.lsid);
+}
+
+void AccountInfoFetcher::OnClientLoginFailure(
+ const GoogleServiceAuthError& error) {
+ service_->OnUserInfoFetchFailure(this);
+}
+
+void AccountInfoFetcher::OnGetUserInfoSuccess(const UserInfoMap& data) {
+ fetched_service_flags_.reset(new std::vector<std::string>);
+ UserInfoMap::const_iterator services_iter = data.find("allServices");
+ if (services_iter != data.end()) {
+ base::SplitString(services_iter->second, ',', fetched_service_flags_.get());
+ SendSuccessIfDoneFetching();
+ } else {
+ DLOG(WARNING) << "AccountInfoFetcher::OnGetUserInfoSuccess: "
+ << "GetUserInfo response didn't include allServices field.";
+ service_->OnUserInfoFetchFailure(this);
+ }
+}
+
+void AccountInfoFetcher::OnGetUserInfoFailure(
+ const GoogleServiceAuthError& error) {
+ service_->OnUserInfoFetchFailure(this);
}
void AccountInfoFetcher::OnOAuthError() {
@@ -440,7 +498,8 @@ void AccountTrackerService::StartFetchingUserInfo(
void AccountTrackerService::SetAccountStateFromUserInfo(
const std::string& account_id,
- const base::DictionaryValue* user_info) {
+ const base::DictionaryValue* user_info,
+ const std::vector<std::string>* service_flags) {
AccountState& state = accounts_[account_id];
std::string gaia_id;
@@ -461,6 +520,8 @@ void AccountTrackerService::SetAccountStateFromUserInfo(
user_info->GetString("given_name", &state.info.given_name);
user_info->GetString("locale", &state.info.locale);
+ state.info.service_flags = *service_flags;
+
NotifyAccountUpdated(state);
SaveToPrefs(state);
}
@@ -468,11 +529,12 @@ void AccountTrackerService::SetAccountStateFromUserInfo(
void AccountTrackerService::OnUserInfoFetchSuccess(
AccountInfoFetcher* fetcher,
- const base::DictionaryValue* user_info) {
+ const base::DictionaryValue* user_info,
+ const std::vector<std::string>* service_flags) {
const std::string& account_id = fetcher->account_id();
DCHECK(ContainsKey(accounts_, account_id));
- SetAccountStateFromUserInfo(account_id, user_info);
+ SetAccountStateFromUserInfo(account_id, user_info, service_flags);
DeleteFetcher(fetcher);
}
@@ -516,6 +578,18 @@ void AccountTrackerService::LoadFromPrefs() {
state.info.given_name = base::UTF16ToUTF8(value);
if (dict->GetString(kAccountLocalePath, &value))
state.info.locale = base::UTF16ToUTF8(value);
+
+ const base::ListValue* service_flags_list;
+ if (dict->GetList(kAccountServiceFlagsPath, &service_flags_list)) {
+ std::string flag;
+ for(base::Value* flag: *service_flags_list) {
+ std::string flag_string;
+ if(flag->GetAsString(&flag_string)) {
+ state.info.service_flags.push_back(flag_string);
+ }
+ }
+ }
+
if (state.info.IsValid())
NotifyAccountUpdated(state);
}
@@ -552,6 +626,12 @@ void AccountTrackerService::SaveToPrefs(const AccountState& state) {
dict->SetString(kAccountFullNamePath, state.info.full_name);
dict->SetString(kAccountGivenNamePath, state.info.given_name);
dict->SetString(kAccountLocalePath, state.info.locale);
+
+ scoped_ptr<base::ListValue> service_flags_list;
+ service_flags_list.reset(new base::ListValue);
+ service_flags_list->AppendStrings(state.info.service_flags);
+
+ dict->Set(kAccountServiceFlagsPath, service_flags_list.Pass());
}
void AccountTrackerService::RemoveFromPrefs(const AccountState& state) {
diff --git a/components/signin/core/browser/account_tracker_service.h b/components/signin/core/browser/account_tracker_service.h
index 2040e70..4debf41 100644
--- a/components/signin/core/browser/account_tracker_service.h
+++ b/components/signin/core/browser/account_tracker_service.h
@@ -58,6 +58,7 @@ class AccountTrackerService : public KeyedService,
std::string given_name;
std::string hosted_domain;
std::string locale;
+ std::vector<std::string> service_flags;
// TODO(rogerta): eventually this structure will include other information
// about the account, like full name, profile picture URL, etc.
@@ -130,15 +131,18 @@ class AccountTrackerService : public KeyedService,
protected:
// Available to be called in tests.
- void SetAccountStateFromUserInfo(const std::string& account_id,
- const base::DictionaryValue* user_info);
+ void SetAccountStateFromUserInfo(
+ const std::string& account_id,
+ const base::DictionaryValue* user_info,
+ const std::vector<std::string>* service_flags);
private:
friend class AccountInfoFetcher;
// These methods are called by fetchers.
void OnUserInfoFetchSuccess(AccountInfoFetcher* fetcher,
- const base::DictionaryValue* user_info);
+ const base::DictionaryValue* user_info,
+ const std::vector<std::string>* service_flags);
void OnUserInfoFetchFailure(AccountInfoFetcher* fetcher);
// Refreshes the AccountInfo associated with |account_id| if it's invalid or
diff --git a/components/signin/core/browser/account_tracker_service_unittest.cc b/components/signin/core/browser/account_tracker_service_unittest.cc
index 3ea1ab4..fe4a929 100644
--- a/components/signin/core/browser/account_tracker_service_unittest.cc
+++ b/components/signin/core/browser/account_tracker_service_unittest.cc
@@ -39,6 +39,10 @@ const std::string kTokenInfoIncompleteResponseFormat =
\"hd\": \"\", \
}";
+const std::string kLSIDResponse = "{ lsid: \"Foo\" }";
+
+const std::string kServiceFlags = "allServices=Service1,Service2";
+
enum TrackingEventType {
UPDATED,
REMOVED,
@@ -74,6 +78,9 @@ void CheckAccountDetails(const std::string account_id,
EXPECT_EQ(AccountIdToFullName(account_id), info.full_name);
EXPECT_EQ(AccountIdToGivenName(account_id), info.given_name);
EXPECT_EQ(AccountIdToLocale(account_id), info.locale);
+ EXPECT_EQ(2U, info.service_flags.size());
+ EXPECT_EQ("Service1", info.service_flags[0]);
+ EXPECT_EQ("Service2", info.service_flags[1]);
}
class TrackingEvent {
@@ -340,6 +347,8 @@ void AccountTrackerServiceTest::ReturnOAuthUrlFetchSuccess(
ReturnOAuthUrlFetchResults(gaia::GaiaOAuthClient::kUrlFetcherId,
net::HTTP_OK,
GenerateValidTokenInfoResponse(account_id));
+ ReturnOAuthUrlFetchResults(0, net::HTTP_OK, kLSIDResponse);
+ ReturnOAuthUrlFetchResults(0, net::HTTP_OK, kServiceFlags);
}
void AccountTrackerServiceTest::ReturnOAuthUrlFetchSuccessIncomplete(