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

Side by Side Diff: chrome/browser/chromeos/login/login_manager.cc

Issue 11649055: OAuth2 sign-in flow for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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) 2012 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.
xiyuan 2013/01/07 23:07:55 nit: insert an empty line
zel 2013/01/08 02:05:41 Done.
4 #include "chrome/browser/chromeos/login/login_manager.h"
5
6 #include "base/metrics/histogram.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/token_service.h"
10 #include "chrome/browser/signin/token_service_factory.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_service.h"
14 #include "google_apis/gaia/gaia_auth_fetcher.h"
15 #include "google_apis/gaia/gaia_constants.h"
16
17 using content::BrowserThread;
18
19 namespace {
20
21 // OAuth token verification max retry count.
22 const int kMaxCookieRecoveryAttemptCount = 5;
23 // OAuth token verification retry delay in milliseconds.
24 const int kCookieRecoveryRestartDelay = 10000;
25
26 } // namespace
27
28
29 namespace chromeos {
30
31 LoginManager::LoginManager(Delegate* delegate,
32 Profile* user_profile)
33 : delegate_(delegate),
34 user_profile_(user_profile),
35 loading_reported_(false),
36 restore_attempt_count_(0) {
37 TokenService* token_service =
38 TokenServiceFactory::GetForProfile(user_profile_);
39 registrar_.Add(this,
40 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
41 content::Source<TokenService>(token_service));
42 registrar_.Add(this,
43 chrome::NOTIFICATION_TOKEN_AVAILABLE,
44 content::Source<TokenService>(token_service));
45 registrar_.Add(this,
46 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
47 content::Source<TokenService>(token_service));
48 }
49
50 void LoginManager::Observe(
51 int type,
52 const content::NotificationSource& source,
53 const content::NotificationDetails& details) OVERRIDE {
54 TokenService* token_service =
55 TokenServiceFactory::GetForProfile(user_profile_);
56 switch (type) {
57 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: {
58 refresh_token_ = token_service->GetOAuth2LoginRefreshToken();
59 ReportTokenLoaded();
60 // Have we started restoring GAIA auth cookies yet?
61 if (!refresh_token_.empty() && !login_verifier_.get())
62 RestoreSessionCookies();
63
64 break;
65 }
66 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: {
67 // TODO(zelidrag): Figure out how to recover from transient errors with
68 // TokenService class - similar to what we do in RetryOnError() here.
69 TokenService::TokenAvailableDetails* token_details =
70 content::Details<TokenService::TokenAvailableDetails>(
71 details).ptr();
72 if (token_details->service() ==
73 GaiaConstants::kGaiaOAuth2LoginRefreshToken) {
74 delegate_->OnOAuth2RefreshTokenFetchFailed(user_profile_, token_details- >service());
xiyuan 2013/01/07 23:07:55 nit: 80 cols
zel 2013/01/08 02:05:41 Done.
75 }
76 break;
77 }
78 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
79 TokenService::TokenAvailableDetails* token_details =
80 content::Details<TokenService::TokenAvailableDetails>(
81 details).ptr();
82 if (token_details->service() ==
83 GaiaConstants::kGaiaOAuth2LoginRefreshToken) {
84 DCHECK(!login_verifier_.get());
85 refresh_token_ = token_details->token();
86 RestoreSessionCookies();
87 }
88
89 break;
90 }
91 default:
92 NOTREACHED();
93 break;
94 }
95 }
96
97 void LoginManager::RestoreSessionCookies() {
98 LOG(WARNING) << "Fetched refresh token!";
xiyuan 2013/01/07 23:07:55 nit: VLOG(1) instead of LOG(WARNING)?
99 DCHECK(!refresh_token_.empty());
100 if (!login_verifier_.get()) {
101 login_verifier_.reset(
102 new OAuth2LoginVerifier(this,
103 g_browser_process->system_request_context(),
104 user_profile_));
105 }
106 login_verifier_->VerifyRefreshToken(refresh_token_);
107 }
108
109 void LoginManager::OnOAuth2LoginVerifierSuccess(
110 const std::string& sid, const std::string& lsid, const std::string& auth) {
xiyuan 2013/01/07 23:07:55 nit: put the args into their own lines.
zel 2013/01/08 02:05:41 Done.
111 delegate_->OnCookiesRestoreSuccess(user_profile_);
112 }
113
114 void LoginManager::OnOAuth2LoginVerifierFaulure() {
115 delegate_->OnCookiesRestoreFailure(user_profile_);
116 }
117
118 void LoginManager::ReportTokenLoaded() {
119 LOG(WARNING) << "Got OAuth2 refresh token!";
xiyuan 2013/01/07 23:07:55 nit: VLOG(1) instead of LOG(WARNING)?
120 DCHECK(!loading_reported_);
121 loading_reported_ = true;
122 delegate_->OnOAuth2RefreshTokenLoaded(user_profile_, refresh_token_);
123 }
124
125 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698