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

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

Issue 2461223003: Remove stl_util's deletion function use from components/signin/. (Closed)
Patch Set: more loop Created 4 years, 1 month 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
« no previous file with comments | « components/signin/core/browser/about_signin_internals.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 10 #include <utility>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/hash.h" 13 #include "base/hash.h"
13 #include "base/i18n/time_formatting.h" 14 #include "base/i18n/time_formatting.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h"
15 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
19 #include "build/build_config.h" 21 #include "build/build_config.h"
20 #include "components/pref_registry/pref_registry_syncable.h" 22 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
22 #include "components/signin/core/browser/account_tracker_service.h" 24 #include "components/signin/core/browser/account_tracker_service.h"
23 #include "components/signin/core/browser/profile_oauth2_token_service.h" 25 #include "components/signin/core/browser/profile_oauth2_token_service.h"
24 #include "components/signin/core/browser/signin_client.h" 26 #include "components/signin/core/browser/signin_client.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 301 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
300 // fixed. 302 // fixed.
301 tracked_objects::ScopedTracker tracking_profile( 303 tracked_objects::ScopedTracker tracking_profile(
302 FROM_HERE_WITH_EXPLICIT_FUNCTION( 304 FROM_HERE_WITH_EXPLICIT_FUNCTION(
303 "422460 AboutSigninInternals::OnAccessTokenRequested")); 305 "422460 AboutSigninInternals::OnAccessTokenRequested"));
304 306
305 TokenInfo* token = signin_status_.FindToken(account_id, consumer_id, scopes); 307 TokenInfo* token = signin_status_.FindToken(account_id, consumer_id, scopes);
306 if (token) { 308 if (token) {
307 *token = TokenInfo(consumer_id, scopes); 309 *token = TokenInfo(consumer_id, scopes);
308 } else { 310 } else {
309 token = new TokenInfo(consumer_id, scopes); 311 signin_status_.token_info_map[account_id].push_back(
310 signin_status_.token_info_map[account_id].push_back(token); 312 base::MakeUnique<TokenInfo>(consumer_id, scopes));
311 } 313 }
312 314
313 NotifyObservers(); 315 NotifyObservers();
314 } 316 }
315 317
316 void AboutSigninInternals::OnFetchAccessTokenComplete( 318 void AboutSigninInternals::OnFetchAccessTokenComplete(
317 const std::string& account_id, 319 const std::string& account_id,
318 const std::string& consumer_id, 320 const std::string& consumer_id,
319 const OAuth2TokenService::ScopeSet& scopes, 321 const OAuth2TokenService::ScopeSet& scopes,
320 GoogleServiceAuthError error, 322 GoogleServiceAuthError error,
321 base::Time expiration_time) { 323 base::Time expiration_time) {
322 TokenInfo* token = signin_status_.FindToken(account_id, consumer_id, scopes); 324 TokenInfo* token = signin_status_.FindToken(account_id, consumer_id, scopes);
323 if (!token) { 325 if (!token) {
324 DVLOG(1) << "Can't find token: " << account_id << ", " << consumer_id; 326 DVLOG(1) << "Can't find token: " << account_id << ", " << consumer_id;
325 return; 327 return;
326 } 328 }
327 329
328 token->receive_time = base::Time::Now(); 330 token->receive_time = base::Time::Now();
329 token->error = error; 331 token->error = error;
330 token->expiration_time = expiration_time; 332 token->expiration_time = expiration_time;
331 333
332 NotifyObservers(); 334 NotifyObservers();
333 } 335 }
334 336
335 void AboutSigninInternals::OnTokenRemoved( 337 void AboutSigninInternals::OnTokenRemoved(
336 const std::string& account_id, 338 const std::string& account_id,
337 const OAuth2TokenService::ScopeSet& scopes) { 339 const OAuth2TokenService::ScopeSet& scopes) {
338 for (size_t i = 0; i < signin_status_.token_info_map[account_id].size(); 340 for (const std::unique_ptr<TokenInfo>& token :
339 ++i) { 341 signin_status_.token_info_map[account_id]) {
340 TokenInfo* token = signin_status_.token_info_map[account_id][i];
341 if (token->scopes == scopes) 342 if (token->scopes == scopes)
342 token->Invalidate(); 343 token->Invalidate();
343 } 344 }
344 NotifyObservers(); 345 NotifyObservers();
345 } 346 }
346 347
347 void AboutSigninInternals::OnRefreshTokenReceived(const std::string& status) { 348 void AboutSigninInternals::OnRefreshTokenReceived(const std::string& status) {
348 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); 349 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status);
349 } 350 }
350 351
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 const std::string& consumer_id, 408 const std::string& consumer_id,
408 const OAuth2TokenService::ScopeSet& scopes) 409 const OAuth2TokenService::ScopeSet& scopes)
409 : consumer_id(consumer_id), 410 : consumer_id(consumer_id),
410 scopes(scopes), 411 scopes(scopes),
411 request_time(base::Time::Now()), 412 request_time(base::Time::Now()),
412 error(GoogleServiceAuthError::AuthErrorNone()), 413 error(GoogleServiceAuthError::AuthErrorNone()),
413 removed_(false) {} 414 removed_(false) {}
414 415
415 AboutSigninInternals::TokenInfo::~TokenInfo() {} 416 AboutSigninInternals::TokenInfo::~TokenInfo() {}
416 417
417 bool AboutSigninInternals::TokenInfo::LessThan(const TokenInfo* a, 418 bool AboutSigninInternals::TokenInfo::LessThan(
418 const TokenInfo* b) { 419 const std::unique_ptr<TokenInfo>& a,
419 if (a->request_time == b->request_time) { 420 const std::unique_ptr<TokenInfo>& b) {
420 if (a->consumer_id == b->consumer_id) { 421 return std::tie(a->request_time, a->consumer_id, a->scopes) <
421 return a->scopes < b->scopes; 422 std::tie(b->request_time, b->consumer_id, b->scopes);
422 }
423 return a->consumer_id < b->consumer_id;
424 }
425 return a->request_time < b->request_time;
426 } 423 }
427 424
428 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } 425 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; }
429 426
430 std::unique_ptr<base::DictionaryValue> 427 std::unique_ptr<base::DictionaryValue>
431 AboutSigninInternals::TokenInfo::ToValue() const { 428 AboutSigninInternals::TokenInfo::ToValue() const {
432 std::unique_ptr<base::DictionaryValue> token_info( 429 std::unique_ptr<base::DictionaryValue> token_info(
433 new base::DictionaryValue()); 430 new base::DictionaryValue());
434 token_info->SetString("service", consumer_id); 431 token_info->SetString("service", consumer_id);
435 432
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } else { 466 } else {
470 token_info->SetString("status", "Waiting for response"); 467 token_info->SetString("status", "Waiting for response");
471 } 468 }
472 469
473 return token_info; 470 return token_info;
474 } 471 }
475 472
476 AboutSigninInternals::SigninStatus::SigninStatus() 473 AboutSigninInternals::SigninStatus::SigninStatus()
477 : timed_signin_fields(TIMED_FIELDS_COUNT) {} 474 : timed_signin_fields(TIMED_FIELDS_COUNT) {}
478 475
479 AboutSigninInternals::SigninStatus::~SigninStatus() { 476 AboutSigninInternals::SigninStatus::~SigninStatus() {}
480 for (TokenInfoMap::iterator it = token_info_map.begin();
481 it != token_info_map.end();
482 ++it) {
483 base::STLDeleteElements(&it->second);
484 }
485 }
486 477
487 AboutSigninInternals::TokenInfo* AboutSigninInternals::SigninStatus::FindToken( 478 AboutSigninInternals::TokenInfo* AboutSigninInternals::SigninStatus::FindToken(
488 const std::string& account_id, 479 const std::string& account_id,
489 const std::string& consumer_id, 480 const std::string& consumer_id,
490 const OAuth2TokenService::ScopeSet& scopes) { 481 const OAuth2TokenService::ScopeSet& scopes) {
491 for (size_t i = 0; i < token_info_map[account_id].size(); ++i) { 482 for (const std::unique_ptr<TokenInfo>& token : token_info_map[account_id]) {
492 TokenInfo* tmp = token_info_map[account_id][i]; 483 if (token->consumer_id == consumer_id && token->scopes == scopes)
493 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) 484 return token.get();
494 return tmp;
495 } 485 }
496 return NULL; 486 return nullptr;
497 } 487 }
498 488
499 std::unique_ptr<base::DictionaryValue> 489 std::unique_ptr<base::DictionaryValue>
500 AboutSigninInternals::SigninStatus::ToValue( 490 AboutSigninInternals::SigninStatus::ToValue(
501 AccountTrackerService* account_tracker, 491 AccountTrackerService* account_tracker,
502 SigninManagerBase* signin_manager, 492 SigninManagerBase* signin_manager,
503 SigninErrorController* signin_error_controller, 493 SigninErrorController* signin_error_controller,
504 ProfileOAuth2TokenService* token_service, 494 ProfileOAuth2TokenService* token_service,
505 GaiaCookieManagerService* cookie_manager_service_, 495 GaiaCookieManagerService* cookie_manager_service_,
506 const std::string& product_version) { 496 const std::string& product_version) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 608
619 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 609 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
620 // fixed. 610 // fixed.
621 tracked_objects::ScopedTracker tracking_profile4( 611 tracked_objects::ScopedTracker tracking_profile4(
622 FROM_HERE_WITH_EXPLICIT_FUNCTION( 612 FROM_HERE_WITH_EXPLICIT_FUNCTION(
623 "422460 AboutSigninInternals::SigninStatus::ToValue4")); 613 "422460 AboutSigninInternals::SigninStatus::ToValue4"));
624 614
625 // Token information for all services. 615 // Token information for all services.
626 base::ListValue* token_info = new base::ListValue(); 616 base::ListValue* token_info = new base::ListValue();
627 signin_status->Set("token_info", token_info); 617 signin_status->Set("token_info", token_info);
628 for (TokenInfoMap::iterator it = token_info_map.begin(); 618 for (auto it = token_info_map.begin(); it != token_info_map.end(); ++it) {
629 it != token_info_map.end();
630 ++it) {
631 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 619 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
632 // is fixed. 620 // is fixed.
633 tracked_objects::ScopedTracker tracking_profile41( 621 tracked_objects::ScopedTracker tracking_profile41(
634 FROM_HERE_WITH_EXPLICIT_FUNCTION( 622 FROM_HERE_WITH_EXPLICIT_FUNCTION(
635 "422460 AboutSigninInternals::SigninStatus::ToValue41")); 623 "422460 AboutSigninInternals::SigninStatus::ToValue41"));
636 624
637 base::ListValue* token_details = AddSection(token_info, it->first); 625 base::ListValue* token_details = AddSection(token_info, it->first);
638 626
639 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 627 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
640 // is fixed. 628 // is fixed.
641 tracked_objects::ScopedTracker tracking_profile42( 629 tracked_objects::ScopedTracker tracking_profile42(
642 FROM_HERE_WITH_EXPLICIT_FUNCTION( 630 FROM_HERE_WITH_EXPLICIT_FUNCTION(
643 "422460 AboutSigninInternals::SigninStatus::ToValue42")); 631 "422460 AboutSigninInternals::SigninStatus::ToValue42"));
644 632
645 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); 633 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan);
646 const std::vector<TokenInfo*>& tokens = it->second; 634 const auto& tokens = it->second;
647 635
648 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 636 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460
649 // is fixed. 637 // is fixed.
650 tracked_objects::ScopedTracker tracking_profile43( 638 tracked_objects::ScopedTracker tracking_profile43(
651 FROM_HERE_WITH_EXPLICIT_FUNCTION( 639 FROM_HERE_WITH_EXPLICIT_FUNCTION(
652 "422460 AboutSigninInternals::SigninStatus::ToValue43")); 640 "422460 AboutSigninInternals::SigninStatus::ToValue43"));
653 641
654 for (size_t i = 0; i < tokens.size(); ++i) { 642 for (const std::unique_ptr<TokenInfo>& token : tokens) {
655 token_details->Append(tokens[i]->ToValue()); 643 token_details->Append(token->ToValue());
656 } 644 }
657 } 645 }
658 646
659 base::ListValue* account_info = new base::ListValue(); 647 base::ListValue* account_info = new base::ListValue();
660 signin_status->Set("accountInfo", account_info); 648 signin_status->Set("accountInfo", account_info);
661 const std::vector<std::string>& accounts_in_token_service = 649 const std::vector<std::string>& accounts_in_token_service =
662 token_service->GetAccounts(); 650 token_service->GetAccounts();
663 651
664 if(accounts_in_token_service.size() == 0) { 652 if(accounts_in_token_service.size() == 0) {
665 std::unique_ptr<base::DictionaryValue> no_token_entry( 653 std::unique_ptr<base::DictionaryValue> no_token_entry(
666 new base::DictionaryValue()); 654 new base::DictionaryValue());
667 no_token_entry->SetString("accountId", "No token in Token Service."); 655 no_token_entry->SetString("accountId", "No token in Token Service.");
668 account_info->Append(std::move(no_token_entry)); 656 account_info->Append(std::move(no_token_entry));
669 } 657 }
670 658
671 for(const std::string& account_id : accounts_in_token_service) { 659 for(const std::string& account_id : accounts_in_token_service) {
672 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); 660 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue());
673 entry->SetString("accountId", account_id); 661 entry->SetString("accountId", account_id);
674 account_info->Append(std::move(entry)); 662 account_info->Append(std::move(entry));
675 } 663 }
676 664
677 return signin_status; 665 return signin_status;
678 } 666 }
OLDNEW
« no previous file with comments | « components/signin/core/browser/about_signin_internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698