| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "components/signin/core/browser/account_tracker_service.h" | 16 #include "components/signin/core/browser/account_tracker_service.h" |
| 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 18 #include "components/signin/core/browser/signin_client.h" | 18 #include "components/signin/core/browser/signin_client.h" |
| 19 #include "components/signin/core/browser/signin_internals_util.h" | 19 #include "components/signin/core/browser/signin_internals_util.h" |
| 20 #include "components/signin/core/browser/signin_manager.h" | 20 #include "components/signin/core/browser/signin_manager.h" |
| 21 #include "components/signin/core/common/profile_management_switches.h" | 21 #include "components/signin/core/common/profile_management_switches.h" |
| 22 #include "components/signin/core/common/signin_switches.h" | 22 #include "components/signin/core/common/signin_switches.h" |
| 23 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | |
| 25 #include "google_apis/gaia/gaia_constants.h" | |
| 26 #include "google_apis/gaia/gaia_urls.h" | |
| 27 #include "net/cookies/canonical_cookie.h" | |
| 28 | 23 |
| 29 using base::Time; | 24 using base::Time; |
| 30 using namespace signin_internals_util; | 25 using namespace signin_internals_util; |
| 31 | 26 |
| 32 namespace { | 27 namespace { |
| 33 | 28 |
| 34 std::string GetTimeStr(base::Time time) { | 29 std::string GetTimeStr(base::Time time) { |
| 35 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time)); | 30 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time)); |
| 36 } | 31 } |
| 37 | 32 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 prefs->ClearPref(value_pref); | 123 prefs->ClearPref(value_pref); |
| 129 prefs->ClearPref(time_pref); | 124 prefs->ClearPref(time_pref); |
| 130 } | 125 } |
| 131 | 126 |
| 132 } // anonymous namespace | 127 } // anonymous namespace |
| 133 | 128 |
| 134 AboutSigninInternals::AboutSigninInternals( | 129 AboutSigninInternals::AboutSigninInternals( |
| 135 ProfileOAuth2TokenService* token_service, | 130 ProfileOAuth2TokenService* token_service, |
| 136 AccountTrackerService* account_tracker, | 131 AccountTrackerService* account_tracker, |
| 137 SigninManagerBase* signin_manager, | 132 SigninManagerBase* signin_manager, |
| 138 SigninErrorController* signin_error_controller) | 133 SigninErrorController* signin_error_controller, |
| 134 GaiaCookieManagerService* cookie_manager_service) |
| 139 : token_service_(token_service), | 135 : token_service_(token_service), |
| 140 account_tracker_(account_tracker), | 136 account_tracker_(account_tracker), |
| 141 signin_manager_(signin_manager), | 137 signin_manager_(signin_manager), |
| 142 client_(NULL), | 138 client_(NULL), |
| 143 signin_error_controller_(signin_error_controller) {} | 139 signin_error_controller_(signin_error_controller), |
| 140 cookie_manager_service_(cookie_manager_service) {} |
| 144 | 141 |
| 145 AboutSigninInternals::~AboutSigninInternals() {} | 142 AboutSigninInternals::~AboutSigninInternals() {} |
| 146 | 143 |
| 147 void AboutSigninInternals::AddSigninObserver( | 144 void AboutSigninInternals::AddSigninObserver( |
| 148 AboutSigninInternals::Observer* observer) { | 145 AboutSigninInternals::Observer* observer) { |
| 149 signin_observers_.AddObserver(observer); | 146 signin_observers_.AddObserver(observer); |
| 150 } | 147 } |
| 151 | 148 |
| 152 void AboutSigninInternals::RemoveSigninObserver( | 149 void AboutSigninInternals::RemoveSigninObserver( |
| 153 AboutSigninInternals::Observer* observer) { | 150 AboutSigninInternals::Observer* observer) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 201 |
| 205 void AboutSigninInternals::Initialize(SigninClient* client) { | 202 void AboutSigninInternals::Initialize(SigninClient* client) { |
| 206 DCHECK(!client_); | 203 DCHECK(!client_); |
| 207 client_ = client; | 204 client_ = client; |
| 208 | 205 |
| 209 RefreshSigninPrefs(); | 206 RefreshSigninPrefs(); |
| 210 | 207 |
| 211 signin_error_controller_->AddObserver(this); | 208 signin_error_controller_->AddObserver(this); |
| 212 signin_manager_->AddSigninDiagnosticsObserver(this); | 209 signin_manager_->AddSigninDiagnosticsObserver(this); |
| 213 token_service_->AddDiagnosticsObserver(this); | 210 token_service_->AddDiagnosticsObserver(this); |
| 214 cookie_changed_subscription_ = client_->AddCookieChangedCallback( | 211 cookie_manager_service_->AddObserver(this); |
| 215 GaiaUrls::GetInstance()->gaia_url(), | |
| 216 "LSID", | |
| 217 base::Bind(&AboutSigninInternals::OnCookieChanged, | |
| 218 base::Unretained(this))); | |
| 219 } | 212 } |
| 220 | 213 |
| 221 void AboutSigninInternals::Shutdown() { | 214 void AboutSigninInternals::Shutdown() { |
| 222 signin_error_controller_->RemoveObserver(this); | 215 signin_error_controller_->RemoveObserver(this); |
| 223 signin_manager_->RemoveSigninDiagnosticsObserver(this); | 216 signin_manager_->RemoveSigninDiagnosticsObserver(this); |
| 224 token_service_->RemoveDiagnosticsObserver(this); | 217 token_service_->RemoveDiagnosticsObserver(this); |
| 225 cookie_changed_subscription_.reset(); | 218 cookie_manager_service_->RemoveObserver(this); |
| 226 } | 219 } |
| 227 | 220 |
| 228 void AboutSigninInternals::NotifyObservers() { | 221 void AboutSigninInternals::NotifyObservers() { |
| 229 if (!signin_observers_.might_have_observers()) | 222 if (!signin_observers_.might_have_observers()) |
| 230 return; | 223 return; |
| 231 | 224 |
| 232 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 225 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 233 // fixed. | 226 // fixed. |
| 234 tracked_objects::ScopedTracker tracking_profile( | 227 tracked_objects::ScopedTracker tracking_profile( |
| 235 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 228 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 315 } |
| 323 | 316 |
| 324 void AboutSigninInternals::OnRefreshTokenReceived(std::string status) { | 317 void AboutSigninInternals::OnRefreshTokenReceived(std::string status) { |
| 325 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); | 318 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); |
| 326 } | 319 } |
| 327 | 320 |
| 328 void AboutSigninInternals::OnAuthenticationResultReceived(std::string status) { | 321 void AboutSigninInternals::OnAuthenticationResultReceived(std::string status) { |
| 329 NotifySigninValueChanged(AUTHENTICATION_RESULT_RECEIVED, status); | 322 NotifySigninValueChanged(AUTHENTICATION_RESULT_RECEIVED, status); |
| 330 } | 323 } |
| 331 | 324 |
| 332 void AboutSigninInternals::OnCookieChanged(const net::CanonicalCookie& cookie, | |
| 333 bool removed) { | |
| 334 DCHECK_EQ("LSID", cookie.Name()); | |
| 335 DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); | |
| 336 if (cookie.IsSecure() && cookie.IsHttpOnly()) { | |
| 337 GetCookieAccountsAsync(); | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 void AboutSigninInternals::OnErrorChanged() { | 325 void AboutSigninInternals::OnErrorChanged() { |
| 342 NotifyObservers(); | 326 NotifyObservers(); |
| 343 } | 327 } |
| 344 | 328 |
| 345 void AboutSigninInternals::GetCookieAccountsAsync() { | |
| 346 // Don't bother calling /ListAccounts if no one will observe the response. | |
| 347 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { | |
| 348 // There is no list account request in flight. | |
| 349 gaia_fetcher_.reset(new GaiaAuthFetcher( | |
| 350 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); | |
| 351 gaia_fetcher_->StartListAccounts(); | |
| 352 } | |
| 353 } | |
| 354 | |
| 355 void AboutSigninInternals::OnListAccountsSuccess(const std::string& data) { | |
| 356 gaia_fetcher_.reset(); | |
| 357 | |
| 358 // Get account information from response data. | |
| 359 std::vector<std::pair<std::string, bool> > gaia_accounts; | |
| 360 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); | |
| 361 if (!valid_json) { | |
| 362 VLOG(1) << "AboutSigninInternals::OnListAccountsSuccess: parsing error"; | |
| 363 } else { | |
| 364 OnListAccountsComplete(gaia_accounts); | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 void AboutSigninInternals::OnListAccountsFailure( | |
| 369 const GoogleServiceAuthError& error) { | |
| 370 gaia_fetcher_.reset(); | |
| 371 VLOG(1) << "AboutSigninInternals::OnListAccountsFailure:" << error.ToString(); | |
| 372 } | |
| 373 | |
| 374 void AboutSigninInternals::GoogleSigninFailed( | 329 void AboutSigninInternals::GoogleSigninFailed( |
| 375 const GoogleServiceAuthError& error) { | 330 const GoogleServiceAuthError& error) { |
| 376 NotifyObservers(); | 331 NotifyObservers(); |
| 377 } | 332 } |
| 378 | 333 |
| 379 void AboutSigninInternals::GoogleSigninSucceeded(const std::string& account_id, | 334 void AboutSigninInternals::GoogleSigninSucceeded(const std::string& account_id, |
| 380 const std::string& username, | 335 const std::string& username, |
| 381 const std::string& password) { | 336 const std::string& password) { |
| 382 NotifyObservers(); | 337 NotifyObservers(); |
| 383 } | 338 } |
| 384 | 339 |
| 385 void AboutSigninInternals::GoogleSignedOut(const std::string& account_id, | 340 void AboutSigninInternals::GoogleSignedOut(const std::string& account_id, |
| 386 const std::string& username) { | 341 const std::string& username) { |
| 387 NotifyObservers(); | 342 NotifyObservers(); |
| 388 } | 343 } |
| 389 | 344 |
| 390 void AboutSigninInternals::OnListAccountsComplete( | 345 void AboutSigninInternals::OnGaiaAccountsInCookieUpdated( |
| 391 std::vector<std::pair<std::string, bool> >& gaia_accounts) { | 346 const std::vector<std::pair<std::string, bool> >& gaia_accounts, |
| 347 const GoogleServiceAuthError& error) { |
| 348 if (error.state() != GoogleServiceAuthError::NONE) |
| 349 return; |
| 350 |
| 392 base::DictionaryValue cookie_status; | 351 base::DictionaryValue cookie_status; |
| 393 base::ListValue* cookie_info = new base::ListValue(); | 352 base::ListValue* cookie_info = new base::ListValue(); |
| 394 cookie_status.Set("cookie_info", cookie_info); | 353 cookie_status.Set("cookie_info", cookie_info); |
| 395 | 354 |
| 396 for (size_t i = 0; i < gaia_accounts.size(); ++i) { | 355 for (size_t i = 0; i < gaia_accounts.size(); ++i) { |
| 397 AddCookieEntry(cookie_info, | 356 AddCookieEntry(cookie_info, |
| 398 gaia_accounts[i].first, | 357 gaia_accounts[i].first, |
| 399 gaia_accounts[i].second ? "Valid" : "Invalid"); | 358 gaia_accounts[i].second ? "Valid" : "Invalid"); |
| 400 } | 359 } |
| 401 | 360 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 } | 588 } |
| 630 | 589 |
| 631 for(const std::string& account_id : accounts_in_token_service) { | 590 for(const std::string& account_id : accounts_in_token_service) { |
| 632 base::DictionaryValue* entry = new base::DictionaryValue(); | 591 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 633 entry->SetString("accountId", account_id); | 592 entry->SetString("accountId", account_id); |
| 634 account_info->Append(entry); | 593 account_info->Append(entry); |
| 635 } | 594 } |
| 636 | 595 |
| 637 return signin_status.Pass(); | 596 return signin_status.Pass(); |
| 638 } | 597 } |
| OLD | NEW |