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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 201 |
200 NotifyObservers(); | 202 NotifyObservers(); |
201 } | 203 } |
202 | 204 |
203 void AboutSigninInternals::Initialize(SigninClient* client) { | 205 void AboutSigninInternals::Initialize(SigninClient* client) { |
204 DCHECK(!client_); | 206 DCHECK(!client_); |
205 client_ = client; | 207 client_ = client; |
206 | 208 |
207 RefreshSigninPrefs(); | 209 RefreshSigninPrefs(); |
208 | 210 |
| 211 signin_error_controller_->AddObserver(this); |
209 signin_manager_->AddSigninDiagnosticsObserver(this); | 212 signin_manager_->AddSigninDiagnosticsObserver(this); |
210 token_service_->AddDiagnosticsObserver(this); | 213 token_service_->AddDiagnosticsObserver(this); |
211 cookie_changed_subscription_ = client_->AddCookieChangedCallback( | 214 cookie_changed_subscription_ = client_->AddCookieChangedCallback( |
212 GaiaUrls::GetInstance()->gaia_url(), | 215 GaiaUrls::GetInstance()->gaia_url(), |
213 "LSID", | 216 "LSID", |
214 base::Bind(&AboutSigninInternals::OnCookieChanged, | 217 base::Bind(&AboutSigninInternals::OnCookieChanged, |
215 base::Unretained(this))); | 218 base::Unretained(this))); |
216 } | 219 } |
217 | 220 |
218 void AboutSigninInternals::Shutdown() { | 221 void AboutSigninInternals::Shutdown() { |
| 222 signin_error_controller_->RemoveObserver(this); |
219 signin_manager_->RemoveSigninDiagnosticsObserver(this); | 223 signin_manager_->RemoveSigninDiagnosticsObserver(this); |
220 token_service_->RemoveDiagnosticsObserver(this); | 224 token_service_->RemoveDiagnosticsObserver(this); |
221 cookie_changed_subscription_.reset(); | 225 cookie_changed_subscription_.reset(); |
222 } | 226 } |
223 | 227 |
224 void AboutSigninInternals::NotifyObservers() { | 228 void AboutSigninInternals::NotifyObservers() { |
225 if (!signin_observers_.might_have_observers()) | 229 if (!signin_observers_.might_have_observers()) |
226 return; | 230 return; |
227 | 231 |
228 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 232 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
229 // fixed. | 233 // fixed. |
230 tracked_objects::ScopedTracker tracking_profile( | 234 tracked_objects::ScopedTracker tracking_profile( |
231 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 235 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
232 "422460 AboutSigninInternals::NotifyObservers")); | 236 "422460 AboutSigninInternals::NotifyObservers")); |
233 | 237 |
234 const std::string product_version = client_->GetProductVersion(); | 238 const std::string product_version = client_->GetProductVersion(); |
235 | 239 |
236 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 240 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
237 // fixed. | 241 // fixed. |
238 tracked_objects::ScopedTracker tracking_profile05( | 242 tracked_objects::ScopedTracker tracking_profile05( |
239 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 243 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
240 "422460 AboutSigninInternals::NotifyObservers 0.5")); | 244 "422460 AboutSigninInternals::NotifyObservers 0.5")); |
241 | 245 |
242 scoped_ptr<base::DictionaryValue> signin_status_value = | 246 scoped_ptr<base::DictionaryValue> signin_status_value = |
243 signin_status_.ToValue(account_tracker_, signin_manager_, | 247 signin_status_.ToValue(account_tracker_, |
| 248 signin_manager_, |
| 249 signin_error_controller_, |
244 product_version); | 250 product_version); |
245 | 251 |
246 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 252 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
247 // fixed. | 253 // fixed. |
248 tracked_objects::ScopedTracker tracking_profile1( | 254 tracked_objects::ScopedTracker tracking_profile1( |
249 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 255 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
250 "422460 AboutSigninInternals::NotifyObservers1")); | 256 "422460 AboutSigninInternals::NotifyObservers1")); |
251 | 257 |
252 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, | 258 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, |
253 signin_observers_, | 259 signin_observers_, |
254 OnSigninStateChanged(signin_status_value.get())); | 260 OnSigninStateChanged(signin_status_value.get())); |
255 } | 261 } |
256 | 262 |
257 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { | 263 scoped_ptr<base::DictionaryValue> AboutSigninInternals::GetSigninStatus() { |
258 return signin_status_.ToValue(account_tracker_, signin_manager_, | 264 return signin_status_.ToValue(account_tracker_, |
| 265 signin_manager_, |
| 266 signin_error_controller_, |
259 client_->GetProductVersion()).Pass(); | 267 client_->GetProductVersion()).Pass(); |
260 } | 268 } |
261 | 269 |
262 void AboutSigninInternals::OnAccessTokenRequested( | 270 void AboutSigninInternals::OnAccessTokenRequested( |
263 const std::string& account_id, | 271 const std::string& account_id, |
264 const std::string& consumer_id, | 272 const std::string& consumer_id, |
265 const OAuth2TokenService::ScopeSet& scopes) { | 273 const OAuth2TokenService::ScopeSet& scopes) { |
266 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 274 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
267 // fixed. | 275 // fixed. |
268 tracked_objects::ScopedTracker tracking_profile( | 276 tracked_objects::ScopedTracker tracking_profile( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 329 |
322 void AboutSigninInternals::OnCookieChanged(const net::CanonicalCookie& cookie, | 330 void AboutSigninInternals::OnCookieChanged(const net::CanonicalCookie& cookie, |
323 bool removed) { | 331 bool removed) { |
324 DCHECK_EQ("LSID", cookie.Name()); | 332 DCHECK_EQ("LSID", cookie.Name()); |
325 DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); | 333 DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); |
326 if (cookie.IsSecure() && cookie.IsHttpOnly()) { | 334 if (cookie.IsSecure() && cookie.IsHttpOnly()) { |
327 GetCookieAccountsAsync(); | 335 GetCookieAccountsAsync(); |
328 } | 336 } |
329 } | 337 } |
330 | 338 |
| 339 void AboutSigninInternals::OnErrorChanged() { |
| 340 NotifyObservers(); |
| 341 } |
| 342 |
331 void AboutSigninInternals::GetCookieAccountsAsync() { | 343 void AboutSigninInternals::GetCookieAccountsAsync() { |
332 // Don't bother calling /ListAccounts if no one will observe the response. | 344 // Don't bother calling /ListAccounts if no one will observe the response. |
333 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { | 345 if (!gaia_fetcher_ && signin_observers_.might_have_observers()) { |
334 // There is no list account request in flight. | 346 // There is no list account request in flight. |
335 gaia_fetcher_.reset(new GaiaAuthFetcher( | 347 gaia_fetcher_.reset(new GaiaAuthFetcher( |
336 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); | 348 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); |
337 gaia_fetcher_->StartListAccounts(); | 349 gaia_fetcher_->StartListAccounts(); |
338 } | 350 } |
339 } | 351 } |
340 | 352 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 TokenInfo* tmp = token_info_map[account_id][i]; | 484 TokenInfo* tmp = token_info_map[account_id][i]; |
473 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) | 485 if (tmp->consumer_id == consumer_id && tmp->scopes == scopes) |
474 return tmp; | 486 return tmp; |
475 } | 487 } |
476 return NULL; | 488 return NULL; |
477 } | 489 } |
478 | 490 |
479 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( | 491 scoped_ptr<base::DictionaryValue> AboutSigninInternals::SigninStatus::ToValue( |
480 AccountTrackerService* account_tracker, | 492 AccountTrackerService* account_tracker, |
481 SigninManagerBase* signin_manager, | 493 SigninManagerBase* signin_manager, |
| 494 SigninErrorController* signin_error_controller, |
482 const std::string& product_version) { | 495 const std::string& product_version) { |
483 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 496 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
484 // fixed. | 497 // fixed. |
485 tracked_objects::ScopedTracker tracking_profile1( | 498 tracked_objects::ScopedTracker tracking_profile1( |
486 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 499 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
487 "422460 AboutSigninInternals::SigninStatus::ToValue1")); | 500 "422460 AboutSigninInternals::SigninStatus::ToValue1")); |
488 | 501 |
489 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); | 502 scoped_ptr<base::DictionaryValue> signin_status(new base::DictionaryValue()); |
490 base::ListValue* signin_info = new base::ListValue(); | 503 base::ListValue* signin_info = new base::ListValue(); |
491 signin_status->Set("signin_info", signin_info); | 504 signin_status->Set("signin_info", signin_info); |
(...skipping 25 matching lines...) Expand all Loading... |
517 static_cast<UntimedSigninStatusField>(ACCOUNT_ID)), | 530 static_cast<UntimedSigninStatusField>(ACCOUNT_ID)), |
518 account_id); | 531 account_id); |
519 AddSectionEntry(basic_info, | 532 AddSectionEntry(basic_info, |
520 SigninStatusFieldToLabel( | 533 SigninStatusFieldToLabel( |
521 static_cast<UntimedSigninStatusField>(GAIA_ID)), | 534 static_cast<UntimedSigninStatusField>(GAIA_ID)), |
522 account_tracker->GetAccountInfo(account_id).gaia); | 535 account_tracker->GetAccountInfo(account_id).gaia); |
523 AddSectionEntry(basic_info, | 536 AddSectionEntry(basic_info, |
524 SigninStatusFieldToLabel( | 537 SigninStatusFieldToLabel( |
525 static_cast<UntimedSigninStatusField>(USERNAME)), | 538 static_cast<UntimedSigninStatusField>(USERNAME)), |
526 signin_manager->GetAuthenticatedUsername()); | 539 signin_manager->GetAuthenticatedUsername()); |
| 540 if (signin_error_controller->HasError()) { |
| 541 AddSectionEntry(basic_info, "Auth Error", |
| 542 signin_error_controller->auth_error().ToString()); |
| 543 AddSectionEntry(basic_info, "Auth Error Username", |
| 544 signin_error_controller->error_username()); |
| 545 } else { |
| 546 AddSectionEntry(basic_info, "Auth Error", "None"); |
| 547 } |
527 } | 548 } |
528 | 549 |
529 #if !defined(OS_CHROMEOS) | 550 #if !defined(OS_CHROMEOS) |
530 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 551 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
531 // fixed. | 552 // fixed. |
532 tracked_objects::ScopedTracker tracking_profile3( | 553 tracked_objects::ScopedTracker tracking_profile3( |
533 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 554 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
534 "422460 AboutSigninInternals::SigninStatus::ToValue3")); | 555 "422460 AboutSigninInternals::SigninStatus::ToValue3")); |
535 | 556 |
536 // Time and status information of the possible sign in types. | 557 // 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")); | 604 "422460 AboutSigninInternals::SigninStatus::ToValue43")); |
584 | 605 |
585 for (size_t i = 0; i < tokens.size(); ++i) { | 606 for (size_t i = 0; i < tokens.size(); ++i) { |
586 base::DictionaryValue* token_info = tokens[i]->ToValue(); | 607 base::DictionaryValue* token_info = tokens[i]->ToValue(); |
587 token_details->Append(token_info); | 608 token_details->Append(token_info); |
588 } | 609 } |
589 } | 610 } |
590 | 611 |
591 return signin_status.Pass(); | 612 return signin_status.Pass(); |
592 } | 613 } |
OLD | NEW |