OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/signin/oauth2_login_manager.h" | 5 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 16 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
19 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
20 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
21 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
22 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 21 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
23 #include "components/signin/core/browser/signin_client.h" | 22 #include "components/signin/core/browser/signin_client.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 24 #include "components/user_manager/user_manager.h" |
25 #include "google_apis/gaia/gaia_auth_util.h" | 25 #include "google_apis/gaia/gaia_auth_util.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 26 #include "google_apis/gaia/gaia_constants.h" |
27 #include "google_apis/gaia/gaia_urls.h" | 27 #include "google_apis/gaia/gaia_urls.h" |
28 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
29 | 29 |
30 namespace chromeos { | 30 namespace chromeos { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 static const char kServiceScopeGetUserInfo[] = | 34 static const char kServiceScopeGetUserInfo[] = |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { | 104 if (token_service->RefreshTokenIsAvailable(primary_account_id)) { |
105 VLOG(1) << "OAuth2 refresh token is already loaded."; | 105 VLOG(1) << "OAuth2 refresh token is already loaded."; |
106 VerifySessionCookies(); | 106 VerifySessionCookies(); |
107 } else { | 107 } else { |
108 VLOG(1) << "Loading OAuth2 refresh token from database."; | 108 VLOG(1) << "Loading OAuth2 refresh token from database."; |
109 | 109 |
110 // Flag user with unknown token status in case there are no saved tokens | 110 // Flag user with unknown token status in case there are no saved tokens |
111 // and OnRefreshTokenAvailable is not called. Flagging it here would | 111 // and OnRefreshTokenAvailable is not called. Flagging it here would |
112 // cause user to go through Gaia in next login to obtain a new refresh | 112 // cause user to go through Gaia in next login to obtain a new refresh |
113 // token. | 113 // token. |
114 UserManager::Get()->SaveUserOAuthStatus( | 114 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
115 primary_account_id, user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); | 115 primary_account_id, user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); |
116 | 116 |
117 token_service->LoadCredentials(primary_account_id); | 117 token_service->LoadCredentials(primary_account_id); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 void OAuth2LoginManager::Stop() { | 121 void OAuth2LoginManager::Stop() { |
122 oauth2_token_fetcher_.reset(); | 122 oauth2_token_fetcher_.reset(); |
123 login_verifier_.reset(); | 123 login_verifier_.reset(); |
124 } | 124 } |
125 | 125 |
126 bool OAuth2LoginManager::ShouldBlockTabLoading() { | 126 bool OAuth2LoginManager::ShouldBlockTabLoading() { |
127 return state_ == SESSION_RESTORE_PREPARING || | 127 return state_ == SESSION_RESTORE_PREPARING || |
128 state_ == SESSION_RESTORE_IN_PROGRESS; | 128 state_ == SESSION_RESTORE_IN_PROGRESS; |
129 } | 129 } |
130 | 130 |
131 void OAuth2LoginManager::OnRefreshTokenAvailable( | 131 void OAuth2LoginManager::OnRefreshTokenAvailable( |
132 const std::string& account_id) { | 132 const std::string& account_id) { |
133 VLOG(1) << "OnRefreshTokenAvailable"; | 133 VLOG(1) << "OnRefreshTokenAvailable"; |
134 | 134 |
135 if (state_ == SESSION_RESTORE_NOT_STARTED) | 135 if (state_ == SESSION_RESTORE_NOT_STARTED) |
136 return; | 136 return; |
137 | 137 |
138 // TODO(fgorski): Once ProfileOAuth2TokenService supports multi-login, make | 138 // TODO(fgorski): Once ProfileOAuth2TokenService supports multi-login, make |
139 // sure to restore session cookies in the context of the correct account_id. | 139 // sure to restore session cookies in the context of the correct account_id. |
140 | 140 |
141 // Do not validate tokens for supervised users, as they don't actually have | 141 // Do not validate tokens for supervised users, as they don't actually have |
142 // oauth2 token. | 142 // oauth2 token. |
143 if (UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 143 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { |
144 VLOG(1) << "Logged in as supervised user, skip token validation."; | 144 VLOG(1) << "Logged in as supervised user, skip token validation."; |
145 return; | 145 return; |
146 } | 146 } |
147 // Only restore session cookies for the primary account in the profile. | 147 // Only restore session cookies for the primary account in the profile. |
148 if (GetPrimaryAccountId() == account_id) { | 148 if (GetPrimaryAccountId() == account_id) { |
149 // Token is loaded. Undo the flagging before token loading. | 149 // Token is loaded. Undo the flagging before token loading. |
150 UserManager::Get()->SaveUserOAuthStatus( | 150 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
151 account_id, user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 151 account_id, user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
152 VerifySessionCookies(); | 152 VerifySessionCookies(); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() { | 156 ProfileOAuth2TokenService* OAuth2LoginManager::GetTokenService() { |
157 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); | 157 return ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); |
158 } | 158 } |
159 | 159 |
160 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { | 160 const std::string& OAuth2LoginManager::GetPrimaryAccountId() { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 FOR_EACH_OBSERVER(Observer, observer_list_, | 403 FOR_EACH_OBSERVER(Observer, observer_list_, |
404 OnSessionRestoreStateChanged(user_profile_, state_)); | 404 OnSessionRestoreStateChanged(user_profile_, state_)); |
405 } | 405 } |
406 | 406 |
407 void OAuth2LoginManager::SetSessionRestoreStartForTesting( | 407 void OAuth2LoginManager::SetSessionRestoreStartForTesting( |
408 const base::Time& time) { | 408 const base::Time& time) { |
409 session_restore_start_ = time; | 409 session_restore_start_ = time; |
410 } | 410 } |
411 | 411 |
412 } // namespace chromeos | 412 } // namespace chromeos |
OLD | NEW |