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

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

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/about_signin_internals.h" 5 #include "components/signin/core/browser/about_signin_internals.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 #include <utility> 10 #include <utility>
(...skipping 24 matching lines...) Expand all
35 using namespace signin_internals_util; 35 using namespace signin_internals_util;
36 36
37 namespace { 37 namespace {
38 38
39 std::string GetTimeStr(base::Time time) { 39 std::string GetTimeStr(base::Time time) {
40 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time)); 40 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time));
41 } 41 }
42 42
43 base::ListValue* AddSection(base::ListValue* parent_list, 43 base::ListValue* AddSection(base::ListValue* parent_list,
44 const std::string& title) { 44 const std::string& title) {
45 std::unique_ptr<base::DictionaryValue> section(new base::DictionaryValue()); 45 auto section = base::MakeUnique<base::DictionaryValue>();
46 base::ListValue* section_contents = new base::ListValue();
47 46
48 section->SetString("title", title); 47 section->SetString("title", title);
49 section->Set("data", section_contents); 48 base::ListValue* section_contents =
49 section->SetList("data", base::MakeUnique<base::ListValue>());
50 parent_list->Append(std::move(section)); 50 parent_list->Append(std::move(section));
51 return section_contents; 51 return section_contents;
52 } 52 }
53 53
54 void AddSectionEntry(base::ListValue* section_list, 54 void AddSectionEntry(base::ListValue* section_list,
55 const std::string& field_name, 55 const std::string& field_name,
56 const std::string& field_status, 56 const std::string& field_status,
57 const std::string& field_time = "") { 57 const std::string& field_time = "") {
58 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); 58 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue());
59 entry->SetString("label", field_name); 59 entry->SetString("label", field_name);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 NotifyObservers(); 403 NotifyObservers();
404 } 404 }
405 405
406 void AboutSigninInternals::OnGaiaAccountsInCookieUpdated( 406 void AboutSigninInternals::OnGaiaAccountsInCookieUpdated(
407 const std::vector<gaia::ListedAccount>& gaia_accounts, 407 const std::vector<gaia::ListedAccount>& gaia_accounts,
408 const std::vector<gaia::ListedAccount>& signed_out_account, 408 const std::vector<gaia::ListedAccount>& signed_out_account,
409 const GoogleServiceAuthError& error) { 409 const GoogleServiceAuthError& error) {
410 if (error.state() != GoogleServiceAuthError::NONE) 410 if (error.state() != GoogleServiceAuthError::NONE)
411 return; 411 return;
412 412
413 base::DictionaryValue cookie_status; 413 auto cookie_info = base::MakeUnique<base::ListValue>();
414 base::ListValue* cookie_info = new base::ListValue();
415 cookie_status.Set("cookie_info", cookie_info);
416 414
417 for (size_t i = 0; i < gaia_accounts.size(); ++i) { 415 for (size_t i = 0; i < gaia_accounts.size(); ++i) {
418 AddCookieEntry(cookie_info, 416 AddCookieEntry(cookie_info.get(), gaia_accounts[i].raw_email,
419 gaia_accounts[i].raw_email,
420 gaia_accounts[i].gaia_id, 417 gaia_accounts[i].gaia_id,
421 gaia_accounts[i].valid ? "Valid" : "Invalid"); 418 gaia_accounts[i].valid ? "Valid" : "Invalid");
422 } 419 }
423 420
424 if (gaia_accounts.size() == 0) { 421 if (gaia_accounts.size() == 0) {
425 AddCookieEntry(cookie_info, 422 AddCookieEntry(cookie_info.get(), "No Accounts Present.", std::string(),
426 "No Accounts Present.",
427 std::string(),
428 std::string()); 423 std::string());
429 } 424 }
430 425
426 base::DictionaryValue cookie_status;
427 cookie_status.Set("cookie_info", std::move(cookie_info));
431 // Update the observers that the cookie's accounts are updated. 428 // Update the observers that the cookie's accounts are updated.
432 for (auto& observer : signin_observers_) 429 for (auto& observer : signin_observers_)
433 observer.OnCookieAccountsFetched(&cookie_status); 430 observer.OnCookieAccountsFetched(&cookie_status);
434 } 431 }
435 432
436 AboutSigninInternals::TokenInfo::TokenInfo( 433 AboutSigninInternals::TokenInfo::TokenInfo(
437 const std::string& consumer_id, 434 const std::string& consumer_id,
438 const OAuth2TokenService::ScopeSet& scopes) 435 const OAuth2TokenService::ScopeSet& scopes)
439 : consumer_id(consumer_id), 436 : consumer_id(consumer_id),
440 scopes(scopes), 437 scopes(scopes),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 SigninErrorController* signin_error_controller, 519 SigninErrorController* signin_error_controller,
523 ProfileOAuth2TokenService* token_service, 520 ProfileOAuth2TokenService* token_service,
524 GaiaCookieManagerService* cookie_manager_service_, 521 GaiaCookieManagerService* cookie_manager_service_,
525 const std::string& product_version) { 522 const std::string& product_version) {
526 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 523 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
527 // fixed. 524 // fixed.
528 tracked_objects::ScopedTracker tracking_profile1( 525 tracked_objects::ScopedTracker tracking_profile1(
529 FROM_HERE_WITH_EXPLICIT_FUNCTION( 526 FROM_HERE_WITH_EXPLICIT_FUNCTION(
530 "422460 AboutSigninInternals::SigninStatus::ToValue1")); 527 "422460 AboutSigninInternals::SigninStatus::ToValue1"));
531 528
532 std::unique_ptr<base::DictionaryValue> signin_status( 529 auto signin_status = base::MakeUnique<base::DictionaryValue>();
533 new base::DictionaryValue()); 530 auto signin_info = base::MakeUnique<base::ListValue>();
534 base::ListValue* signin_info = new base::ListValue();
535 signin_status->Set("signin_info", signin_info);
536 531
537 // A summary of signin related info first. 532 // A summary of signin related info first.
538 base::ListValue* basic_info = AddSection(signin_info, "Basic Information"); 533 base::ListValue* basic_info =
534 AddSection(signin_info.get(), "Basic Information");
539 AddSectionEntry(basic_info, "Chrome Version", product_version); 535 AddSectionEntry(basic_info, "Chrome Version", product_version);
540 AddSectionEntry(basic_info, "Account Consistency?", 536 AddSectionEntry(basic_info, "Account Consistency?",
541 switches::IsEnableAccountConsistency() == true ? "On" : "Off"); 537 switches::IsEnableAccountConsistency() == true ? "On" : "Off");
542 AddSectionEntry(basic_info, "Signin Status", 538 AddSectionEntry(basic_info, "Signin Status",
543 signin_manager->IsAuthenticated() ? "Signed In" : "Not Signed In"); 539 signin_manager->IsAuthenticated() ? "Signed In" : "Not Signed In");
544 OAuth2TokenServiceDelegate::LoadCredentialsState load_tokens_state = 540 OAuth2TokenServiceDelegate::LoadCredentialsState load_tokens_state =
545 token_service->GetDelegate()->GetLoadCredentialsState(); 541 token_service->GetDelegate()->GetLoadCredentialsState();
546 AddSectionEntry(basic_info, "TokenService Status", 542 AddSectionEntry(basic_info, "TokenService Status",
547 TokenServiceLoadCredentialsStateToLabel(load_tokens_state)); 543 TokenServiceLoadCredentialsStateToLabel(load_tokens_state));
548 544
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 578
583 #if !defined(OS_CHROMEOS) 579 #if !defined(OS_CHROMEOS)
584 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 580 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
585 // fixed. 581 // fixed.
586 tracked_objects::ScopedTracker tracking_profile3( 582 tracked_objects::ScopedTracker tracking_profile3(
587 FROM_HERE_WITH_EXPLICIT_FUNCTION( 583 FROM_HERE_WITH_EXPLICIT_FUNCTION(
588 "422460 AboutSigninInternals::SigninStatus::ToValue3")); 584 "422460 AboutSigninInternals::SigninStatus::ToValue3"));
589 585
590 // Time and status information of the possible sign in types. 586 // Time and status information of the possible sign in types.
591 base::ListValue* detailed_info = 587 base::ListValue* detailed_info =
592 AddSection(signin_info, "Last Signin Details"); 588 AddSection(signin_info.get(), "Last Signin Details");
589 signin_status->Set("signin_info", std::move(signin_info));
593 for (int i = TIMED_FIELDS_BEGIN; i < TIMED_FIELDS_END; ++i) { 590 for (int i = TIMED_FIELDS_BEGIN; i < TIMED_FIELDS_END; ++i) {
594 const std::string status_field_label = 591 const std::string status_field_label =
595 SigninStatusFieldToLabel(static_cast<TimedSigninStatusField>(i)); 592 SigninStatusFieldToLabel(static_cast<TimedSigninStatusField>(i));
596 593
597 AddSectionEntry(detailed_info, 594 AddSectionEntry(detailed_info,
598 status_field_label, 595 status_field_label,
599 timed_signin_fields[i - TIMED_FIELDS_BEGIN].first, 596 timed_signin_fields[i - TIMED_FIELDS_BEGIN].first,
600 timed_signin_fields[i - TIMED_FIELDS_BEGIN].second); 597 timed_signin_fields[i - TIMED_FIELDS_BEGIN].second);
601 } 598 }
602 599
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 634
638 #endif // !defined(OS_CHROMEOS) 635 #endif // !defined(OS_CHROMEOS)
639 636
640 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 637 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
641 // fixed. 638 // fixed.
642 tracked_objects::ScopedTracker tracking_profile4( 639 tracked_objects::ScopedTracker tracking_profile4(
643 FROM_HERE_WITH_EXPLICIT_FUNCTION( 640 FROM_HERE_WITH_EXPLICIT_FUNCTION(
644 "422460 AboutSigninInternals::SigninStatus::ToValue4")); 641 "422460 AboutSigninInternals::SigninStatus::ToValue4"));
645 642
646 // Token information for all services. 643 // Token information for all services.
647 base::ListValue* token_info = new base::ListValue(); 644 auto token_info = base::MakeUnique<base::ListValue>();
648 signin_status->Set("token_info", token_info);
649 for (auto it = token_info_map.begin(); it != token_info_map.end(); ++it) { 645 for (auto it = token_info_map.begin(); it != token_info_map.end(); ++it) {
650 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 646 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
651 // is fixed. 647 // is fixed.
652 tracked_objects::ScopedTracker tracking_profile41( 648 tracked_objects::ScopedTracker tracking_profile41(
653 FROM_HERE_WITH_EXPLICIT_FUNCTION( 649 FROM_HERE_WITH_EXPLICIT_FUNCTION(
654 "422460 AboutSigninInternals::SigninStatus::ToValue41")); 650 "422460 AboutSigninInternals::SigninStatus::ToValue41"));
655 651
656 base::ListValue* token_details = AddSection(token_info, it->first); 652 base::ListValue* token_details = AddSection(token_info.get(), it->first);
657 653
658 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 654 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
659 // is fixed. 655 // is fixed.
660 tracked_objects::ScopedTracker tracking_profile42( 656 tracked_objects::ScopedTracker tracking_profile42(
661 FROM_HERE_WITH_EXPLICIT_FUNCTION( 657 FROM_HERE_WITH_EXPLICIT_FUNCTION(
662 "422460 AboutSigninInternals::SigninStatus::ToValue42")); 658 "422460 AboutSigninInternals::SigninStatus::ToValue42"));
663 659
664 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); 660 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan);
665 const auto& tokens = it->second; 661 const auto& tokens = it->second;
666 662
667 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 663 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
668 // is fixed. 664 // is fixed.
669 tracked_objects::ScopedTracker tracking_profile43( 665 tracked_objects::ScopedTracker tracking_profile43(
670 FROM_HERE_WITH_EXPLICIT_FUNCTION( 666 FROM_HERE_WITH_EXPLICIT_FUNCTION(
671 "422460 AboutSigninInternals::SigninStatus::ToValue43")); 667 "422460 AboutSigninInternals::SigninStatus::ToValue43"));
672 668
673 for (const std::unique_ptr<TokenInfo>& token : tokens) { 669 for (const std::unique_ptr<TokenInfo>& token : tokens) {
674 token_details->Append(token->ToValue()); 670 token_details->Append(token->ToValue());
675 } 671 }
676 } 672 }
673 signin_status->Set("token_info", std::move(token_info));
677 674
678 base::ListValue* account_info = new base::ListValue(); 675 auto account_info = base::MakeUnique<base::ListValue>();
679 signin_status->Set("accountInfo", account_info);
680 const std::vector<std::string>& accounts_in_token_service = 676 const std::vector<std::string>& accounts_in_token_service =
681 token_service->GetAccounts(); 677 token_service->GetAccounts();
682 678
683 if(accounts_in_token_service.size() == 0) { 679 if (accounts_in_token_service.size() == 0) {
684 std::unique_ptr<base::DictionaryValue> no_token_entry( 680 auto no_token_entry = base::MakeUnique<base::DictionaryValue>();
685 new base::DictionaryValue());
686 no_token_entry->SetString("accountId", "No token in Token Service."); 681 no_token_entry->SetString("accountId", "No token in Token Service.");
687 account_info->Append(std::move(no_token_entry)); 682 account_info->Append(std::move(no_token_entry));
688 } 683 }
689 684
690 for(const std::string& account_id : accounts_in_token_service) { 685 for (const std::string& account_id : accounts_in_token_service) {
691 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); 686 auto entry = base::MakeUnique<base::DictionaryValue>();
692 entry->SetString("accountId", account_id); 687 entry->SetString("accountId", account_id);
693 account_info->Append(std::move(entry)); 688 account_info->Append(std::move(entry));
694 } 689 }
695 690
691 signin_status->Set("accountInfo", std::move(account_info));
696 return signin_status; 692 return signin_status;
697 } 693 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_prepopulate_data_unittest.cc ('k') | components/sync/base/model_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698