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

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

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/signin_manager.h"
6
7 #include "base/string_util.h"
8 #include "chrome/browser/net/gaia/token_service.h"
9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profile.h"
11 #include "chrome/common/net/gaia/gaia_constants.h"
12 #include "chrome/common/notification_service.h"
13 #include "chrome/common/pref_names.h"
14
15 // static
16 void SigninManager::RegisterUserPrefs(PrefService* user_prefs) {
17 user_prefs->RegisterStringPref(prefs::kGoogleServicesUsername, "");
18 }
19
20 void SigninManager::Initialize(Profile* profile) {
21 profile_ = profile;
22 username_ = profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
23 profile_->GetTokenService()->Initialize(
24 GaiaConstants::kChromeSource, profile_);
25 if (!username_.empty()) {
26 profile_->GetTokenService()->LoadTokensFromDB();
27 }
28 }
29
30 // If a username already exists, the user is logged in.
31 const std::string& SigninManager::GetUsername() {
32 return username_;
33 }
34
35 void SigninManager::SetUsername(const std::string& username) {
36 username_ = username;
37 }
38
39 // Users must always sign out before they sign in again.
40 void SigninManager::StartSignIn(const std::string& username,
41 const std::string& password,
42 const std::string& login_token,
43 const std::string& login_captcha) {
44 DCHECK(username_.empty());
45 // The Sign out should clear the token service credentials.
46 DCHECK(!profile_->GetTokenService()->AreCredentialsValid());
47
48 username_.assign(username);
49 password_.assign(password);
50
51 client_login_.reset(new GaiaAuthenticator2(this,
52 GaiaConstants::kChromeSource,
53 profile_->GetRequestContext()));
54 client_login_->StartClientLogin(username,
55 password,
56 "",
57 login_token,
58 login_captcha);
59 }
60
61 void SigninManager::SignOut() {
62 client_login_.reset();
63 username_.clear();
64 password_.clear();
65 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_);
66 profile_->GetPrefs()->ScheduleSavePersistentPrefs();
67 profile_->GetTokenService()->ResetCredentialsInMemory();
68 profile_->GetTokenService()->EraseTokensFromDB();
69 }
70
71 void SigninManager::OnClientLoginSuccess(const ClientLoginResult& result) {
72 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_);
73 profile_->GetPrefs()->ScheduleSavePersistentPrefs();
74
75 GoogleServiceSigninSuccessDetails details(username_, password_);
76 NotificationService::current()->Notify(
77 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL,
78 Source<SigninManager>(this),
79 Details<const GoogleServiceSigninSuccessDetails>(&details));
80
81 password_.clear(); // Don't need it anymore.
82
83 profile_->GetTokenService()->UpdateCredentials(result);
84 DCHECK(profile_->GetTokenService()->AreCredentialsValid());
85 profile_->GetTokenService()->StartFetchingTokens();
86 }
87
88 void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) {
89 GoogleServiceAuthError details(error);
90 NotificationService::current()->Notify(
91 NotificationType::GOOGLE_SIGNIN_FAILED,
92 Source<SigninManager>(this),
93 Details<const GoogleServiceAuthError>(&details));
94 SignOut();
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698