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" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 base::Unretained(this))); | 213 base::Unretained(this))); |
214 } | 214 } |
215 | 215 |
216 void AboutSigninInternals::Shutdown() { | 216 void AboutSigninInternals::Shutdown() { |
217 signin_manager_->RemoveSigninDiagnosticsObserver(this); | 217 signin_manager_->RemoveSigninDiagnosticsObserver(this); |
218 token_service_->RemoveDiagnosticsObserver(this); | 218 token_service_->RemoveDiagnosticsObserver(this); |
219 cookie_changed_subscription_.reset(); | 219 cookie_changed_subscription_.reset(); |
220 } | 220 } |
221 | 221 |
222 void AboutSigninInternals::NotifyObservers() { | 222 void AboutSigninInternals::NotifyObservers() { |
| 223 scoped_ptr<base::DictionaryValue> signin_status_value = |
| 224 signin_status_.ToValue(client_->GetProductVersion()); |
223 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 225 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
224 signin_observers_, | 226 signin_observers_, |
225 OnSigninStateChanged( | 227 OnSigninStateChanged(signin_status_value.get())); |
226 signin_status_.ToValue(client_->GetProductVersion()))); | |
227 } | 228 } |
228 | 229 |
229 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { | 230 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { |
230 return signin_status_.ToValue(client_->GetProductVersion()).Pass(); | 231 return signin_status_.ToValue(client_->GetProductVersion()).Pass(); |
231 } | 232 } |
232 | 233 |
233 void AboutSigninInternals::OnAccessTokenRequested( | 234 void AboutSigninInternals::OnAccessTokenRequested( |
234 const std::string& account_id, | 235 const std::string& account_id, |
235 const std::string& consumer_id, | 236 const std::string& consumer_id, |
236 const OAuth2TokenService::ScopeSet& scopes) { | 237 const OAuth2TokenService::ScopeSet& scopes) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 const net::CanonicalCookie* cookie) { | 289 const net::CanonicalCookie* cookie) { |
289 if (cookie->Name() == "LSID" && | 290 if (cookie->Name() == "LSID" && |
290 cookie->Domain() == GaiaUrls::GetInstance()->gaia_url().host() && | 291 cookie->Domain() == GaiaUrls::GetInstance()->gaia_url().host() && |
291 cookie->IsSecure() && | 292 cookie->IsSecure() && |
292 cookie->IsHttpOnly()) { | 293 cookie->IsHttpOnly()) { |
293 GetCookieAccountsAsync(); | 294 GetCookieAccountsAsync(); |
294 } | 295 } |
295 } | 296 } |
296 | 297 |
297 void AboutSigninInternals::GetCookieAccountsAsync() { | 298 void AboutSigninInternals::GetCookieAccountsAsync() { |
298 if (!gaia_fetcher_) { | 299 // Don't bother calling /ListAccounts if no one will observe the response. |
| 300 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { |
299 // There is no list account request in flight. | 301 // There is no list account request in flight. |
300 gaia_fetcher_.reset(new GaiaAuthFetcher( | 302 gaia_fetcher_.reset(new GaiaAuthFetcher( |
301 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); | 303 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); |
302 gaia_fetcher_->StartListAccounts(); | 304 gaia_fetcher_->StartListAccounts(); |
303 } | 305 } |
304 } | 306 } |
305 | 307 |
306 void AboutSigninInternals::OnListAccountsSuccess(const std::string& data) { | 308 void AboutSigninInternals::OnListAccountsSuccess(const std::string& data) { |
307 gaia_fetcher_.reset(); | 309 gaia_fetcher_.reset(); |
308 | 310 |
309 // Get account information from response data. | 311 // Get account information from response data. |
310 std::vector<std::pair<std::string, bool> > gaia_accounts; | 312 std::vector<std::pair<std::string, bool> > gaia_accounts; |
311 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); | 313 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); |
312 if (!valid_json) { | 314 if (!valid_json) { |
313 VLOG(1) << "AboutSigninInternals::OnListAccountsSuccess: parsing error"; | 315 VLOG(1) << "AboutSigninInternals::OnListAccountsSuccess: parsing error"; |
314 } else { | 316 } else { |
315 OnListAccountsComplete(gaia_accounts); | 317 OnListAccountsComplete(gaia_accounts); |
316 } | 318 } |
317 } | 319 } |
318 | 320 |
319 void AboutSigninInternals::OnListAccountsFailure( | 321 void AboutSigninInternals::OnListAccountsFailure( |
320 const GoogleServiceAuthError& error) { | 322 const GoogleServiceAuthError& error) { |
321 gaia_fetcher_.reset(); | 323 gaia_fetcher_.reset(); |
322 VLOG(1) << "AboutSigninInternals::OnListAccountsFailure:" << error.ToString(); | 324 VLOG(1) << "AboutSigninInternals::OnListAccountsFailure:" << error.ToString(); |
323 } | 325 } |
324 | 326 |
325 void AboutSigninInternals::OnListAccountsComplete( | 327 void AboutSigninInternals::OnListAccountsComplete( |
326 std::vector<std::pair<std::string, bool> >& gaia_accounts) { | 328 std::vector<std::pair<std::string, bool> >& gaia_accounts) { |
327 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); | 329 base::DictionaryValue signin_status; |
328 base::ListValue* cookie_info = new base::ListValue(); | 330 base::ListValue* cookie_info = new base::ListValue(); |
329 signin_status->Set("cookie_info", cookie_info); | 331 signin_status.Set("cookie_info", cookie_info); |
330 | 332 |
331 for (size_t i = 0; i < gaia_accounts.size(); ++i) { | 333 for (size_t i = 0; i < gaia_accounts.size(); ++i) { |
332 AddCookieEntry(cookie_info, | 334 AddCookieEntry(cookie_info, |
333 gaia_accounts[i].first, | 335 gaia_accounts[i].first, |
334 gaia_accounts[i].second ? "Valid" : "Invalid"); | 336 gaia_accounts[i].second ? "Valid" : "Invalid"); |
335 } | 337 } |
336 | 338 |
337 if (gaia_accounts.size() == 0) | 339 if (gaia_accounts.size() == 0) |
338 AddCookieEntry(cookie_info, "No Accounts Present.", ""); | 340 AddCookieEntry(cookie_info, "No Accounts Present.", ""); |
339 | 341 |
340 // Update the observers that the cookie's accounts are updated. | 342 // Update the observers that the cookie's accounts are updated. |
341 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 343 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
342 signin_observers_, | 344 signin_observers_, |
343 OnCookieAccountsFetched(signin_status.Pass())); | 345 OnCookieAccountsFetched(&signin_status)); |
344 } | 346 } |
345 | 347 |
346 AboutSigninInternals::TokenInfo::TokenInfo( | 348 AboutSigninInternals::TokenInfo::TokenInfo( |
347 const std::string& consumer_id, | 349 const std::string& consumer_id, |
348 const OAuth2TokenService::ScopeSet& scopes) | 350 const OAuth2TokenService::ScopeSet& scopes) |
349 : consumer_id(consumer_id), | 351 : consumer_id(consumer_id), |
350 scopes(scopes), | 352 scopes(scopes), |
351 request_time(base::Time::Now()), | 353 request_time(base::Time::Now()), |
352 error(GoogleServiceAuthError::AuthErrorNone()), | 354 error(GoogleServiceAuthError::AuthErrorNone()), |
353 removed_(false) {} | 355 removed_(false) {} |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); | 483 std::sort(it->second.begin(), it->second.end(), TokenInfo::LessThan); |
482 const std::vector<TokenInfo*>& tokens = it->second; | 484 const std::vector<TokenInfo*>& tokens = it->second; |
483 for (size_t i = 0; i < tokens.size(); ++i) { | 485 for (size_t i = 0; i < tokens.size(); ++i) { |
484 base::DictionaryValue* token_info = tokens[i]->ToValue(); | 486 base::DictionaryValue* token_info = tokens[i]->ToValue(); |
485 token_details->Append(token_info); | 487 token_details->Append(token_info); |
486 } | 488 } |
487 } | 489 } |
488 | 490 |
489 return signin_status.Pass(); | 491 return signin_status.Pass(); |
490 } | 492 } |
OLD | NEW |