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