Commit 314a23a1 authored by jdufault's avatar jdufault Committed by Commit bot

cros: Preload and reuse the lock screen across lock sessions

This is currently behind a feature flag and not enabled by default.

- The lock screen webview will be saved and reused across lock sessions.
- The lock screen webview will be preloaded after the user has not generated any input events for 8 seconds.

See https://codereview.chromium.org/2512473004/ for additional context.

BUG=669638

Review-Url: https://codereview.chromium.org/2553863002
Cr-Commit-Position: refs/heads/master@{#438698}
parent a94f63df
......@@ -8,6 +8,7 @@
#include "ash/shell.h"
#include "ash/system/chromeos/power/power_event_observer.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
......@@ -16,19 +17,29 @@
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/login/ui/shared_web_view.h"
#include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
#include "chrome/browser/chromeos/login/ui/web_view_handle.h"
#include "chrome/browser/chromeos/login/ui/webui_login_display.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/x/x11_util.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
......@@ -53,15 +64,61 @@ void ResetKeyboardOverscrollOverride() {
keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE);
}
chromeos::WebUILoginView::WebViewSettings BuildSettings() {
chromeos::WebUILoginView::WebViewSettings settings;
if (chromeos::WebUIScreenLocker::ShouldShareLockScreen()) {
settings.preloaded_url = GURL(kLoginURL);
settings.web_view_title =
l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME);
}
return settings;
}
} // namespace
namespace chromeos {
// static
bool WebUIScreenLocker::ShouldShareLockScreen() {
Profile* profile = ProfileHelper::Get()->GetProfileByUser(
user_manager::UserManager::Get()->GetActiveUser());
// We only want to share the lock screen if the user is likely to see the lock
// screen (since caching the lock screen uses memory). Without preloading,
// showing the lock screen can take so long we will timeout and crash the
// browser process (which currently takes down all of Chrome). See
// crbug.com/452599 for more context.
//
// prefs::kEnableAutoScreenLock controls if the lock screen is shown on
// suspend, so that is our primary hueristic.
// Note that |profile| can be null in tests.
return base::FeatureList::IsEnabled(features::kSharedLockScreen) && profile &&
profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock);
}
// static
void WebUIScreenLocker::Preload() {
DCHECK(ShouldShareLockScreen());
VLOG(1) << "Preloading lock screen";
SharedWebView* shared_web_view =
SharedWebViewFactory::GetForProfile(ProfileHelper::GetSigninProfile());
scoped_refptr<WebViewHandle> web_view_handle;
if (!shared_web_view->Get(GURL(kLoginURL), &web_view_handle)) {
web_view_handle->web_view()->LoadInitialURL(GURL(kLoginURL));
InitializeWebView(
web_view_handle->web_view(),
l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME));
}
}
////////////////////////////////////////////////////////////////////////////////
// WebUIScreenLocker implementation.
WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker)
: WebUILoginView(WebViewSettings()),
: WebUILoginView(BuildSettings()),
screen_locker_(screen_locker),
network_state_helper_(new login::NetworkStateHelper),
weak_factory_(this) {
......
......@@ -55,6 +55,10 @@ class WebUIScreenLocker : public WebUILoginView,
public display::DisplayObserver,
public content::WebContentsObserver {
public:
// Returns true if the lock screen should be shared.
static bool ShouldShareLockScreen();
static void Preload();
explicit WebUIScreenLocker(ScreenLocker* screen_locker);
~WebUIScreenLocker() override;
......
......@@ -17,6 +17,8 @@
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/arc/arc_service_launcher.h"
#include "chrome/browser/chromeos/boot_times_recorder.h"
#include "chrome/browser/chromeos/idle_detector.h"
#include "chrome/browser/chromeos/login/lock/webui_screen_locker.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
......@@ -44,6 +46,9 @@ namespace chromeos {
namespace {
// Duration of user inactivity before preloading the lock screen.
constexpr int kIdleSecondsBeforePreloadingLockScreen = 8;
// Whether kiosk auto launch should be started.
bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) {
KioskAppManager* app_manager = KioskAppManager::Get();
......@@ -232,6 +237,13 @@ void ChromeSessionManager::SessionStarted() {
content::Source<session_manager::SessionManager>(this),
content::Details<const user_manager::User>(
user_manager->GetActiveUser()));
if (chromeos::WebUIScreenLocker::ShouldShareLockScreen()) {
idle_detector_ = base::MakeUnique<chromeos::IdleDetector>(
base::Bind(&chromeos::WebUIScreenLocker::Preload));
idle_detector_->Start(
base::TimeDelta::FromSeconds(kIdleSecondsBeforePreloadingLockScreen));
}
}
void ChromeSessionManager::NotifyUserLoggedIn(const AccountId& user_account_id,
......
......@@ -16,6 +16,8 @@ class Profile;
namespace chromeos {
class IdleDetector;
class ChromeSessionManager : public session_manager::SessionManager {
public:
ChromeSessionManager();
......@@ -38,6 +40,9 @@ class ChromeSessionManager : public session_manager::SessionManager {
bool browser_restart) override;
private:
// Used to preload the lock screen when the user is inactive.
std::unique_ptr<IdleDetector> idle_detector_;
DISALLOW_COPY_AND_ASSIGN(ChromeSessionManager);
};
......
......@@ -194,6 +194,13 @@ const base::Feature kRunAllFlashInAllowMode{"RunAllFlashInAllowMode",
const base::Feature kSafeSearchUrlReporting{"SafeSearchUrlReporting",
base::FEATURE_DISABLED_BY_DEFAULT};
#if defined(OS_CHROMEOS)
// The lock screen will be preloaded and shared so it is instantly available
// when the user locks the Chromebook device.
const base::Feature kSharedLockScreen{"SharedLockScreen",
base::FEATURE_DISABLED_BY_DEFAULT};
#endif
// A new user experience for transitioning into fullscreen and mouse pointer
// lock states.
const base::Feature kSimplifiedFullscreenUI{"ViewsSimplifiedFullscreenUI",
......
......@@ -115,6 +115,10 @@ extern const base::Feature kRunAllFlashInAllowMode;
extern const base::Feature kSafeSearchUrlReporting;
#if defined(OS_CHROMEOS)
extern const base::Feature kSharedLockScreen;
#endif
extern const base::Feature kSimplifiedFullscreenUI;
#if defined(SYZYASAN)
......
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