Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 auto& token : signin_status_.token_info_map[account_id]) { |
|
Roger Tawa OOO till Jul 10th
2016/11/08 15:40:34
For my own info, is there a danger of doing:
fo
Avi (use Gerrit)
2016/11/08 18:50:51
You can't do either of those. auto would deduce th
| |
| 339 ++i) { | |
| 340 TokenInfo* token = signin_status_.token_info_map[account_id][i]; | |
| 341 if (token->scopes == scopes) | 341 if (token->scopes == scopes) |
| 342 token->Invalidate(); | 342 token->Invalidate(); |
| 343 } | 343 } |
| 344 NotifyObservers(); | 344 NotifyObservers(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void AboutSigninInternals::OnRefreshTokenReceived(const std::string& status) { | 347 void AboutSigninInternals::OnRefreshTokenReceived(const std::string& status) { |
| 348 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); | 348 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); |
| 349 } | 349 } |
| 350 | 350 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 const std::string& consumer_id, | 407 const std::string& consumer_id, |
| 408 const OAuth2TokenService::ScopeSet& scopes) | 408 const OAuth2TokenService::ScopeSet& scopes) |
| 409 : consumer_id(consumer_id), | 409 : consumer_id(consumer_id), |
| 410 scopes(scopes), | 410 scopes(scopes), |
| 411 request_time(base::Time::Now()), | 411 request_time(base::Time::Now()), |
| 412 error(GoogleServiceAuthError::AuthErrorNone()), | 412 error(GoogleServiceAuthError::AuthErrorNone()), |
| 413 removed_(false) {} | 413 removed_(false) {} |
| 414 | 414 |
| 415 AboutSigninInternals::TokenInfo::~TokenInfo() {} | 415 AboutSigninInternals::TokenInfo::~TokenInfo() {} |
| 416 | 416 |
| 417 bool AboutSigninInternals::TokenInfo::LessThan(const TokenInfo* a, | 417 bool AboutSigninInternals::TokenInfo::LessThan( |
| 418 const TokenInfo* b) { | 418 const std::unique_ptr<TokenInfo>& a, |
| 419 if (a->request_time == b->request_time) { | 419 const std::unique_ptr<TokenInfo>& b) { |
| 420 if (a->consumer_id == b->consumer_id) { | 420 return std::tie(a->request_time, a->consumer_id, a->scopes) < |
| 421 return a->scopes < b->scopes; | 421 std::tie(b->request_time, b->consumer_id, b->scopes); |
|
Roger Tawa OOO till Jul 10th
2016/11/08 15:40:34
That's neat :-)
Avi (use Gerrit)
2016/11/08 18:50:51
Indeed it is :)
| |
| 422 } | |
| 423 return a->consumer_id < b->consumer_id; | |
| 424 } | |
| 425 return a->request_time < b->request_time; | |
| 426 } | 422 } |
| 427 | 423 |
| 428 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } | 424 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } |
| 429 | 425 |
| 430 std::unique_ptr<base::DictionaryValue> | 426 std::unique_ptr<base::DictionaryValue> |
| 431 AboutSigninInternals::TokenInfo::ToValue() const { | 427 AboutSigninInternals::TokenInfo::ToValue() const { |
| 432 std::unique_ptr<base::DictionaryValue> token_info( | 428 std::unique_ptr<base::DictionaryValue> token_info( |
| 433 new base::DictionaryValue()); | 429 new base::DictionaryValue()); |
| 434 token_info->SetString("service", consumer_id); | 430 token_info->SetString("service", consumer_id); |
| 435 | 431 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 } else { | 465 } else { |
| 470 token_info->SetString("status", "Waiting for response"); | 466 token_info->SetString("status", "Waiting for response"); |
| 471 } | 467 } |
| 472 | 468 |
| 473 return token_info; | 469 return token_info; |
| 474 } | 470 } |
| 475 | 471 |
| 476 AboutSigninInternals::SigninStatus::SigninStatus() | 472 AboutSigninInternals::SigninStatus::SigninStatus() |
| 477 : timed_signin_fields(TIMED_FIELDS_COUNT) {} | 473 : timed_signin_fields(TIMED_FIELDS_COUNT) {} |
| 478 | 474 |
| 479 AboutSigninInternals::SigninStatus::~SigninStatus() { | 475 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 | 476 |
| 487 AboutSigninInternals::TokenInfo* AboutSigninInternals::SigninStatus::FindToken( | 477 AboutSigninInternals::TokenInfo* AboutSigninInternals::SigninStatus::FindToken( |
| 488 const std::string& account_id, | 478 const std::string& account_id, |
| 489 const std::string& consumer_id, | 479 const std::string& consumer_id, |
| 490 const OAuth2TokenService::ScopeSet& scopes) { | 480 const OAuth2TokenService::ScopeSet& scopes) { |
| 491 for (size_t i = 0; i < token_info_map[account_id].size(); ++i) { | 481 for (const auto& token : token_info_map[account_id]) { |
| 492 TokenInfo* tmp = token_info_map[account_id][i]; | 482 if (token->consumer_id == consumer_id && token->scopes == scopes) |
| 493 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) | 483 return token.get(); |
| 494 return tmp; | |
| 495 } | 484 } |
| 496 return NULL; | 485 return nullptr; |
| 497 } | 486 } |
| 498 | 487 |
| 499 std::unique_ptr<base::DictionaryValue> | 488 std::unique_ptr<base::DictionaryValue> |
| 500 AboutSigninInternals::SigninStatus::ToValue( | 489 AboutSigninInternals::SigninStatus::ToValue( |
| 501 AccountTrackerService* account_tracker, | 490 AccountTrackerService* account_tracker, |
| 502 SigninManagerBase* signin_manager, | 491 SigninManagerBase* signin_manager, |
| 503 SigninErrorController* signin_error_controller, | 492 SigninErrorController* signin_error_controller, |
| 504 ProfileOAuth2TokenService* token_service, | 493 ProfileOAuth2TokenService* token_service, |
| 505 GaiaCookieManagerService* cookie_manager_service_, | 494 GaiaCookieManagerService* cookie_manager_service_, |
| 506 const std::string& product_version) { | 495 const std::string& product_version) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 | 607 |
| 619 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 608 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 620 // fixed. | 609 // fixed. |
| 621 tracked_objects::ScopedTracker tracking_profile4( | 610 tracked_objects::ScopedTracker tracking_profile4( |
| 622 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 611 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 623 "422460 AboutSigninInternals::SigninStatus::ToValue4")); | 612 "422460 AboutSigninInternals::SigninStatus::ToValue4")); |
| 624 | 613 |
| 625 // Token information for all services. | 614 // Token information for all services. |
| 626 base::ListValue* token_info = new base::ListValue(); | 615 base::ListValue* token_info = new base::ListValue(); |
| 627 signin_status->Set("token_info", token_info); | 616 signin_status->Set("token_info", token_info); |
| 628 for (TokenInfoMap::iterator it = token_info_map.begin(); | 617 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 | 618 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| 632 // is fixed. | 619 // is fixed. |
| 633 tracked_objects::ScopedTracker tracking_profile41( | 620 tracked_objects::ScopedTracker tracking_profile41( |
| 634 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 621 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 635 "422460 AboutSigninInternals::SigninStatus::ToValue41")); | 622 "422460 AboutSigninInternals::SigninStatus::ToValue41")); |
| 636 | 623 |
| 637 base::ListValue* token_details = AddSection(token_info, it->first); | 624 base::ListValue* token_details = AddSection(token_info, it->first); |
| 638 | 625 |
| 639 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 626 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| 640 // is fixed. | 627 // is fixed. |
| 641 tracked_objects::ScopedTracker tracking_profile42( | 628 tracked_objects::ScopedTracker tracking_profile42( |
| 642 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 629 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 643 "422460 AboutSigninInternals::SigninStatus::ToValue42")); | 630 "422460 AboutSigninInternals::SigninStatus::ToValue42")); |
| 644 | 631 |
| 645 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); | 632 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); |
| 646 const std::vector<TokenInfo*>& tokens = it->second; | 633 const auto& tokens = it->second; |
| 647 | 634 |
| 648 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 635 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| 649 // is fixed. | 636 // is fixed. |
| 650 tracked_objects::ScopedTracker tracking_profile43( | 637 tracked_objects::ScopedTracker tracking_profile43( |
| 651 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 638 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 652 "422460 AboutSigninInternals::SigninStatus::ToValue43")); | 639 "422460 AboutSigninInternals::SigninStatus::ToValue43")); |
| 653 | 640 |
| 654 for (size_t i = 0; i < tokens.size(); ++i) { | 641 for (const auto& token : tokens) { |
| 655 token_details->Append(tokens[i]->ToValue()); | 642 token_details->Append(token->ToValue()); |
| 656 } | 643 } |
| 657 } | 644 } |
| 658 | 645 |
| 659 base::ListValue* account_info = new base::ListValue(); | 646 base::ListValue* account_info = new base::ListValue(); |
| 660 signin_status->Set("accountInfo", account_info); | 647 signin_status->Set("accountInfo", account_info); |
| 661 const std::vector<std::string>& accounts_in_token_service = | 648 const std::vector<std::string>& accounts_in_token_service = |
| 662 token_service->GetAccounts(); | 649 token_service->GetAccounts(); |
| 663 | 650 |
| 664 if(accounts_in_token_service.size() == 0) { | 651 if(accounts_in_token_service.size() == 0) { |
| 665 std::unique_ptr<base::DictionaryValue> no_token_entry( | 652 std::unique_ptr<base::DictionaryValue> no_token_entry( |
| 666 new base::DictionaryValue()); | 653 new base::DictionaryValue()); |
| 667 no_token_entry->SetString("accountId", "No token in Token Service."); | 654 no_token_entry->SetString("accountId", "No token in Token Service."); |
| 668 account_info->Append(std::move(no_token_entry)); | 655 account_info->Append(std::move(no_token_entry)); |
| 669 } | 656 } |
| 670 | 657 |
| 671 for(const std::string& account_id : accounts_in_token_service) { | 658 for(const std::string& account_id : accounts_in_token_service) { |
| 672 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); | 659 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); |
| 673 entry->SetString("accountId", account_id); | 660 entry->SetString("accountId", account_id); |
| 674 account_info->Append(std::move(entry)); | 661 account_info->Append(std::move(entry)); |
| 675 } | 662 } |
| 676 | 663 |
| 677 return signin_status; | 664 return signin_status; |
| 678 } | 665 } |
| OLD | NEW |