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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 240 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
241 // fixed. | 241 // fixed. |
242 tracked_objects::ScopedTracker tracking_profile05( | 242 tracked_objects::ScopedTracker tracking_profile05( |
243 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 243 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
244 "422460 AboutSigninInternals::NotifyObservers 0.5")); | 244 "422460 AboutSigninInternals::NotifyObservers 0.5")); |
245 | 245 |
246 scoped_ptr<base::DictionaryValue> signin_status_value = | 246 scoped_ptr<base::DictionaryValue> signin_status_value = |
247 signin_status_.ToValue(account_tracker_, | 247 signin_status_.ToValue(account_tracker_, |
248 signin_manager_, | 248 signin_manager_, |
249 signin_error_controller_, | 249 signin_error_controller_, |
| 250 token_service_, |
250 product_version); | 251 product_version); |
251 | 252 |
252 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 253 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
253 // fixed. | 254 // fixed. |
254 tracked_objects::ScopedTracker tracking_profile1( | 255 tracked_objects::ScopedTracker tracking_profile1( |
255 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 256 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
256 "422460 AboutSigninInternals::NotifyObservers1")); | 257 "422460 AboutSigninInternals::NotifyObservers1")); |
257 | 258 |
258 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 259 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
259 signin_observers_, | 260 signin_observers_, |
260 OnSigninStateChanged(signin_status_value.get())); | 261 OnSigninStateChanged(signin_status_value.get())); |
261 } | 262 } |
262 | 263 |
263 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { | 264 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { |
264 return signin_status_.ToValue(account_tracker_, | 265 return signin_status_.ToValue(account_tracker_, |
265 signin_manager_, | 266 signin_manager_, |
266 signin_error_controller_, | 267 signin_error_controller_, |
| 268 token_service_, |
267 client_->GetProductVersion()).Pass(); | 269 client_->GetProductVersion()).Pass(); |
268 } | 270 } |
269 | 271 |
270 void AboutSigninInternals::OnAccessTokenRequested( | 272 void AboutSigninInternals::OnAccessTokenRequested( |
271 const std::string& account_id, | 273 const std::string& account_id, |
272 const std::string& consumer_id, | 274 const std::string& consumer_id, |
273 const OAuth2TokenService::ScopeSet& scopes) { | 275 const OAuth2TokenService::ScopeSet& scopes) { |
274 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 276 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
275 // fixed. | 277 // fixed. |
276 tracked_objects::ScopedTracker tracking_profile( | 278 tracked_objects::ScopedTracker tracking_profile( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 : consumer_id(consumer_id), | 414 : consumer_id(consumer_id), |
413 scopes(scopes), | 415 scopes(scopes), |
414 request_time(base::Time::Now()), | 416 request_time(base::Time::Now()), |
415 error(GoogleServiceAuthError::AuthErrorNone()), | 417 error(GoogleServiceAuthError::AuthErrorNone()), |
416 removed_(false) {} | 418 removed_(false) {} |
417 | 419 |
418 AboutSigninInternals::TokenInfo::~TokenInfo() {} | 420 AboutSigninInternals::TokenInfo::~TokenInfo() {} |
419 | 421 |
420 bool AboutSigninInternals::TokenInfo::LessThan(const TokenInfo* a, | 422 bool AboutSigninInternals::TokenInfo::LessThan(const TokenInfo* a, |
421 const TokenInfo* b) { | 423 const TokenInfo* b) { |
422 return a->consumer_id < b->consumer_id || | 424 if (a->request_time == b->request_time) { |
423 (a->consumer_id == b->consumer_id && a->scopes < b->scopes); | 425 if (a->consumer_id == b->consumer_id) { |
| 426 return a->scopes < b->scopes; |
| 427 } |
| 428 return a->consumer_id < b->consumer_id; |
| 429 } |
| 430 return a->request_time < b->request_time; |
424 } | 431 } |
425 | 432 |
426 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } | 433 void AboutSigninInternals::TokenInfo::Invalidate() { removed_ = true; } |
427 | 434 |
428 base::DictionaryValue* AboutSigninInternals::TokenInfo::ToValue() const { | 435 base::DictionaryValue* AboutSigninInternals::TokenInfo::ToValue() const { |
429 scoped_ptr<base::DictionaryValue> token_info(new base::DictionaryValue()); | 436 scoped_ptr<base::DictionaryValue> token_info(new base::DictionaryValue()); |
430 token_info->SetString("service", consumer_id); | 437 token_info->SetString("service", consumer_id); |
431 | 438 |
432 std::string scopes_str; | 439 std::string scopes_str; |
433 for (OAuth2TokenService::ScopeSet::const_iterator it = scopes.begin(); | 440 for (OAuth2TokenService::ScopeSet::const_iterator it = scopes.begin(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) | 492 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) |
486 return tmp; | 493 return tmp; |
487 } | 494 } |
488 return NULL; | 495 return NULL; |
489 } | 496 } |
490 | 497 |
491 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( | 498 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( |
492 AccountTrackerService* account_tracker, | 499 AccountTrackerService* account_tracker, |
493 SigninManagerBase* signin_manager, | 500 SigninManagerBase* signin_manager, |
494 SigninErrorController* signin_error_controller, | 501 SigninErrorController* signin_error_controller, |
| 502 ProfileOAuth2TokenService* token_service, |
495 const std::string& product_version) { | 503 const std::string& product_version) { |
496 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 504 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
497 // fixed. | 505 // fixed. |
498 tracked_objects::ScopedTracker tracking_profile1( | 506 tracked_objects::ScopedTracker tracking_profile1( |
499 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 507 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
500 "422460 AboutSigninInternals::SigninStatus::ToValue1")); | 508 "422460 AboutSigninInternals::SigninStatus::ToValue1")); |
501 | 509 |
502 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); | 510 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); |
503 base::ListValue* signin_info = new base::ListValue(); | 511 base::ListValue* signin_info = new base::ListValue(); |
504 signin_status->Set("signin_info", signin_info); | 512 signin_status->Set("signin_info", signin_info); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 tracked_objects::ScopedTracker tracking_profile43( | 610 tracked_objects::ScopedTracker tracking_profile43( |
603 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 611 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
604 "422460 AboutSigninInternals::SigninStatus::ToValue43")); | 612 "422460 AboutSigninInternals::SigninStatus::ToValue43")); |
605 | 613 |
606 for (size_t i = 0; i < tokens.size(); ++i) { | 614 for (size_t i = 0; i < tokens.size(); ++i) { |
607 base::DictionaryValue* token_info = tokens[i]->ToValue(); | 615 base::DictionaryValue* token_info = tokens[i]->ToValue(); |
608 token_details->Append(token_info); | 616 token_details->Append(token_info); |
609 } | 617 } |
610 } | 618 } |
611 | 619 |
| 620 base::ListValue* account_info = new base::ListValue(); |
| 621 signin_status->Set("accountInfo", account_info); |
| 622 const std::vector<std::string>& accounts_in_token_service = |
| 623 token_service->GetAccounts(); |
| 624 |
| 625 if(accounts_in_token_service.size() == 0) { |
| 626 base::DictionaryValue* no_token_entry = new base::DictionaryValue(); |
| 627 no_token_entry->SetString("accountId", "No token in Token Service."); |
| 628 account_info->Append(no_token_entry); |
| 629 } |
| 630 |
| 631 for(const std::string& account_id : accounts_in_token_service) { |
| 632 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 633 entry->SetString("accountId", account_id); |
| 634 account_info->Append(entry); |
| 635 } |
| 636 |
612 return signin_status.Pass(); | 637 return signin_status.Pass(); |
613 } | 638 } |
OLD | NEW |