Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/signin/signin_manager.cc

Issue 10656033: [sync] Automatic bootstrapping of Sync on Win 8 from cached credentials (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "" Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/signin/signin_manager.h" 5 #include "chrome/browser/signin/signin_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/string_split.h" 12 #include "base/string_split.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #if defined(OS_WIN)
16 #include "base/win/windows_version.h"
17 #endif
14 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/content_settings/cookie_settings.h" 19 #include "chrome/browser/content_settings/cookie_settings.h"
16 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/signin/token_service.h" 22 #include "chrome/browser/signin/token_service.h"
19 #include "chrome/browser/signin/token_service_factory.h" 23 #include "chrome/browser/signin/token_service_factory.h"
20 #include "chrome/browser/sync/profile_sync_service.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_paths_internal.h"
22 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 29 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
24 #include "chrome/common/net/gaia/gaia_constants.h" 30 #include "chrome/common/net/gaia/gaia_constants.h"
25 #include "chrome/common/net/gaia/gaia_urls.h" 31 #include "chrome/common/net/gaia/gaia_urls.h"
26 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
28 #include "net/cookies/cookie_monster.h" 35 #include "net/cookies/cookie_monster.h"
29 #include "unicode/regex.h" 36 #include "unicode/regex.h"
30 37
31 namespace { 38 namespace {
32 39
33 const char kGetInfoEmailKey[] = "email"; 40 const char kGetInfoEmailKey[] = "email";
34 const char kGetInfoServicesKey[] = "allServices"; 41 const char kGetInfoServicesKey[] = "allServices";
35 const char kGooglePlusServiceKey[] = "googleme"; 42 const char kGooglePlusServiceKey[] = "googleme";
36 43
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 << authenticated_username_ <<"."; 446 << authenticated_username_ <<".";
440 } else { 447 } else {
441 DCHECK(service_iter->first == kGetInfoServicesKey); 448 DCHECK(service_iter->first == kGetInfoServicesKey);
442 std::vector<std::string> services; 449 std::vector<std::string> services;
443 base::SplitStringUsingSubstr(service_iter->second, ", ", &services); 450 base::SplitStringUsingSubstr(service_iter->second, ", ", &services);
444 std::vector<std::string>::const_iterator iter = 451 std::vector<std::string>::const_iterator iter =
445 std::find(services.begin(), services.end(), kGooglePlusServiceKey); 452 std::find(services.begin(), services.end(), kGooglePlusServiceKey);
446 bool isGPlusUser = (iter != services.end()); 453 bool isGPlusUser = (iter != services.end());
447 profile_->GetPrefs()->SetBoolean(prefs::kIsGooglePlusUser, isGPlusUser); 454 profile_->GetPrefs()->SetBoolean(prefs::kIsGooglePlusUser, isGPlusUser);
448 } 455 }
456
457 ConsumeUserInfoAndFinishSignin();
458
459 #if defined(OS_WIN)
460 // On Windows 8, we persist credentials after a successful sign in on Desktop
461 // (or Metro) Chrome so that when the corresponding Metro (or Desktop) Chrome
462 // is subsequently launched, we can automatically bootstrap sync without the
463 // user having to manually sign in to sync all over again.
464 // Note: We currently do this only for the "Default" profile, because there is
465 // no 1:1 correspondence between non-default profiles on Metro and Desktop.
466 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
467 csync::CredentialCache::IsDefaultProfileDir(profile_->GetPath())) {
468 PersistAuthTokensAsync();
Andrew T Wilson (Slow) 2012/06/26 23:26:13 I wonder if we need to do this, or if it's better/
Raghu Simha 2012/06/27 00:17:04 I agree with the premise of your suggestion. It tu
Raghu Simha 2012/07/19 06:57:07 Done. All code removed from SigninManager.
469 }
470 #endif // OS_WIN
471 }
472
473 void SigninManager::ConsumeUserInfoAndFinishSignin() {
449 GoogleServiceSigninSuccessDetails details(authenticated_username_, 474 GoogleServiceSigninSuccessDetails details(authenticated_username_,
450 password_); 475 password_);
451 content::NotificationService::current()->Notify( 476 content::NotificationService::current()->Notify(
452 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 477 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
453 content::Source<Profile>(profile_), 478 content::Source<Profile>(profile_),
454 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 479 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
455 480
456 password_.clear(); // Don't need it anymore. 481 password_.clear(); // Don't need it anymore.
457 482
458 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 483 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
459 token_service->UpdateCredentials(last_result_); 484 token_service->UpdateCredentials(last_result_);
460 DCHECK(token_service->AreCredentialsValid()); 485 DCHECK(token_service->AreCredentialsValid());
461 token_service->StartFetchingTokens(); 486 token_service->StartFetchingTokens();
462 } 487 }
463 488
489 #if defined(OS_WIN)
490
491 void SigninManager::StartSignInWithCachedCredentials(
492 scoped_refptr<csync::CredentialCache> credentials) {
Roger Tawa OOO till Jul 10th 2012/06/27 21:23:28 The order of implementation in the cc file should
Raghu Simha 2012/07/19 06:57:07 Moot for this file, but I've followed this rule in
493 DCHECK(credentials.get() != NULL);
494 SetAuthenticatedUsername(credentials->authenticated_username());
495 possibly_invalid_username_.clear();
496 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
497 authenticated_username_);
498 last_result_.sid = credentials->sid();
499 last_result_.lsid = credentials->lsid();
500 password_.clear();
Andrew T Wilson (Slow) 2012/06/26 23:26:13 Hmmm. It previously has been illegal to send out S
Raghu Simha 2012/06/27 00:17:04 I had to do this due to a DCHECK. This problem sho
501
502 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
503 registrar_.Add(this,
504 chrome::NOTIFICATION_TOKEN_AVAILABLE,
505 content::Source<TokenService>(token_service));
Roger Tawa OOO till Jul 10th 2012/06/27 21:23:28 why do you need to register? Note that the case f
Raghu Simha 2012/07/19 06:57:07 We no longer do this.
506
507 ConsumeUserInfoAndFinishSignin();
508 }
509
510 void SigninManager::PersistAuthTokensAsync() {
511 scoped_refptr<csync::CredentialCache> credentials =
512 new csync::CredentialCache(authenticated_username_,
513 last_result_.sid,
514 last_result_.lsid,
515 "",
516 profile_->GetPath());
517 content::BrowserThread::PostTask(
518 content::BrowserThread::FILE,
519 FROM_HERE,
520 base::Bind(&csync::CredentialCache::PersistAuthTokens, credentials));
521 }
522
523 #endif // OS_WIN
524
464 void SigninManager::OnGetUserInfoFailure(const GoogleServiceAuthError& error) { 525 void SigninManager::OnGetUserInfoFailure(const GoogleServiceAuthError& error) {
465 LOG(ERROR) << "Unable to retreive the canonical email address. Login failed."; 526 LOG(ERROR) << "Unable to retrieve the canonical email address. Login failed.";
466 // REVIEW: why does this call OnClientLoginFailure? 527 // REVIEW: why does this call OnClientLoginFailure?
467 OnClientLoginFailure(error); 528 OnClientLoginFailure(error);
468 } 529 }
469 530
470 void SigninManager::Observe(int type, 531 void SigninManager::Observe(int type,
471 const content::NotificationSource& source, 532 const content::NotificationSource& source,
472 const content::NotificationDetails& details) { 533 const content::NotificationDetails& details) {
473 switch (type) { 534 switch (type) {
474 case chrome::NOTIFICATION_PREF_CHANGED: 535 case chrome::NOTIFICATION_PREF_CHANGED:
475 DCHECK(*content::Details<std::string>(details).ptr() == 536 DCHECK(*content::Details<std::string>(details).ptr() ==
(...skipping 28 matching lines...) Expand all
504 CleanupNotificationRegistration(); 565 CleanupNotificationRegistration();
505 } 566 }
506 break; 567 break;
507 } 568 }
508 #endif 569 #endif
509 default: 570 default:
510 NOTREACHED(); 571 NOTREACHED();
511 } 572 }
512 } 573 }
513 574
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698