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

Side by Side Diff: components/signin/core/browser/account_tracker_service.cc

Issue 1091363002: Change ProfileDownloader to use AccountTrackerService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up unit test. Created 5 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/signin/core/browser/account_tracker_service.h" 5 #include "components/signin/core/browser/account_tracker_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace { 25 namespace {
26 26
27 const char kAccountKeyPath[] = "account_id"; 27 const char kAccountKeyPath[] = "account_id";
28 const char kAccountEmailPath[] = "email"; 28 const char kAccountEmailPath[] = "email";
29 const char kAccountGaiaPath[] = "gaia"; 29 const char kAccountGaiaPath[] = "gaia";
30 const char kAccountHostedDomainPath[] = "hd"; 30 const char kAccountHostedDomainPath[] = "hd";
31 const char kAccountFullNamePath[] = "full_name"; 31 const char kAccountFullNamePath[] = "full_name";
32 const char kAccountGivenNamePath[] = "given_name"; 32 const char kAccountGivenNamePath[] = "given_name";
33 const char kAccountLocalePath[] = "locale"; 33 const char kAccountLocalePath[] = "locale";
34 const char kAccountPictureURLPath[] = "picture_url";
34 35
35 #if !defined(OS_ANDROID) && !defined(OS_IOS) 36 #if !defined(OS_ANDROID) && !defined(OS_IOS)
36 // IsRefreshTokenDeviceIdExperimentEnabled is called from 37 // IsRefreshTokenDeviceIdExperimentEnabled is called from
37 // SendRefreshTokenAnnotationRequest only on desktop platforms. 38 // SendRefreshTokenAnnotationRequest only on desktop platforms.
38 bool IsRefreshTokenDeviceIdExperimentEnabled() { 39 bool IsRefreshTokenDeviceIdExperimentEnabled() {
39 const std::string group_name = 40 const std::string group_name =
40 base::FieldTrialList::FindFullName("RefreshTokenDeviceId"); 41 base::FieldTrialList::FindFullName("RefreshTokenDeviceId");
41 return group_name == "Enabled"; 42 return group_name == "Enabled";
42 } 43 }
43 #endif 44 #endif
44 } 45 }
45 46
46 // This must be a string which can never be a valid domain. 47 // This must be a string which can never be a valid domain.
47 const char AccountTrackerService::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN"; 48 const char AccountTrackerService::kNoHostedDomainFound[] = "NO_HOSTED_DOMAIN";
48 49
50 // This must be a string which can never be a valid picture URL.
51 const char AccountTrackerService::kNoPictureURLFound[] = "NO_PICTURE_URL";
52
49 class AccountInfoFetcher : public OAuth2TokenService::Consumer, 53 class AccountInfoFetcher : public OAuth2TokenService::Consumer,
50 public gaia::GaiaOAuthClient::Delegate { 54 public gaia::GaiaOAuthClient::Delegate {
51 public: 55 public:
52 AccountInfoFetcher(OAuth2TokenService* token_service, 56 AccountInfoFetcher(OAuth2TokenService* token_service,
53 net::URLRequestContextGetter* request_context_getter, 57 net::URLRequestContextGetter* request_context_getter,
54 AccountTrackerService* service, 58 AccountTrackerService* service,
55 const std::string& account_id); 59 const std::string& account_id);
56 ~AccountInfoFetcher() override; 60 ~AccountInfoFetcher() override;
57 61
58 const std::string& account_id() { return account_id_; } 62 const std::string& account_id() { return account_id_; }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 "OnNetworkError", 166 "OnNetworkError",
163 "response_code", 167 "response_code",
164 response_code); 168 response_code);
165 LOG(ERROR) << "OnNetworkError " << response_code; 169 LOG(ERROR) << "OnNetworkError " << response_code;
166 service_->OnUserInfoFetchFailure(this); 170 service_->OnUserInfoFetchFailure(this);
167 } 171 }
168 172
169 AccountTrackerService::AccountInfo::AccountInfo() {} 173 AccountTrackerService::AccountInfo::AccountInfo() {}
170 AccountTrackerService::AccountInfo::~AccountInfo() {} 174 AccountTrackerService::AccountInfo::~AccountInfo() {}
171 175
172 bool AccountTrackerService::AccountInfo::IsValid() { 176 bool AccountTrackerService::AccountInfo::IsValid() const {
173 return !account_id.empty() && !email.empty() && !gaia.empty() && 177 return !account_id.empty() && !email.empty() && !gaia.empty() &&
174 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() && 178 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() &&
175 !locale.empty(); 179 !locale.empty() && !picture_url.empty();
176 } 180 }
177 181
178 182
179 const char AccountTrackerService::kAccountInfoPref[] = "account_info"; 183 const char AccountTrackerService::kAccountInfoPref[] = "account_info";
180 184
181 AccountTrackerService::AccountTrackerService() 185 AccountTrackerService::AccountTrackerService()
182 : token_service_(NULL), 186 : token_service_(NULL),
183 signin_client_(NULL), 187 signin_client_(NULL),
184 shutdown_called_(false), 188 shutdown_called_(false),
185 network_fetches_enabled_(false) { 189 network_fetches_enabled_(false) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (user_info->GetString("hd", &hosted_domain) && !hosted_domain.empty()) { 429 if (user_info->GetString("hd", &hosted_domain) && !hosted_domain.empty()) {
426 state.info.hosted_domain = hosted_domain; 430 state.info.hosted_domain = hosted_domain;
427 } else { 431 } else {
428 state.info.hosted_domain = kNoHostedDomainFound; 432 state.info.hosted_domain = kNoHostedDomainFound;
429 } 433 }
430 434
431 user_info->GetString("name", &state.info.full_name); 435 user_info->GetString("name", &state.info.full_name);
432 user_info->GetString("given_name", &state.info.given_name); 436 user_info->GetString("given_name", &state.info.given_name);
433 user_info->GetString("locale", &state.info.locale); 437 user_info->GetString("locale", &state.info.locale);
434 438
439 std::string picture_url;
440 if(user_info->GetString("picture", &picture_url)) {
441 state.info.picture_url = picture_url;
442 } else {
443 state.info.picture_url = kNoPictureURLFound;
444 }
445
435 NotifyAccountUpdated(state); 446 NotifyAccountUpdated(state);
436 SaveToPrefs(state); 447 SaveToPrefs(state);
437 } 448 }
438 } 449 }
439 450
440 void AccountTrackerService::OnUserInfoFetchSuccess( 451 void AccountTrackerService::OnUserInfoFetchSuccess(
441 AccountInfoFetcher* fetcher, 452 AccountInfoFetcher* fetcher,
442 const base::DictionaryValue* user_info) { 453 const base::DictionaryValue* user_info) {
443 const std::string& account_id = fetcher->account_id(); 454 const std::string& account_id = fetcher->account_id();
444 DCHECK(ContainsKey(accounts_, account_id)); 455 DCHECK(ContainsKey(accounts_, account_id));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (dict->GetString(kAccountEmailPath, &value)) 492 if (dict->GetString(kAccountEmailPath, &value))
482 state.info.email = base::UTF16ToUTF8(value); 493 state.info.email = base::UTF16ToUTF8(value);
483 if (dict->GetString(kAccountHostedDomainPath, &value)) 494 if (dict->GetString(kAccountHostedDomainPath, &value))
484 state.info.hosted_domain = base::UTF16ToUTF8(value); 495 state.info.hosted_domain = base::UTF16ToUTF8(value);
485 if (dict->GetString(kAccountFullNamePath, &value)) 496 if (dict->GetString(kAccountFullNamePath, &value))
486 state.info.full_name = base::UTF16ToUTF8(value); 497 state.info.full_name = base::UTF16ToUTF8(value);
487 if (dict->GetString(kAccountGivenNamePath, &value)) 498 if (dict->GetString(kAccountGivenNamePath, &value))
488 state.info.given_name = base::UTF16ToUTF8(value); 499 state.info.given_name = base::UTF16ToUTF8(value);
489 if (dict->GetString(kAccountLocalePath, &value)) 500 if (dict->GetString(kAccountLocalePath, &value))
490 state.info.locale = base::UTF16ToUTF8(value); 501 state.info.locale = base::UTF16ToUTF8(value);
502 if (dict->GetString(kAccountPictureURLPath, &value))
503 state.info.picture_url = base::UTF16ToUTF8(value);
491 if (state.info.IsValid()) 504 if (state.info.IsValid())
492 NotifyAccountUpdated(state); 505 NotifyAccountUpdated(state);
493 } 506 }
494 } 507 }
495 } 508 }
496 } 509 }
497 510
498 void AccountTrackerService::SaveToPrefs(const AccountState& state) { 511 void AccountTrackerService::SaveToPrefs(const AccountState& state) {
499 if (!signin_client_->GetPrefs()) 512 if (!signin_client_->GetPrefs())
500 return; 513 return;
(...skipping 14 matching lines...) Expand all
515 update->Append(dict); // |update| takes ownership. 528 update->Append(dict); // |update| takes ownership.
516 dict->SetString(kAccountKeyPath, account_id_16); 529 dict->SetString(kAccountKeyPath, account_id_16);
517 } 530 }
518 531
519 dict->SetString(kAccountEmailPath, state.info.email); 532 dict->SetString(kAccountEmailPath, state.info.email);
520 dict->SetString(kAccountGaiaPath, state.info.gaia); 533 dict->SetString(kAccountGaiaPath, state.info.gaia);
521 dict->SetString(kAccountHostedDomainPath, state.info.hosted_domain); 534 dict->SetString(kAccountHostedDomainPath, state.info.hosted_domain);
522 dict->SetString(kAccountFullNamePath, state.info.full_name); 535 dict->SetString(kAccountFullNamePath, state.info.full_name);
523 dict->SetString(kAccountGivenNamePath, state.info.given_name); 536 dict->SetString(kAccountGivenNamePath, state.info.given_name);
524 dict->SetString(kAccountLocalePath, state.info.locale); 537 dict->SetString(kAccountLocalePath, state.info.locale);
538 dict->SetString(kAccountPictureURLPath, state.info.picture_url);
525 } 539 }
526 540
527 void AccountTrackerService::RemoveFromPrefs(const AccountState& state) { 541 void AccountTrackerService::RemoveFromPrefs(const AccountState& state) {
528 if (!signin_client_->GetPrefs()) 542 if (!signin_client_->GetPrefs())
529 return; 543 return;
530 544
531 base::string16 account_id_16 = base::UTF8ToUTF16(state.info.account_id); 545 base::string16 account_id_16 = base::UTF8ToUTF16(state.info.account_id);
532 ListPrefUpdate update(signin_client_->GetPrefs(), kAccountInfoPref); 546 ListPrefUpdate update(signin_client_->GetPrefs(), kAccountInfoPref);
533 for(size_t i = 0; i < update->GetSize(); ++i) { 547 for(size_t i = 0; i < update->GetSize(); ++i) {
534 base::DictionaryValue* dict = NULL; 548 base::DictionaryValue* dict = NULL;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 state.info.email = email; 631 state.info.email = email;
618 SaveToPrefs(state); 632 SaveToPrefs(state);
619 633
620 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" 634 DVLOG(1) << "AccountTrackerService::SeedAccountInfo"
621 << " account_id=" << account_id 635 << " account_id=" << account_id
622 << " gaia_id=" << gaia 636 << " gaia_id=" << gaia
623 << " email=" << email; 637 << " email=" << email;
624 638
625 return account_id; 639 return account_id;
626 } 640 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698