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 "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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 std::string time_pref = SigninStatusFieldToString(field) + ".time"; | 127 std::string time_pref = SigninStatusFieldToString(field) + ".time"; |
| 128 prefs->ClearPref(value_pref); | 128 prefs->ClearPref(value_pref); |
| 129 prefs->ClearPref(time_pref); | 129 prefs->ClearPref(time_pref); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // anonymous namespace | 132 } // anonymous namespace |
| 133 | 133 |
| 134 AboutSigninInternals::AboutSigninInternals( | 134 AboutSigninInternals::AboutSigninInternals( |
| 135 ProfileOAuth2TokenService* token_service, | 135 ProfileOAuth2TokenService* token_service, |
| 136 AccountTrackerService* account_tracker, | 136 AccountTrackerService* account_tracker, |
| 137 SigninManagerBase* signin_manager) | 137 SigninManagerBase* signin_manager, |
| 138 SigninErrorController* signin_error_controller) | |
| 138 : token_service_(token_service), | 139 : token_service_(token_service), |
| 139 account_tracker_(account_tracker), | 140 account_tracker_(account_tracker), |
| 140 signin_manager_(signin_manager), | 141 signin_manager_(signin_manager), |
| 141 client_(NULL) {} | 142 client_(NULL), |
| 143 signin_error_controller_(signin_error_controller) {} | |
| 142 | 144 |
| 143 AboutSigninInternals::~AboutSigninInternals() {} | 145 AboutSigninInternals::~AboutSigninInternals() {} |
| 144 | 146 |
| 145 void AboutSigninInternals::AddSigninObserver( | 147 void AboutSigninInternals::AddSigninObserver( |
| 146 AboutSigninInternals::Observer* observer) { | 148 AboutSigninInternals::Observer* observer) { |
| 147 signin_observers_.AddObserver(observer); | 149 signin_observers_.AddObserver(observer); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void AboutSigninInternals::RemoveSigninObserver( | 152 void AboutSigninInternals::RemoveSigninObserver( |
| 151 AboutSigninInternals::Observer* observer) { | 153 AboutSigninInternals::Observer* observer) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 208 |
| 207 RefreshSigninPrefs(); | 209 RefreshSigninPrefs(); |
| 208 | 210 |
| 209 signin_manager_->AddSigninDiagnosticsObserver(this); | 211 signin_manager_->AddSigninDiagnosticsObserver(this); |
| 210 token_service_->AddDiagnosticsObserver(this); | 212 token_service_->AddDiagnosticsObserver(this); |
| 211 cookie_changed_subscription_ = client_->AddCookieChangedCallback( | 213 cookie_changed_subscription_ = client_->AddCookieChangedCallback( |
| 212 GaiaUrls::GetInstance()->gaia_url(), | 214 GaiaUrls::GetInstance()->gaia_url(), |
| 213 "LSID", | 215 "LSID", |
| 214 base::Bind(&AboutSigninInternals::OnCookieChanged, | 216 base::Bind(&AboutSigninInternals::OnCookieChanged, |
| 215 base::Unretained(this))); | 217 base::Unretained(this))); |
| 218 signin_error_controller_->AddObserver(this); | |
| 216 } | 219 } |
| 217 | 220 |
| 218 void AboutSigninInternals::Shutdown() { | 221 void AboutSigninInternals::Shutdown() { |
| 219 signin_manager_->RemoveSigninDiagnosticsObserver(this); | 222 signin_manager_->RemoveSigninDiagnosticsObserver(this); |
| 220 token_service_->RemoveDiagnosticsObserver(this); | 223 token_service_->RemoveDiagnosticsObserver(this); |
| 221 cookie_changed_subscription_.reset(); | 224 cookie_changed_subscription_.reset(); |
|
Roger Tawa OOO till Jul 10th
2015/03/25 15:41:55
Remove observer here?
anthonyvd
2015/03/26 15:49:58
Done.
| |
| 222 } | 225 } |
| 223 | 226 |
| 224 void AboutSigninInternals::NotifyObservers() { | 227 void AboutSigninInternals::NotifyObservers() { |
| 225 if (!signin_observers_.might_have_observers()) | 228 if (!signin_observers_.might_have_observers()) |
| 226 return; | 229 return; |
| 227 | 230 |
| 228 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 231 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 229 // fixed. | 232 // fixed. |
| 230 tracked_objects::ScopedTracker tracking_profile( | 233 tracked_objects::ScopedTracker tracking_profile( |
| 231 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 234 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 232 "422460 AboutSigninInternals::NotifyObservers")); | 235 "422460 AboutSigninInternals::NotifyObservers")); |
| 233 | 236 |
| 234 const std::string product_version = client_->GetProductVersion(); | 237 const std::string product_version = client_->GetProductVersion(); |
| 235 | 238 |
| 236 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 239 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 237 // fixed. | 240 // fixed. |
| 238 tracked_objects::ScopedTracker tracking_profile05( | 241 tracked_objects::ScopedTracker tracking_profile05( |
| 239 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 242 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 240 "422460 AboutSigninInternals::NotifyObservers 0.5")); | 243 "422460 AboutSigninInternals::NotifyObservers 0.5")); |
| 241 | 244 |
| 242 scoped_ptr<base::DictionaryValue> signin_status_value = | 245 scoped_ptr<base::DictionaryValue> signin_status_value = |
| 243 signin_status_.ToValue(account_tracker_, signin_manager_, | 246 signin_status_.ToValue(account_tracker_, |
| 247 signin_manager_, | |
| 248 signin_error_controller_, | |
| 244 product_version); | 249 product_version); |
| 245 | 250 |
| 246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 251 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 247 // fixed. | 252 // fixed. |
| 248 tracked_objects::ScopedTracker tracking_profile1( | 253 tracked_objects::ScopedTracker tracking_profile1( |
| 249 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 254 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 250 "422460 AboutSigninInternals::NotifyObservers1")); | 255 "422460 AboutSigninInternals::NotifyObservers1")); |
| 251 | 256 |
| 252 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 257 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
| 253 signin_observers_, | 258 signin_observers_, |
| 254 OnSigninStateChanged(signin_status_value.get())); | 259 OnSigninStateChanged(signin_status_value.get())); |
| 255 } | 260 } |
| 256 | 261 |
| 257 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { | 262 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { |
| 258 return signin_status_.ToValue(account_tracker_, signin_manager_, | 263 return signin_status_.ToValue(account_tracker_, |
| 264 signin_manager_, | |
| 265 signin_error_controller_, | |
| 259 client_->GetProductVersion()).Pass(); | 266 client_->GetProductVersion()).Pass(); |
| 260 } | 267 } |
| 261 | 268 |
| 262 void AboutSigninInternals::OnAccessTokenRequested( | 269 void AboutSigninInternals::OnAccessTokenRequested( |
| 263 const std::string& account_id, | 270 const std::string& account_id, |
| 264 const std::string& consumer_id, | 271 const std::string& consumer_id, |
| 265 const OAuth2TokenService::ScopeSet& scopes) { | 272 const OAuth2TokenService::ScopeSet& scopes) { |
| 266 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 273 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 267 // fixed. | 274 // fixed. |
| 268 tracked_objects::ScopedTracker tracking_profile( | 275 tracked_objects::ScopedTracker tracking_profile( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 328 |
| 322 void AboutSigninInternals::OnCookieChanged(const net::CanonicalCookie& cookie, | 329 void AboutSigninInternals::OnCookieChanged(const net::CanonicalCookie& cookie, |
| 323 bool removed) { | 330 bool removed) { |
| 324 DCHECK_EQ("LSID", cookie.Name()); | 331 DCHECK_EQ("LSID", cookie.Name()); |
| 325 DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); | 332 DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); |
| 326 if (cookie.IsSecure() && cookie.IsHttpOnly()) { | 333 if (cookie.IsSecure() && cookie.IsHttpOnly()) { |
| 327 GetCookieAccountsAsync(); | 334 GetCookieAccountsAsync(); |
| 328 } | 335 } |
| 329 } | 336 } |
| 330 | 337 |
| 338 void AboutSigninInternals::OnErrorChanged() { | |
| 339 NotifyObservers(); | |
| 340 } | |
| 341 | |
| 331 void AboutSigninInternals::GetCookieAccountsAsync() { | 342 void AboutSigninInternals::GetCookieAccountsAsync() { |
| 332 // Don't bother calling /ListAccounts if no one will observe the response. | 343 // Don't bother calling /ListAccounts if no one will observe the response. |
| 333 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { | 344 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { |
| 334 // There is no list account request in flight. | 345 // There is no list account request in flight. |
| 335 gaia_fetcher_.reset(new GaiaAuthFetcher( | 346 gaia_fetcher_.reset(new GaiaAuthFetcher( |
| 336 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); | 347 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); |
| 337 gaia_fetcher_->StartListAccounts(); | 348 gaia_fetcher_->StartListAccounts(); |
| 338 } | 349 } |
| 339 } | 350 } |
| 340 | 351 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 TokenInfo* tmp = token_info_map[account_id][i]; | 483 TokenInfo* tmp = token_info_map[account_id][i]; |
| 473 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) | 484 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) |
| 474 return tmp; | 485 return tmp; |
| 475 } | 486 } |
| 476 return NULL; | 487 return NULL; |
| 477 } | 488 } |
| 478 | 489 |
| 479 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( | 490 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( |
| 480 AccountTrackerService* account_tracker, | 491 AccountTrackerService* account_tracker, |
| 481 SigninManagerBase* signin_manager, | 492 SigninManagerBase* signin_manager, |
| 493 SigninErrorController* signin_error_controller, | |
| 482 const std::string& product_version) { | 494 const std::string& product_version) { |
| 483 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 495 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 484 // fixed. | 496 // fixed. |
| 485 tracked_objects::ScopedTracker tracking_profile1( | 497 tracked_objects::ScopedTracker tracking_profile1( |
| 486 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 498 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 487 "422460 AboutSigninInternals::SigninStatus::ToValue1")); | 499 "422460 AboutSigninInternals::SigninStatus::ToValue1")); |
| 488 | 500 |
| 489 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); | 501 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); |
| 490 base::ListValue* signin_info = new base::ListValue(); | 502 base::ListValue* signin_info = new base::ListValue(); |
| 491 signin_status->Set("signin_info", signin_info); | 503 signin_status->Set("signin_info", signin_info); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 517 static_cast<UntimedSigninStatusField>(ACCOUNT_ID)), | 529 static_cast<UntimedSigninStatusField>(ACCOUNT_ID)), |
| 518 account_id); | 530 account_id); |
| 519 AddSectionEntry(basic_info, | 531 AddSectionEntry(basic_info, |
| 520 SigninStatusFieldToLabel( | 532 SigninStatusFieldToLabel( |
| 521 static_cast<UntimedSigninStatusField>(GAIA_ID)), | 533 static_cast<UntimedSigninStatusField>(GAIA_ID)), |
| 522 account_tracker->GetAccountInfo(account_id).gaia); | 534 account_tracker->GetAccountInfo(account_id).gaia); |
| 523 AddSectionEntry(basic_info, | 535 AddSectionEntry(basic_info, |
| 524 SigninStatusFieldToLabel( | 536 SigninStatusFieldToLabel( |
| 525 static_cast<UntimedSigninStatusField>(USERNAME)), | 537 static_cast<UntimedSigninStatusField>(USERNAME)), |
| 526 signin_manager->GetAuthenticatedUsername()); | 538 signin_manager->GetAuthenticatedUsername()); |
| 539 if (signin_error_controller->HasError()) { | |
| 540 AddSectionEntry(basic_info, "ErrorController Username", | |
| 541 signin_error_controller->error_username()); | |
| 542 AddSectionEntry(basic_info, "ErrorController Status", | |
| 543 signin_error_controller->auth_error().ToString()); | |
| 544 } | |
|
Roger Tawa OOO till Jul 10th
2015/03/25 15:41:55
If there is no auth error, maybe it should say:
anthonyvd
2015/03/26 15:49:58
Done. Makes sense to be consistent with Signin Sta
| |
| 527 } | 545 } |
| 528 | 546 |
| 529 #if !defined(OS_CHROMEOS) | 547 #if !defined(OS_CHROMEOS) |
| 530 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 548 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 531 // fixed. | 549 // fixed. |
| 532 tracked_objects::ScopedTracker tracking_profile3( | 550 tracked_objects::ScopedTracker tracking_profile3( |
| 533 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 551 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 534 "422460 AboutSigninInternals::SigninStatus::ToValue3")); | 552 "422460 AboutSigninInternals::SigninStatus::ToValue3")); |
| 535 | 553 |
| 536 // Time and status information of the possible sign in types. | 554 // Time and status information of the possible sign in types. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 "422460 AboutSigninInternals::SigninStatus::ToValue43")); | 601 "422460 AboutSigninInternals::SigninStatus::ToValue43")); |
| 584 | 602 |
| 585 for (size_t i = 0; i < tokens.size(); ++i) { | 603 for (size_t i = 0; i < tokens.size(); ++i) { |
| 586 base::DictionaryValue* token_info = tokens[i]->ToValue(); | 604 base::DictionaryValue* token_info = tokens[i]->ToValue(); |
| 587 token_details->Append(token_info); | 605 token_details->Append(token_info); |
| 588 } | 606 } |
| 589 } | 607 } |
| 590 | 608 |
| 591 return signin_status.Pass(); | 609 return signin_status.Pass(); |
| 592 } | 610 } |
| OLD | NEW |