| 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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/hash.h" | 9 #include "base/hash.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.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 "components/signin/core/browser/profile_oauth2_token_service.h" | 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 16 #include "components/signin/core/browser/signin_client.h" | 16 #include "components/signin/core/browser/signin_client.h" |
| 17 #include "components/signin/core/browser/signin_internals_util.h" | 17 #include "components/signin/core/browser/signin_internals_util.h" |
| 18 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
| 19 #include "components/signin/core/common/profile_management_switches.h" | 19 #include "components/signin/core/common/profile_management_switches.h" |
| 20 #include "components/signin/core/common/signin_switches.h" | 20 #include "components/signin/core/common/signin_switches.h" |
| 21 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 22 #include "google_apis/gaia/gaia_auth_util.h" |
| 21 #include "google_apis/gaia/gaia_constants.h" | 23 #include "google_apis/gaia/gaia_constants.h" |
| 24 #include "google_apis/gaia/gaia_urls.h" |
| 25 #include "net/cookies/canonical_cookie.h" |
| 22 | 26 |
| 23 using base::Time; | 27 using base::Time; |
| 24 using namespace signin_internals_util; | 28 using namespace signin_internals_util; |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 std::string GetTimeStr(base::Time time) { | 32 std::string GetTimeStr(base::Time time) { |
| 29 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time)); | 33 return base::UTF16ToUTF8(base::TimeFormatShortDateAndTime(time)); |
| 30 } | 34 } |
| 31 | 35 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 const std::string& field_name, | 48 const std::string& field_name, |
| 45 const std::string& field_status, | 49 const std::string& field_status, |
| 46 const std::string& field_time = "") { | 50 const std::string& field_time = "") { |
| 47 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); | 51 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); |
| 48 entry->SetString("label", field_name); | 52 entry->SetString("label", field_name); |
| 49 entry->SetString("status", field_status); | 53 entry->SetString("status", field_status); |
| 50 entry->SetString("time", field_time); | 54 entry->SetString("time", field_time); |
| 51 section_list->Append(entry.release()); | 55 section_list->Append(entry.release()); |
| 52 } | 56 } |
| 53 | 57 |
| 58 void AddCookieEntry(base::ListValue* accounts_list, |
| 59 const std::string& field_email, |
| 60 const std::string& field_valid) { |
| 61 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue()); |
| 62 entry->SetString("email", field_email); |
| 63 entry->SetString("valid", field_valid); |
| 64 accounts_list->Append(entry.release()); |
| 65 } |
| 66 |
| 54 std::string SigninStatusFieldToLabel(UntimedSigninStatusField field) { | 67 std::string SigninStatusFieldToLabel(UntimedSigninStatusField field) { |
| 55 switch (field) { | 68 switch (field) { |
| 56 case USERNAME: | 69 case USERNAME: |
| 57 return "User Id"; | 70 return "User Id"; |
| 58 case UNTIMED_FIELDS_END: | 71 case UNTIMED_FIELDS_END: |
| 59 NOTREACHED(); | 72 NOTREACHED(); |
| 60 return std::string(); | 73 return std::string(); |
| 61 } | 74 } |
| 62 NOTREACHED(); | 75 NOTREACHED(); |
| 63 return std::string(); | 76 return std::string(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 201 } |
| 189 | 202 |
| 190 void AboutSigninInternals::Initialize(SigninClient* client) { | 203 void AboutSigninInternals::Initialize(SigninClient* client) { |
| 191 DCHECK(!client_); | 204 DCHECK(!client_); |
| 192 client_ = client; | 205 client_ = client; |
| 193 | 206 |
| 194 RefreshSigninPrefs(); | 207 RefreshSigninPrefs(); |
| 195 | 208 |
| 196 signin_manager_->AddSigninDiagnosticsObserver(this); | 209 signin_manager_->AddSigninDiagnosticsObserver(this); |
| 197 token_service_->AddDiagnosticsObserver(this); | 210 token_service_->AddDiagnosticsObserver(this); |
| 211 cookie_changed_subscription_ = client_->AddCookieChangedCallback( |
| 212 base::Bind(&AboutSigninInternals::OnCookieChanged, |
| 213 base::Unretained(this))); |
| 198 } | 214 } |
| 199 | 215 |
| 200 void AboutSigninInternals::Shutdown() { | 216 void AboutSigninInternals::Shutdown() { |
| 201 signin_manager_->RemoveSigninDiagnosticsObserver(this); | 217 signin_manager_->RemoveSigninDiagnosticsObserver(this); |
| 202 token_service_->RemoveDiagnosticsObserver(this); | 218 token_service_->RemoveDiagnosticsObserver(this); |
| 219 cookie_changed_subscription_.reset(); |
| 203 } | 220 } |
| 204 | 221 |
| 205 void AboutSigninInternals::NotifyObservers() { | 222 void AboutSigninInternals::NotifyObservers() { |
| 206 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 223 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
| 207 signin_observers_, | 224 signin_observers_, |
| 208 OnSigninStateChanged( | 225 OnSigninStateChanged( |
| 209 signin_status_.ToValue(client_->GetProductVersion()))); | 226 signin_status_.ToValue(client_->GetProductVersion()))); |
| 210 } | 227 } |
| 211 | 228 |
| 212 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { | 229 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 277 } |
| 261 | 278 |
| 262 void AboutSigninInternals::OnRefreshTokenReceived(std::string status) { | 279 void AboutSigninInternals::OnRefreshTokenReceived(std::string status) { |
| 263 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); | 280 NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status); |
| 264 } | 281 } |
| 265 | 282 |
| 266 void AboutSigninInternals::OnAuthenticationResultReceived(std::string status) { | 283 void AboutSigninInternals::OnAuthenticationResultReceived(std::string status) { |
| 267 NotifySigninValueChanged(AUTHENTICATION_RESULT_RECEIVED, status); | 284 NotifySigninValueChanged(AUTHENTICATION_RESULT_RECEIVED, status); |
| 268 } | 285 } |
| 269 | 286 |
| 287 void AboutSigninInternals::OnCookieChanged( |
| 288 const net::CanonicalCookie* cookie) { |
| 289 if (cookie->Name() == "LSID" && |
| 290 cookie->Domain() == GaiaUrls::GetInstance()->gaia_url().host() && |
| 291 cookie->IsSecure() && |
| 292 cookie->IsHttpOnly()) { |
| 293 GetCookieAccountsAsync(); |
| 294 } |
| 295 } |
| 296 |
| 297 void AboutSigninInternals::GetCookieAccountsAsync() { |
| 298 if (!gaia_fetcher_) { |
| 299 // There is no list account request in flight. |
| 300 gaia_fetcher_.reset(new GaiaAuthFetcher( |
| 301 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); |
| 302 gaia_fetcher_->StartListAccounts(); |
| 303 } |
| 304 } |
| 305 |
| 306 void AboutSigninInternals::OnListAccountsSuccess(const std::string& data) { |
| 307 gaia_fetcher_.reset(); |
| 308 |
| 309 // Get account information from response data. |
| 310 std::vector<std::pair<std::string, bool> > gaia_accounts; |
| 311 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); |
| 312 if (!valid_json) { |
| 313 VLOG(1) << "AboutSigninInternals::OnListAccountsSuccess: parsing error"; |
| 314 } else { |
| 315 OnListAccountsComplete(gaia_accounts); |
| 316 } |
| 317 } |
| 318 |
| 319 void AboutSigninInternals::OnListAccountsFailure( |
| 320 const GoogleServiceAuthError& error) { |
| 321 gaia_fetcher_.reset(); |
| 322 VLOG(1) << "AboutSigninInternals::OnListAccountsFailure:" << error.ToString(); |
| 323 } |
| 324 |
| 325 void AboutSigninInternals::OnListAccountsComplete( |
| 326 std::vector<std::pair<std::string, bool> >& gaia_accounts) { |
| 327 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); |
| 328 base::ListValue* cookie_info = new base::ListValue(); |
| 329 signin_status->Set("cookie_info", cookie_info); |
| 330 |
| 331 for (size_t i = 0; i < gaia_accounts.size(); ++i) { |
| 332 AddCookieEntry(cookie_info, |
| 333 gaia_accounts[i].first, |
| 334 gaia_accounts[i].second ? "Valid" : "Invalid"); |
| 335 } |
| 336 |
| 337 if (gaia_accounts.size() == 0) |
| 338 AddCookieEntry(cookie_info, "No Accounts Present.", ""); |
| 339 |
| 340 // Update the observers that the cookie's accounts are updated. |
| 341 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
| 342 signin_observers_, |
| 343 OnCookieAccountsFetched(signin_status.Pass())); |
| 344 } |
| 345 |
| 270 AboutSigninInternals::TokenInfo::TokenInfo( | 346 AboutSigninInternals::TokenInfo::TokenInfo( |
| 271 const std::string& consumer_id, | 347 const std::string& consumer_id, |
| 272 const OAuth2TokenService::ScopeSet& scopes) | 348 const OAuth2TokenService::ScopeSet& scopes) |
| 273 : consumer_id(consumer_id), | 349 : consumer_id(consumer_id), |
| 274 scopes(scopes), | 350 scopes(scopes), |
| 275 request_time(base::Time::Now()), | 351 request_time(base::Time::Now()), |
| 276 error(GoogleServiceAuthError::AuthErrorNone()), | 352 error(GoogleServiceAuthError::AuthErrorNone()), |
| 277 removed_(false) {} | 353 removed_(false) {} |
| 278 | 354 |
| 279 AboutSigninInternals::TokenInfo::~TokenInfo() {} | 355 AboutSigninInternals::TokenInfo::~TokenInfo() {} |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); | 481 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); |
| 406 const std::vector<TokenInfo*>& tokens = it->second; | 482 const std::vector<TokenInfo*>& tokens = it->second; |
| 407 for (size_t i = 0; i < tokens.size(); ++i) { | 483 for (size_t i = 0; i < tokens.size(); ++i) { |
| 408 base::DictionaryValue* token_info = tokens[i]->ToValue(); | 484 base::DictionaryValue* token_info = tokens[i]->ToValue(); |
| 409 token_details->Append(token_info); | 485 token_details->Append(token_info); |
| 410 } | 486 } |
| 411 } | 487 } |
| 412 | 488 |
| 413 return signin_status.Pass(); | 489 return signin_status.Pass(); |
| 414 } | 490 } |
| OLD | NEW |