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

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: Created 5 years, 8 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
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 "OnNetworkError", 163 "OnNetworkError",
163 "response_code", 164 "response_code",
164 response_code); 165 response_code);
165 LOG(ERROR) << "OnNetworkError " << response_code; 166 LOG(ERROR) << "OnNetworkError " << response_code;
166 service_->OnUserInfoFetchFailure(this); 167 service_->OnUserInfoFetchFailure(this);
167 } 168 }
168 169
169 AccountTrackerService::AccountInfo::AccountInfo() {} 170 AccountTrackerService::AccountInfo::AccountInfo() {}
170 AccountTrackerService::AccountInfo::~AccountInfo() {} 171 AccountTrackerService::AccountInfo::~AccountInfo() {}
171 172
172 bool AccountTrackerService::AccountInfo::IsValid() { 173 bool AccountTrackerService::AccountInfo::IsValid() const {
173 return !account_id.empty() && !email.empty() && !gaia.empty() && 174 return !account_id.empty() && !email.empty() && !gaia.empty() &&
174 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() && 175 !hosted_domain.empty() && !full_name.empty() && !given_name.empty() &&
175 !locale.empty(); 176 !locale.empty() && !picture_url.empty();
176 } 177 }
177 178
178 179
179 const char AccountTrackerService::kAccountInfoPref[] = "account_info"; 180 const char AccountTrackerService::kAccountInfoPref[] = "account_info";
180 181
181 AccountTrackerService::AccountTrackerService() 182 AccountTrackerService::AccountTrackerService()
182 : token_service_(NULL), 183 : token_service_(NULL),
183 signin_client_(NULL), 184 signin_client_(NULL),
184 shutdown_called_(false), 185 shutdown_called_(false),
185 network_fetches_enabled_(false) { 186 network_fetches_enabled_(false) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 std::string hosted_domain; 421 std::string hosted_domain;
421 if (user_info->GetString("hd", &hosted_domain) && !hosted_domain.empty()) { 422 if (user_info->GetString("hd", &hosted_domain) && !hosted_domain.empty()) {
422 state.info.hosted_domain = hosted_domain; 423 state.info.hosted_domain = hosted_domain;
423 } else { 424 } else {
424 state.info.hosted_domain = kNoHostedDomainFound; 425 state.info.hosted_domain = kNoHostedDomainFound;
425 } 426 }
426 427
427 user_info->GetString("name", &state.info.full_name); 428 user_info->GetString("name", &state.info.full_name);
428 user_info->GetString("given_name", &state.info.given_name); 429 user_info->GetString("given_name", &state.info.given_name);
429 user_info->GetString("locale", &state.info.locale); 430 user_info->GetString("locale", &state.info.locale);
431 user_info->GetString("picture", &state.info.picture_url);
430 432
431 NotifyAccountUpdated(state); 433 NotifyAccountUpdated(state);
432 SaveToPrefs(state); 434 SaveToPrefs(state);
433 } 435 }
434 } 436 }
435 437
436 void AccountTrackerService::OnUserInfoFetchSuccess( 438 void AccountTrackerService::OnUserInfoFetchSuccess(
437 AccountInfoFetcher* fetcher, 439 AccountInfoFetcher* fetcher,
438 const base::DictionaryValue* user_info) { 440 const base::DictionaryValue* user_info) {
439 const std::string& account_id = fetcher->account_id(); 441 const std::string& account_id = fetcher->account_id();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (dict->GetString(kAccountEmailPath, &value)) 479 if (dict->GetString(kAccountEmailPath, &value))
478 state.info.email = base::UTF16ToUTF8(value); 480 state.info.email = base::UTF16ToUTF8(value);
479 if (dict->GetString(kAccountHostedDomainPath, &value)) 481 if (dict->GetString(kAccountHostedDomainPath, &value))
480 state.info.hosted_domain = base::UTF16ToUTF8(value); 482 state.info.hosted_domain = base::UTF16ToUTF8(value);
481 if (dict->GetString(kAccountFullNamePath, &value)) 483 if (dict->GetString(kAccountFullNamePath, &value))
482 state.info.full_name = base::UTF16ToUTF8(value); 484 state.info.full_name = base::UTF16ToUTF8(value);
483 if (dict->GetString(kAccountGivenNamePath, &value)) 485 if (dict->GetString(kAccountGivenNamePath, &value))
484 state.info.given_name = base::UTF16ToUTF8(value); 486 state.info.given_name = base::UTF16ToUTF8(value);
485 if (dict->GetString(kAccountLocalePath, &value)) 487 if (dict->GetString(kAccountLocalePath, &value))
486 state.info.locale = base::UTF16ToUTF8(value); 488 state.info.locale = base::UTF16ToUTF8(value);
489 if (dict->GetString(kAccountPictureURLPath, &value))
Mike Lerman 2015/04/20 13:25:23 Roger: Does every account HAVE a picture? What if
Roger Tawa OOO till Jul 10th 2015/04/21 14:00:34 That's a good question, don't have the answer. If
anthonyvd 2015/04/29 15:15:08 Done.
490 state.info.picture_url = base::UTF16ToUTF8(value);
487 if (state.info.IsValid()) 491 if (state.info.IsValid())
488 NotifyAccountUpdated(state); 492 NotifyAccountUpdated(state);
489 } 493 }
490 } 494 }
491 } 495 }
492 } 496 }
493 497
494 void AccountTrackerService::SaveToPrefs(const AccountState& state) { 498 void AccountTrackerService::SaveToPrefs(const AccountState& state) {
495 if (!signin_client_->GetPrefs()) 499 if (!signin_client_->GetPrefs())
496 return; 500 return;
(...skipping 14 matching lines...) Expand all
511 update->Append(dict); // |update| takes ownership. 515 update->Append(dict); // |update| takes ownership.
512 dict->SetString(kAccountKeyPath, account_id_16); 516 dict->SetString(kAccountKeyPath, account_id_16);
513 } 517 }
514 518
515 dict->SetString(kAccountEmailPath, state.info.email); 519 dict->SetString(kAccountEmailPath, state.info.email);
516 dict->SetString(kAccountGaiaPath, state.info.gaia); 520 dict->SetString(kAccountGaiaPath, state.info.gaia);
517 dict->SetString(kAccountHostedDomainPath, state.info.hosted_domain); 521 dict->SetString(kAccountHostedDomainPath, state.info.hosted_domain);
518 dict->SetString(kAccountFullNamePath, state.info.full_name); 522 dict->SetString(kAccountFullNamePath, state.info.full_name);
519 dict->SetString(kAccountGivenNamePath, state.info.given_name); 523 dict->SetString(kAccountGivenNamePath, state.info.given_name);
520 dict->SetString(kAccountLocalePath, state.info.locale); 524 dict->SetString(kAccountLocalePath, state.info.locale);
525 dict->SetString(kAccountPictureURLPath, state.info.picture_url);
521 } 526 }
522 527
523 void AccountTrackerService::RemoveFromPrefs(const AccountState& state) { 528 void AccountTrackerService::RemoveFromPrefs(const AccountState& state) {
524 if (!signin_client_->GetPrefs()) 529 if (!signin_client_->GetPrefs())
525 return; 530 return;
526 531
527 base::string16 account_id_16 = base::UTF8ToUTF16(state.info.account_id); 532 base::string16 account_id_16 = base::UTF8ToUTF16(state.info.account_id);
528 ListPrefUpdate update(signin_client_->GetPrefs(), kAccountInfoPref); 533 ListPrefUpdate update(signin_client_->GetPrefs(), kAccountInfoPref);
529 for(size_t i = 0; i < update->GetSize(); ++i) { 534 for(size_t i = 0; i < update->GetSize(); ++i) {
530 base::DictionaryValue* dict = NULL; 535 base::DictionaryValue* dict = NULL;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 DCHECK(!email.empty()); 616 DCHECK(!email.empty());
612 const std::string account_id = PickAccountIdForAccount(gaia, email); 617 const std::string account_id = PickAccountIdForAccount(gaia, email);
613 const bool already_exists = ContainsKey(accounts_, account_id); 618 const bool already_exists = ContainsKey(accounts_, account_id);
614 StartTrackingAccount(account_id); 619 StartTrackingAccount(account_id);
615 AccountState& state = accounts_[account_id]; 620 AccountState& state = accounts_[account_id];
616 DCHECK(!already_exists || state.info.gaia == gaia); 621 DCHECK(!already_exists || state.info.gaia == gaia);
617 state.info.gaia = gaia; 622 state.info.gaia = gaia;
618 state.info.email = email; 623 state.info.email = email;
619 SaveToPrefs(state); 624 SaveToPrefs(state);
620 } 625 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698