Commit 1fc9246a authored by Nancy Wang's avatar Nancy Wang Committed by Chromium LUCI CQ

Modify the browser launch process for the full restore feature.

UI review deck: go/cros-full-restore
PRD: go/cros-full-restore-prd
Design doc: go/chrome-os-full-restore-dd

When the full restore feature is enabled, whether to launch the browser
is controlled by the full restore process:
1. If the full restore setting is not restore, don't launch the browser.
2. If the user selects restore or set always restore, launch the
browser.

This CL modified the current launching browser process during the
startup phase.
1. If the full restore feature is disabled, the current process is not
changed.
2. If the full restore feature is enabled, postpone the browser
launching. Only when the restore data has been fetched, and the user
selects restore or set always restore, launch the browser by the full
restore process.

BUG=1146900

Change-Id: I9f03e7039761f4d2956b7d4c2bdeecf99ef2d955
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2603759Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843296}
parent 31615517
......@@ -13,12 +13,14 @@
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "components/full_restore/full_restore_read_handler.h"
#include "components/full_restore/full_restore_save_handler.h"
#include "components/full_restore/restore_data.h"
#include "components/services/app_service/public/cpp/app_update.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "extensions/common/constants.h"
#include "ui/base/window_open_disposition.h"
namespace chromeos {
......@@ -62,6 +64,20 @@ void AppLaunchHandler::OnAppRegistryCacheWillBeDestroyed(
apps::AppRegistryCache::Observer::Observe(nullptr);
}
void AppLaunchHandler::LauncherBrowserWhenReady() {
// If the restore data has been loaded, and the user has chosen to restore,
// launch the browser.
if (should_restore_ && restore_data_) {
LaunchBrowser();
return;
}
// If the restore data hasn't been loaded, or the user hasn't chosen to
// restore, set should_launch_browser_ as true, and wait the restore data
// loaded, and the user selection, then we can launch the browser.
should_launch_browser_ = true;
}
void AppLaunchHandler::SetShouldRestore() {
should_restore_ = true;
MaybePostRestore();
......@@ -91,6 +107,11 @@ void AppLaunchHandler::MaybePostRestore() {
}
void AppLaunchHandler::MaybeRestore() {
if (should_launch_browser_) {
LaunchBrowser();
should_launch_browser_ = false;
}
// If there is no launch list from the restore data, we don't need to handle
// the restoration.
const auto& launch_list = restore_data_->app_id_to_launch_list();
......@@ -118,6 +139,11 @@ void AppLaunchHandler::MaybeRestore() {
LaunchApp(cache->GetAppType(app_id), app_id);
}
void AppLaunchHandler::LaunchBrowser() {
UserSessionManager::GetInstance()->LaunchBrowser(profile_);
UserSessionManager::GetInstance()->MaybeLaunchSettings(profile_);
}
void AppLaunchHandler::LaunchApp(apps::mojom::AppType app_type,
const std::string& app_id) {
DCHECK(restore_data_);
......
......@@ -42,6 +42,10 @@ class AppLaunchHandler : public apps::AppRegistryCache::Observer {
void OnAppRegistryCacheWillBeDestroyed(
apps::AppRegistryCache* cache) override;
// Launches the browser, When the restore data is loaded, and the user chooses
// to restore.
void LauncherBrowserWhenReady();
// If the user preference sets always restore or the user selects 'Restore'
// from the notification dialog, sets the restore flag |should_restore_| as
// true to allow the restoration.
......@@ -57,6 +61,8 @@ class AppLaunchHandler : public apps::AppRegistryCache::Observer {
// true, launches apps based on the restore data when apps are ready.
void MaybeRestore();
void LaunchBrowser();
void LaunchApp(apps::mojom::AppType app_type, const std::string& app_id);
void LaunchWebAppOrExtension(
......@@ -67,6 +73,8 @@ class AppLaunchHandler : public apps::AppRegistryCache::Observer {
bool should_restore_ = false;
bool should_launch_browser_ = false;
std::unique_ptr<::full_restore::RestoreData> restore_data_;
base::WeakPtrFactory<AppLaunchHandler> weak_ptr_factory_{this};
......
......@@ -39,6 +39,12 @@ const char kSetRestorePrefNotificationId[] = "set_restore_pref_notification";
// set restore pref notification.
const int kMaxConsecutiveRestoreSelectionCount = 3;
// static
FullRestoreService* FullRestoreService::GetForProfile(Profile* profile) {
return static_cast<FullRestoreService*>(
FullRestoreServiceFactory::GetInstance()->GetForProfile(profile));
}
FullRestoreService::FullRestoreService(Profile* profile)
: profile_(profile),
app_launch_handler_(std::make_unique<AppLaunchHandler>(profile_)),
......@@ -84,6 +90,10 @@ FullRestoreService::FullRestoreService(Profile* profile)
FullRestoreService::~FullRestoreService() = default;
void FullRestoreService::LauncherBrowserWhenReady() {
app_launch_handler_->LauncherBrowserWhenReady();
}
void FullRestoreService::Shutdown() {
is_shut_down_ = true;
}
......
......@@ -47,12 +47,18 @@ enum class RestoreNotificationButtonIndex {
// and restore apps and app windows.
class FullRestoreService : public KeyedService {
public:
static FullRestoreService* GetForProfile(Profile* profile);
explicit FullRestoreService(Profile* profile);
~FullRestoreService() override;
FullRestoreService(const FullRestoreService&) = delete;
FullRestoreService& operator=(const FullRestoreService&) = delete;
// Launches the browser, When the restore data is loaded, and the user chooses
// to restore.
void LauncherBrowserWhenReady();
private:
// KeyedService overrides.
void Shutdown() override;
......
......@@ -20,6 +20,12 @@ FullRestoreServiceFactory* FullRestoreServiceFactory::GetInstance() {
return instance.get();
}
// static
FullRestoreService* FullRestoreServiceFactory::GetForProfile(Profile* profile) {
return static_cast<FullRestoreService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
FullRestoreServiceFactory::FullRestoreServiceFactory()
: BrowserContextKeyedServiceFactory(
"FullRestoreService",
......
......@@ -21,6 +21,8 @@ class FullRestoreServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static FullRestoreServiceFactory* GetInstance();
static FullRestoreService* GetForProfile(Profile* profile);
private:
friend base::NoDestructor<FullRestoreServiceFactory>;
......
......@@ -13,6 +13,7 @@
#include <utility>
#include <vector>
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/notification_utils.h"
#include "base/base_paths.h"
#include "base/bind.h"
......@@ -42,6 +43,7 @@
#include "chrome/browser/chromeos/boot_times_recorder.h"
#include "chrome/browser/chromeos/child_accounts/child_policy_observer.h"
#include "chrome/browser/chromeos/first_run/first_run.h"
#include "chrome/browser/chromeos/full_restore/full_restore_service.h"
#include "chrome/browser/chromeos/logging.h"
#include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
#include "chrome/browser/chromeos/login/chrome_restart_request.h"
......@@ -2104,17 +2106,8 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile,
VLOG(1) << "Launching browser...";
TRACE_EVENT0("login", "LaunchBrowser");
if (should_launch_browser_) {
StartupBrowserCreator browser_creator;
chrome::startup::IsFirstRun first_run =
::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN;
browser_creator.LaunchBrowser(
*base::CommandLine::ForCurrentProcess(), profile, base::FilePath(),
chrome::startup::IS_PROCESS_STARTUP, first_run,
std::make_unique<LaunchModeRecorder>());
}
if (should_launch_browser_ && !IsFullRestoreEnabled(profile))
LaunchBrowser(profile);
if (HatsNotificationController::ShouldShowSurveyToProfile(profile))
hats_notification_controller_ = new HatsNotificationController(profile);
......@@ -2141,8 +2134,14 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile,
ShowNotificationsIfNeeded(profile);
if (should_launch_browser_) {
MaybeLaunchSettings(profile);
if (IsFullRestoreEnabled(profile)) {
full_restore::FullRestoreService::GetForProfile(profile)
->LauncherBrowserWhenReady();
} else {
MaybeLaunchSettings(profile);
}
}
StartAccountManagerMigration(profile);
}
......@@ -2167,6 +2166,18 @@ void UserSessionManager::RespectLocalePreferenceWrapper(
}
}
void UserSessionManager::LaunchBrowser(Profile* profile) {
StartupBrowserCreator browser_creator;
chrome::startup::IsFirstRun first_run =
::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN;
browser_creator.LaunchBrowser(*base::CommandLine::ForCurrentProcess(),
profile, base::FilePath(),
chrome::startup::IS_PROCESS_STARTUP, first_run,
std::make_unique<LaunchModeRecorder>());
}
// static
void UserSessionManager::RunCallbackOnLocaleLoaded(
base::OnceClosure callback,
......@@ -2299,4 +2310,10 @@ void UserSessionManager::WaitForEasyUnlockKeyOpsFinished(
easy_unlock_key_ops_finished_callbacks_.push_back(std::move(callback));
}
bool UserSessionManager::IsFullRestoreEnabled(Profile* profile) {
auto* full_restore_service =
full_restore::FullRestoreService::GetForProfile(profile);
return full_restore_service != nullptr;
}
} // namespace chromeos
......@@ -251,6 +251,8 @@ class UserSessionManager
void RespectLocalePreferenceWrapper(Profile* profile,
base::OnceClosure callback);
void LaunchBrowser(Profile* profile);
// Restarts Chrome if needed. This happens when user session has custom
// flags/switches enabled. Another case when owner has setup custom flags,
// they are applied on login screen as well but not to user session.
......@@ -516,6 +518,8 @@ class UserSessionManager
void NotifyEasyUnlockKeyOpsFinished();
bool IsFullRestoreEnabled(Profile* profile);
UserSessionManagerDelegate* delegate_;
// Used to listen to network changes.
......
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