Commit d116d109 authored by antrim's avatar antrim Committed by Commit bot

Move token handle obtaining to UserSessionManager

BUG=484690,484734
R=nkostylev@chromium.org

Committed: https://crrev.com/71ede7fdaf6404ec0f70a60d60f679fee07902a9
Cr-Commit-Position: refs/heads/master@{#329868}

Review URL: https://codereview.chromium.org/1129293004

Cr-Commit-Position: refs/heads/master@{#330110}
parent 6ba76f9b
...@@ -767,6 +767,9 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { ...@@ -767,6 +767,9 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
g_browser_process->platform_part()->DestroyChromeUserManager(); g_browser_process->platform_part()->DestroyChromeUserManager();
// Make sure that there is no pending URLRequests.
UserSessionManager::GetInstance()->Shutdown();
g_browser_process->platform_part()->ShutdownSessionManager(); g_browser_process->platform_part()->ShutdownSessionManager();
} }
......
...@@ -1236,38 +1236,8 @@ void ExistingUserController::OnOAuth2TokensFetched( ...@@ -1236,38 +1236,8 @@ void ExistingUserController::OnOAuth2TokensFetched(
OnAuthFailure(AuthFailure(AuthFailure::FAILED_TO_INITIALIZE_TOKEN)); OnAuthFailure(AuthFailure(AuthFailure::FAILED_TO_INITIALIZE_TOKEN));
return; return;
} }
if (StartupUtils::IsWebviewSigninEnabled() && TokenHandlesEnabled()) { UserSessionManager::GetInstance()->OnOAuth2TokensFetched(user_context);
if (!token_handle_util_.get()) {
token_handle_util_.reset(
new TokenHandleUtil(user_manager::UserManager::Get()));
}
if (token_handle_util_->ShouldObtainHandle(user_context.GetUserID())) {
token_handle_util_->GetTokenHandle(
user_context.GetUserID(), user_context.GetAccessToken(),
base::Bind(&ExistingUserController::OnTokenHandleObtained,
weak_factory_.GetWeakPtr()));
}
}
PerformLogin(user_context, LoginPerformer::AUTH_MODE_EXTENSION); PerformLogin(user_context, LoginPerformer::AUTH_MODE_EXTENSION);
} }
void ExistingUserController::OnTokenHandleObtained(
const user_manager::UserID& id,
TokenHandleUtil::TokenHandleStatus status) {
if (status != TokenHandleUtil::VALID) {
LOG(ERROR) << "OAuth2 token handle fetch failed.";
return;
}
}
bool ExistingUserController::TokenHandlesEnabled() {
bool ephemeral_users_enabled = false;
bool show_names_on_signin = true;
cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled,
&ephemeral_users_enabled);
cros_settings_->GetBoolean(kAccountsPrefShowUserNamesOnSignIn,
&show_names_on_signin);
return show_names_on_signin && !ephemeral_users_enabled;
}
} // namespace chromeos } // namespace chromeos
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/signin/token_handle_util.h"
#include "chrome/browser/chromeos/login/ui/login_display.h" #include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
...@@ -243,13 +242,6 @@ class ExistingUserController : public LoginDisplay::Delegate, ...@@ -243,13 +242,6 @@ class ExistingUserController : public LoginDisplay::Delegate,
// Callback invoked when |oauth2_token_initializer_| has finished. // Callback invoked when |oauth2_token_initializer_| has finished.
void OnOAuth2TokensFetched(bool success, const UserContext& user_context); void OnOAuth2TokensFetched(bool success, const UserContext& user_context);
// Callback invoked when |token_handle_util_| has finished.
void OnTokenHandleObtained(const user_manager::UserID& id,
TokenHandleUtil::TokenHandleStatus status);
// Returns |true| if token handles should be used on this device.
bool TokenHandlesEnabled();
// Public session auto-login timer. // Public session auto-login timer.
scoped_ptr<base::OneShotTimer<ExistingUserController> > auto_login_timer_; scoped_ptr<base::OneShotTimer<ExistingUserController> > auto_login_timer_;
...@@ -338,7 +330,6 @@ class ExistingUserController : public LoginDisplay::Delegate, ...@@ -338,7 +330,6 @@ class ExistingUserController : public LoginDisplay::Delegate,
bootstrap_user_context_initializer_; bootstrap_user_context_initializer_;
scoped_ptr<OAuth2TokenInitializer> oauth2_token_initializer_; scoped_ptr<OAuth2TokenInitializer> oauth2_token_initializer_;
scoped_ptr<TokenHandleUtil> token_handle_util_;
FRIEND_TEST_ALL_PREFIXES(ExistingUserControllerTest, ExistingUserLogin); FRIEND_TEST_ALL_PREFIXES(ExistingUserControllerTest, ExistingUserLogin);
......
...@@ -1672,4 +1672,43 @@ void UserSessionManager::SendUserPodsMetrics() { ...@@ -1672,4 +1672,43 @@ void UserSessionManager::SendUserPodsMetrics() {
NUM_USER_PODS_DISPLAY); NUM_USER_PODS_DISPLAY);
} }
void UserSessionManager::OnOAuth2TokensFetched(UserContext context) {
if (StartupUtils::IsWebviewSigninEnabled() && TokenHandlesEnabled()) {
if (!token_handle_util_.get()) {
token_handle_util_.reset(
new TokenHandleUtil(user_manager::UserManager::Get()));
}
if (token_handle_util_->ShouldObtainHandle(context.GetUserID())) {
token_handle_util_->GetTokenHandle(
context.GetUserID(), context.GetAccessToken(),
base::Bind(&UserSessionManager::OnTokenHandleObtained,
weak_factory_.GetWeakPtr()));
}
}
}
void UserSessionManager::OnTokenHandleObtained(
const user_manager::UserID& id,
TokenHandleUtil::TokenHandleStatus status) {
if (status != TokenHandleUtil::VALID) {
LOG(ERROR) << "OAuth2 token handle fetch failed.";
return;
}
}
bool UserSessionManager::TokenHandlesEnabled() {
bool ephemeral_users_enabled = false;
bool show_names_on_signin = true;
auto cros_settings = CrosSettings::Get();
cros_settings->GetBoolean(kAccountsPrefEphemeralUsersEnabled,
&ephemeral_users_enabled);
cros_settings->GetBoolean(kAccountsPrefShowUserNamesOnSignIn,
&show_names_on_signin);
return show_names_on_signin && !ephemeral_users_enabled;
}
void UserSessionManager::Shutdown() {
token_handle_util_.reset();
}
} // namespace chromeos } // namespace chromeos
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "chrome/browser/chromeos/base/locale_util.h" #include "chrome/browser/chromeos/base/locale_util.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
#include "chrome/browser/chromeos/login/signin/token_handle_util.h"
#include "chromeos/dbus/session_manager_client.h" #include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/auth/authenticator.h" #include "chromeos/login/auth/authenticator.h"
#include "chromeos/login/auth/user_context.h" #include "chromeos/login/auth/user_context.h"
...@@ -218,6 +219,9 @@ class UserSessionManager ...@@ -218,6 +219,9 @@ class UserSessionManager
void ActiveUserChanged(const user_manager::User* active_user) override; void ActiveUserChanged(const user_manager::User* active_user) override;
// This method will be called when user have obtained oauth2 tokens.
void OnOAuth2TokensFetched(UserContext context);
// Returns default IME state for user session. // Returns default IME state for user session.
scoped_refptr<input_method::InputMethodManager::State> GetDefaultIMEState( scoped_refptr<input_method::InputMethodManager::State> GetDefaultIMEState(
Profile* profile); Profile* profile);
...@@ -237,6 +241,8 @@ class UserSessionManager ...@@ -237,6 +241,8 @@ class UserSessionManager
const UserContext& user_context() const { return user_context_; } const UserContext& user_context() const { return user_context_; }
bool has_auth_cookies() const { return has_auth_cookies_; } bool has_auth_cookies() const { return has_auth_cookies_; }
void Shutdown();
private: private:
friend class test::UserSessionManagerTestApi; friend class test::UserSessionManagerTestApi;
friend struct DefaultSingletonTraits<UserSessionManager>; friend struct DefaultSingletonTraits<UserSessionManager>;
...@@ -360,6 +366,13 @@ class UserSessionManager ...@@ -360,6 +366,13 @@ class UserSessionManager
InputEventsBlocker* input_events_blocker, InputEventsBlocker* input_events_blocker,
const locale_util::LanguageSwitchResult& result); const locale_util::LanguageSwitchResult& result);
// Callback invoked when |token_handle_util_| has finished.
void OnTokenHandleObtained(const user_manager::UserID& id,
TokenHandleUtil::TokenHandleStatus status);
// Returns |true| if token handles should be used on this device.
bool TokenHandlesEnabled();
// Test API methods. // Test API methods.
// Injects |user_context| that will be used to create StubAuthenticator // Injects |user_context| that will be used to create StubAuthenticator
...@@ -444,6 +457,8 @@ class UserSessionManager ...@@ -444,6 +457,8 @@ class UserSessionManager
bool running_easy_unlock_key_ops_; bool running_easy_unlock_key_ops_;
base::Closure easy_unlock_key_ops_finished_callback_; base::Closure easy_unlock_key_ops_finished_callback_;
scoped_ptr<TokenHandleUtil> token_handle_util_;
// Whether should launch browser, tests may override this value. // Whether should launch browser, tests may override this value.
bool should_launch_browser_; bool should_launch_browser_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment