Add LacrosSaveHandler to restore Lacros windows.
This CL adds the LacrosSaveHandler class to help restore Lacros windows for FullRestoreReadHandler. Modify IsFullRestoreRunning to set 1 minute waiting time for Lacros windows restoration. BUG=1239984 Change-Id: If38c3344027633feb218f1e9bb9977cd247f0fae Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3388311 Reviewed-by: Sammie Quon <sammiequon@chromium.org> Commit-Queue: Nancy Wang <nancylingwang@chromium.org> Cr-Commit-Position: refs/heads/main@{#960774}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7fd8f3e533
commit
1b68b31ee8
@ -31,6 +31,8 @@ component("app_restore") {
|
||||
"full_restore_save_handler.h",
|
||||
"full_restore_utils.cc",
|
||||
"full_restore_utils.h",
|
||||
"lacros_read_handler.cc",
|
||||
"lacros_read_handler.h",
|
||||
"lacros_save_handler.cc",
|
||||
"lacros_save_handler.h",
|
||||
"restore_data.cc",
|
||||
|
@ -209,10 +209,11 @@ void OnLacrosWindowAdded(aura::Window* const window,
|
||||
return;
|
||||
}
|
||||
|
||||
full_restore::FullRestoreReadHandler::GetInstance()
|
||||
->OnLacrosBrowserWindowAdded(window, restored_browser_session_id);
|
||||
|
||||
full_restore::FullRestoreSaveHandler::GetInstance()
|
||||
->OnLacrosBrowserWindowAdded(window, browser_session_id);
|
||||
|
||||
// TODO(https://crbug.com/1239984): Restore Lacros windows.
|
||||
}
|
||||
|
||||
} // namespace app_restore
|
||||
|
@ -15,9 +15,11 @@
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "components/app_restore/app_launch_info.h"
|
||||
#include "components/app_restore/desk_template_read_handler.h"
|
||||
#include "components/app_restore/features.h"
|
||||
#include "components/app_restore/full_restore_file_handler.h"
|
||||
#include "components/app_restore/full_restore_info.h"
|
||||
#include "components/app_restore/full_restore_save_handler.h"
|
||||
#include "components/app_restore/lacros_read_handler.h"
|
||||
#include "components/app_restore/restore_data.h"
|
||||
#include "components/app_restore/window_info.h"
|
||||
#include "components/app_restore/window_properties.h"
|
||||
@ -33,6 +35,7 @@ namespace {
|
||||
// apps.
|
||||
constexpr base::TimeDelta kFullRestoreEstimateDuration = base::Seconds(5);
|
||||
constexpr base::TimeDelta kFullRestoreARCEstimateDuration = base::Minutes(5);
|
||||
constexpr base::TimeDelta kFullRestoreLacrosEstimateDuration = base::Minutes(1);
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -139,6 +142,15 @@ void FullRestoreReadHandler::OnTaskDestroyed(int32_t task_id) {
|
||||
arc_read_handler_->OnTaskDestroyed(task_id);
|
||||
}
|
||||
|
||||
void FullRestoreReadHandler::OnLacrosBrowserWindowAdded(
|
||||
aura::Window* const window,
|
||||
uint32_t restored_browser_session_id) {
|
||||
if (lacros_read_handler_) {
|
||||
lacros_read_handler_->OnLacrosBrowserWindowAdded(
|
||||
window, restored_browser_session_id);
|
||||
}
|
||||
}
|
||||
|
||||
void FullRestoreReadHandler::SetActiveProfilePath(
|
||||
const base::FilePath& profile_path) {
|
||||
active_profile_path_ = profile_path;
|
||||
@ -307,11 +319,21 @@ bool FullRestoreReadHandler::IsFullRestoreRunning() const {
|
||||
return false;
|
||||
|
||||
base::TimeDelta elapsed_time = base::TimeTicks::Now() - it->second;
|
||||
|
||||
// We estimate that full restore is still running if it has been less than
|
||||
// five seconds since it started, or five minutes if there is at least one ARC
|
||||
// app.
|
||||
return arc_read_handler_ ? elapsed_time < kFullRestoreARCEstimateDuration
|
||||
: elapsed_time < kFullRestoreEstimateDuration;
|
||||
// five minutes since it started, when there is at least one ARC app, since it
|
||||
// might take long time to boot ARC.
|
||||
if (arc_read_handler_)
|
||||
return elapsed_time < kFullRestoreARCEstimateDuration;
|
||||
|
||||
// We estimate that full restore is still running if it has been less than
|
||||
// one minute since it started, when Lacros is available.
|
||||
if (lacros_read_handler_)
|
||||
return elapsed_time < kFullRestoreLacrosEstimateDuration;
|
||||
|
||||
// We estimate that full restore is still running if it has been less than
|
||||
// five seconds since it started.
|
||||
return elapsed_time < kFullRestoreEstimateDuration;
|
||||
}
|
||||
|
||||
void FullRestoreReadHandler::AddChromeBrowserLaunchInfoForTesting(
|
||||
@ -354,6 +376,11 @@ void FullRestoreReadHandler::OnGetRestoreData(
|
||||
if (restore_data) {
|
||||
profile_path_to_restore_data_[profile_path] = restore_data->Clone();
|
||||
|
||||
if (::full_restore::features::IsFullRestoreForLacrosEnabled()) {
|
||||
lacros_read_handler_ =
|
||||
std::make_unique<app_restore::LacrosReadHandler>(profile_path);
|
||||
}
|
||||
|
||||
for (auto it = restore_data->app_id_to_launch_list().begin();
|
||||
it != restore_data->app_id_to_launch_list().end(); it++) {
|
||||
const std::string& app_id = it->first;
|
||||
@ -370,6 +397,10 @@ void FullRestoreReadHandler::OnGetRestoreData(
|
||||
} else {
|
||||
window_id_to_app_restore_info_[window_id] =
|
||||
std::make_pair(profile_path, app_id);
|
||||
// TODO(crbug.com/1239984): Remove restore data from
|
||||
// `lacros_read_handler_` for ash browser apps.
|
||||
if (lacros_read_handler_ && app_id != extension_misc::kChromeAppId)
|
||||
lacros_read_handler_->AddRestoreData(app_id, window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
namespace app_restore {
|
||||
struct AppLaunchInfo;
|
||||
class LacrosReadHandler;
|
||||
class RestoreData;
|
||||
struct WindowInfo;
|
||||
} // namespace app_restore
|
||||
@ -92,6 +93,11 @@ class COMPONENT_EXPORT(APP_RESTORE) FullRestoreReadHandler
|
||||
int32_t session_id) override;
|
||||
void OnTaskDestroyed(int32_t task_id) override;
|
||||
|
||||
// Invoked when Lacros window is created. `restored_browser_session_id` is the
|
||||
// restored browser session id.
|
||||
void OnLacrosBrowserWindowAdded(aura::Window* const window,
|
||||
uint32_t restored_browser_session_id);
|
||||
|
||||
void SetActiveProfilePath(const base::FilePath& profile_path);
|
||||
|
||||
// Sets whether we should check the restore data for `profile_path`. If the
|
||||
@ -210,6 +216,8 @@ class COMPONENT_EXPORT(APP_RESTORE) FullRestoreReadHandler
|
||||
|
||||
std::unique_ptr<app_restore::ArcReadHandler> arc_read_handler_;
|
||||
|
||||
std::unique_ptr<app_restore::LacrosReadHandler> lacros_read_handler_;
|
||||
|
||||
// Records whether we need to check the restore data for the profile path. If
|
||||
// the profile path is recorded, we should check the restore data. Otherwise,
|
||||
// we don't need to check the restore data, because the restore process hasn't
|
||||
|
34
components/app_restore/lacros_read_handler.cc
Normal file
34
components/app_restore/lacros_read_handler.cc
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/app_restore/lacros_read_handler.h"
|
||||
|
||||
#include "ash/constants/app_types.h"
|
||||
#include "components/app_restore/app_restore_utils.h"
|
||||
#include "ui/aura/client/aura_constants.h"
|
||||
#include "ui/aura/window.h"
|
||||
|
||||
namespace app_restore {
|
||||
|
||||
LacrosReadHandler::LacrosReadHandler(const base::FilePath& profile_path)
|
||||
: profile_path_(profile_path) {}
|
||||
|
||||
LacrosReadHandler::~LacrosReadHandler() = default;
|
||||
|
||||
void LacrosReadHandler::AddRestoreData(const std::string& app_id,
|
||||
int32_t window_id) {
|
||||
restore_window_id_to_app_id_[window_id] = app_id;
|
||||
}
|
||||
|
||||
void LacrosReadHandler::OnLacrosBrowserWindowAdded(
|
||||
aura::Window* const window,
|
||||
uint32_t restored_browser_session_id) {
|
||||
if (window->GetProperty(aura::client::kAppType) ==
|
||||
static_cast<int>(ash::AppType::LACROS)) {
|
||||
lacros_window_id_to_restore_window_id_[app_restore::GetLacrosWindowId(
|
||||
window)] = restored_browser_session_id;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace app_restore
|
52
components/app_restore/lacros_read_handler.h
Normal file
52
components/app_restore/lacros_read_handler.h
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_APP_RESTORE_LACROS_READ_HANDLER_H_
|
||||
#define COMPONENTS_APP_RESTORE_LACROS_READ_HANDLER_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "base/component_export.h"
|
||||
#include "base/files/file_path.h"
|
||||
|
||||
namespace aura {
|
||||
class Window;
|
||||
}
|
||||
|
||||
namespace app_restore {
|
||||
|
||||
// LacrosSaveHandler is a helper class for FullRestoreReadHandler to restore
|
||||
// Lacros windows.
|
||||
// TODO(crbug.com/1239984): Restore Lacros windows.
|
||||
class COMPONENT_EXPORT(APP_RESTORE) LacrosReadHandler {
|
||||
public:
|
||||
LacrosReadHandler(const base::FilePath& profile_path);
|
||||
LacrosReadHandler(const LacrosReadHandler&) = delete;
|
||||
LacrosReadHandler& operator=(const LacrosReadHandler&) = delete;
|
||||
~LacrosReadHandler();
|
||||
|
||||
// Sets `app_id` and `window_id` to `restore_window_id_to_app_id_` to record
|
||||
// that there is a restore data for `app_id` and `window_id`.
|
||||
void AddRestoreData(const std::string& app_id, int32_t window_id);
|
||||
|
||||
// Invoked when Lacros window is created. `restored_browser_session_id` is the
|
||||
// restored browser session id.
|
||||
void OnLacrosBrowserWindowAdded(aura::Window* const window,
|
||||
uint32_t restored_browser_session_id);
|
||||
|
||||
private:
|
||||
// The user profile path for Lacros windows.
|
||||
base::FilePath profile_path_;
|
||||
|
||||
// The map from the restore window id to the app id for Lacros windows.
|
||||
std::map<int32_t, std::string> restore_window_id_to_app_id_;
|
||||
|
||||
// The map from the lacros window id to the restore window id for browser
|
||||
// windows.
|
||||
std::map<std::string, int32_t> lacros_window_id_to_restore_window_id_;
|
||||
};
|
||||
|
||||
} // namespace app_restore
|
||||
|
||||
#endif // COMPONENTS_APP_RESTORE_LACROS_READ_HANDLER_H_
|
@ -22,8 +22,6 @@ namespace full_restore {
|
||||
|
||||
// LacrosSaveHandler is a helper class for FullRestoreSaveHandler to handle
|
||||
// Lacros windows special cases, e.g. Lacros window id, etc.
|
||||
// TODO(crbug.com/1239984):
|
||||
// 1. Use the browser session id as the window id.
|
||||
class COMPONENT_EXPORT(APP_RESTORE) LacrosSaveHandler {
|
||||
public:
|
||||
explicit LacrosSaveHandler(const base::FilePath& profile_path);
|
||||
|
Reference in New Issue
Block a user