Chromium Code Reviews| Index: components/signin/core/browser/about_signin_internals.cc |
| diff --git a/components/signin/core/browser/about_signin_internals.cc b/components/signin/core/browser/about_signin_internals.cc |
| index d7c10777df616708af0742c68009dcf71e6f56d2..1c79a10c9d16d7eb0fe4ac19aa369f98e479d09a 100644 |
| --- a/components/signin/core/browser/about_signin_internals.cc |
| +++ b/components/signin/core/browser/about_signin_internals.cc |
| @@ -6,12 +6,14 @@ |
| #include <stddef.h> |
| +#include <tuple> |
| #include <utility> |
| #include "base/command_line.h" |
| #include "base/hash.h" |
| #include "base/i18n/time_formatting.h" |
| #include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/profiler/scoped_tracker.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -306,8 +308,8 @@ void AboutSigninInternals::OnAccessTokenRequested( |
| if (token) { |
| *token = TokenInfo(consumer_id, scopes); |
| } else { |
| - token = new TokenInfo(consumer_id, scopes); |
| - signin_status_.token_info_map[account_id].push_back(token); |
| + signin_status_.token_info_map[account_id].push_back( |
| + base::MakeUnique<TokenInfo>(consumer_id, scopes)); |
| } |
| NotifyObservers(); |
| @@ -335,9 +337,7 @@ void AboutSigninInternals::OnFetchAccessTokenComplete( |
| void AboutSigninInternals::OnTokenRemoved( |
| const std::string& account_id, |
| const OAuth2TokenService::ScopeSet& scopes) { |
| - for (size_t i = 0; i < signin_status_.token_info_map[account_id].size(); |
| - ++i) { |
| - TokenInfo* token = signin_status_.token_info_map[account_id][i]; |
| + 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
|
| if (token->scopes == scopes) |
| token->Invalidate(); |
| } |
| @@ -414,15 +414,11 @@ AboutSigninInternals::TokenInfo::TokenInfo( |
| AboutSigninInternals::TokenInfo::~TokenInfo() {} |
| -bool AboutSigninInternals::TokenInfo::LessThan(const TokenInfo* a, |
| - const TokenInfo* b) { |
| - if (a->request_time == b->request_time) { |
| - if (a->consumer_id == b->consumer_id) { |
| - return a->scopes < b->scopes; |
| - } |
| - return a->consumer_id < b->consumer_id; |
| - } |
| - return a->request_time < b->request_time; |
| +bool AboutSigninInternals::TokenInfo::LessThan( |
| + const std::unique_ptr<TokenInfo>& a, |
| + const std::unique_ptr<TokenInfo>& b) { |
| + return std::tie(a->request_time, a->consumer_id, a->scopes) < |
| + 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 :)
|
| } |
| void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } |
| @@ -476,24 +472,17 @@ AboutSigninInternals::TokenInfo::ToValue() const { |
| AboutSigninInternals::SigninStatus::SigninStatus() |
| : timed_signin_fields(TIMED_FIELDS_COUNT) {} |
| -AboutSigninInternals::SigninStatus::~SigninStatus() { |
| - for (TokenInfoMap::iterator it = token_info_map.begin(); |
| - it != token_info_map.end(); |
| - ++it) { |
| - base::STLDeleteElements(&it->second); |
| - } |
| -} |
| +AboutSigninInternals::SigninStatus::~SigninStatus() {} |
| AboutSigninInternals::TokenInfo* AboutSigninInternals::SigninStatus::FindToken( |
| const std::string& account_id, |
| const std::string& consumer_id, |
| const OAuth2TokenService::ScopeSet& scopes) { |
| - for (size_t i = 0; i < token_info_map[account_id].size(); ++i) { |
| - TokenInfo* tmp = token_info_map[account_id][i]; |
| - if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) |
| - return tmp; |
| + for (const auto& token : token_info_map[account_id]) { |
| + if (token->consumer_id == consumer_id && token->scopes == scopes) |
| + return token.get(); |
| } |
| - return NULL; |
| + return nullptr; |
| } |
| std::unique_ptr<base::DictionaryValue> |
| @@ -625,9 +614,7 @@ AboutSigninInternals::SigninStatus::ToValue( |
| // Token information for all services. |
| base::ListValue* token_info = new base::ListValue(); |
| signin_status->Set("token_info", token_info); |
| - for (TokenInfoMap::iterator it = token_info_map.begin(); |
| - it != token_info_map.end(); |
| - ++it) { |
| + for (auto it = token_info_map.begin(); it != token_info_map.end(); ++it) { |
| // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| // is fixed. |
| tracked_objects::ScopedTracker tracking_profile41( |
| @@ -643,7 +630,7 @@ AboutSigninInternals::SigninStatus::ToValue( |
| "422460 AboutSigninInternals::SigninStatus::ToValue42")); |
| std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); |
| - const std::vector<TokenInfo*>& tokens = it->second; |
| + const auto& tokens = it->second; |
| // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| // is fixed. |
| @@ -651,8 +638,8 @@ AboutSigninInternals::SigninStatus::ToValue( |
| FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| "422460 AboutSigninInternals::SigninStatus::ToValue43")); |
| - for (size_t i = 0; i < tokens.size(); ++i) { |
| - token_details->Append(tokens[i]->ToValue()); |
| + for (const auto& token : tokens) { |
| + token_details->Append(token->ToValue()); |
| } |
| } |