Commit 6ad04657 authored by Nancy Wang's avatar Nancy Wang Committed by Chromium LUCI CQ

Implement the SaveWindowInfo interface.

Add the window property kWindowIdKey as the window id for the full
restore data.

Implement the SaveWindowInfo interface to save the browser session id
as the window id.

BUG=1146900

Change-Id: I4fbe4fe85ec5bf0a15e4576dd7d3d565b830c7aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597519
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840845}
parent f7fe9c75
...@@ -2709,6 +2709,7 @@ static_library("ui") { ...@@ -2709,6 +2709,7 @@ static_library("ui") {
"//components/captive_portal/core", "//components/captive_portal/core",
"//components/consent_auditor:consent_auditor", "//components/consent_auditor:consent_auditor",
"//components/exo", "//components/exo",
"//components/full_restore",
"//components/login", "//components/login",
"//components/metrics/structured:structured_events", "//components/metrics/structured:structured_events",
"//components/services/app_service/public/cpp:app_file_handling", "//components/services/app_service/public/cpp:app_file_handling",
......
...@@ -3,6 +3,9 @@ specific_include_rules = { ...@@ -3,6 +3,9 @@ specific_include_rules = {
"browser_non_client_frame_view_chromeos\.*": [ "browser_non_client_frame_view_chromeos\.*": [
"+ash", "+ash",
], ],
"browser_frame\.cc": [
"+components/full_restore/full_restore_utils.h",
],
"browser_frame_ash\.*": [ "browser_frame_ash\.*": [
"+ash", "+ash",
], ],
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "ui/views/widget/native_widget.h" #include "ui/views/widget/native_widget.h"
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/full_restore/full_restore_utils.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#endif #endif
...@@ -81,6 +82,10 @@ void BrowserFrame::InitBrowserFrame() { ...@@ -81,6 +82,10 @@ void BrowserFrame::InitBrowserFrame() {
views::Widget::InitParams params = native_browser_frame_->GetWidgetParams(); views::Widget::InitParams params = native_browser_frame_->GetWidgetParams();
params.name = "BrowserFrame"; params.name = "BrowserFrame";
params.delegate = browser_view_; params.delegate = browser_view_;
#if BUILDFLAG(IS_CHROMEOS_ASH)
params.init_properties_container.SetProperty(
full_restore::kWindowIdKey, browser_view_->browser()->session_id().id());
#endif
if (browser_view_->browser()->is_type_normal() || if (browser_view_->browser()->is_type_normal() ||
browser_view_->browser()->is_type_devtools() || browser_view_->browser()->is_type_devtools() ||
browser_view_->browser()->is_type_app()) { browser_view_->browser()->is_type_app()) {
......
...@@ -34,6 +34,7 @@ component("full_restore") { ...@@ -34,6 +34,7 @@ component("full_restore") {
"//components/account_id:account_id", "//components/account_id:account_id",
"//components/services/app_service/public/cpp:intents", "//components/services/app_service/public/cpp:intents",
"//components/services/app_service/public/mojom", "//components/services/app_service/public/mojom",
"//components/sessions",
"//ui/aura", "//ui/aura",
] ]
} }
......
...@@ -5,3 +5,9 @@ include_rules = [ ...@@ -5,3 +5,9 @@ include_rules = [
"+components/services/app_service/public", "+components/services/app_service/public",
"+ui", "+ui",
] ]
specific_include_rules = {
"full_restore_save_handler\.cc": [
"+components/sessions/core/session_id.h",
],
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/full_restore/full_restore_save_handler.h" #include "components/full_restore/full_restore_save_handler.h"
#include "ash/public/cpp/app_types.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
...@@ -11,7 +12,12 @@ ...@@ -11,7 +12,12 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "components/full_restore/app_launch_info.h" #include "components/full_restore/app_launch_info.h"
#include "components/full_restore/full_restore_file_handler.h" #include "components/full_restore/full_restore_file_handler.h"
#include "components/full_restore/full_restore_utils.h"
#include "components/full_restore/restore_data.h" #include "components/full_restore/restore_data.h"
#include "components/full_restore/window_info.h"
#include "components/sessions/core/session_id.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
namespace full_restore { namespace full_restore {
...@@ -33,22 +39,54 @@ FullRestoreSaveHandler::FullRestoreSaveHandler() = default; ...@@ -33,22 +39,54 @@ FullRestoreSaveHandler::FullRestoreSaveHandler() = default;
FullRestoreSaveHandler::~FullRestoreSaveHandler() = default; FullRestoreSaveHandler::~FullRestoreSaveHandler() = default;
void FullRestoreSaveHandler::SaveAppLaunchInfo( void FullRestoreSaveHandler::SaveAppLaunchInfo(
const base::FilePath& file_path, const base::FilePath& profile_path,
std::unique_ptr<AppLaunchInfo> app_launch_info) { std::unique_ptr<AppLaunchInfo> app_launch_info) {
if (!app_launch_info) if (!app_launch_info)
return; return;
if (!app_launch_info->id.has_value()) {
// TODO(crbug.com/1146900): Handle ARC app windows.
return;
}
window_id_to_app_restore_info_[app_launch_info->id.value()] =
std::make_pair(profile_path, app_launch_info->app_id);
// Each user should have one full restore file saving the restore data in the // Each user should have one full restore file saving the restore data in the
// profile directory |file_path|. So |app_launch_info| is saved to the restore // profile directory |profile_path|. So |app_launch_info| is saved to the
// data for the user with the profile path |file_path|. // restore data for the user with |profile_path|.
file_path_to_restore_data_[file_path].AddAppLaunchInfo( profile_path_to_restore_data_[profile_path].AddAppLaunchInfo(
std::move(app_launch_info)); std::move(app_launch_info));
should_update_.insert(file_path); pending_save_profile_paths_.insert(profile_path);
MaybeStartSaveTimer(); MaybeStartSaveTimer();
} }
void FullRestoreSaveHandler::SaveWindowInfo(const WindowInfo& window_info) {
if (!window_info.window)
return;
int32_t window_id =
window_info.window->GetProperty(::full_restore::kWindowIdKey);
if (window_info.window->GetProperty(aura::client::kAppType) ==
static_cast<int>(ash::AppType::ARC_APP)) {
// TODO(crbug.com/1146900): Handle ARC app windows.
return;
}
if (!SessionID::IsValidValue(window_id))
return;
auto it = window_id_to_app_restore_info_.find(window_id);
if (it == window_id_to_app_restore_info_.end())
return;
profile_path_to_restore_data_[it->second.first].ModifyWindowInfo(
it->second.second, window_id, window_info);
}
void FullRestoreSaveHandler::MaybeStartSaveTimer() { void FullRestoreSaveHandler::MaybeStartSaveTimer() {
if (!save_timer_.IsRunning() && save_running_.empty()) { if (!save_timer_.IsRunning() && save_running_.empty()) {
save_timer_.Start(FROM_HERE, kSaveDelay, save_timer_.Start(FROM_HERE, kSaveDelay,
...@@ -58,20 +96,20 @@ void FullRestoreSaveHandler::MaybeStartSaveTimer() { ...@@ -58,20 +96,20 @@ void FullRestoreSaveHandler::MaybeStartSaveTimer() {
} }
void FullRestoreSaveHandler::Save() { void FullRestoreSaveHandler::Save() {
if (should_update_.empty()) if (pending_save_profile_paths_.empty())
return; return;
for (const auto& file_path : should_update_) { for (const auto& file_path : pending_save_profile_paths_) {
save_running_.insert(file_path); save_running_.insert(file_path);
BackendTaskRunner(file_path)->PostTaskAndReply( BackendTaskRunner(file_path)->PostTaskAndReply(
FROM_HERE, FROM_HERE,
base::BindOnce(&FullRestoreFileHandler::WriteToFile, base::BindOnce(&FullRestoreFileHandler::WriteToFile,
GetFileHandler(file_path), GetFileHandler(file_path),
file_path_to_restore_data_[file_path].Clone()), profile_path_to_restore_data_[file_path].Clone()),
base::BindOnce(&FullRestoreSaveHandler::OnSaveFinished, base::BindOnce(&FullRestoreSaveHandler::OnSaveFinished,
weak_factory_.GetWeakPtr(), file_path)); weak_factory_.GetWeakPtr(), file_path));
} }
should_update_.clear(); pending_save_profile_paths_.clear();
} }
void FullRestoreSaveHandler::OnSaveFinished(const base::FilePath& file_path) { void FullRestoreSaveHandler::OnSaveFinished(const base::FilePath& file_path) {
...@@ -80,12 +118,12 @@ void FullRestoreSaveHandler::OnSaveFinished(const base::FilePath& file_path) { ...@@ -80,12 +118,12 @@ void FullRestoreSaveHandler::OnSaveFinished(const base::FilePath& file_path) {
FullRestoreFileHandler* FullRestoreSaveHandler::GetFileHandler( FullRestoreFileHandler* FullRestoreSaveHandler::GetFileHandler(
const base::FilePath& file_path) { const base::FilePath& file_path) {
if (file_path_to_file_handler_.find(file_path) == if (profile_path_to_file_handler_.find(file_path) ==
file_path_to_file_handler_.end()) { profile_path_to_file_handler_.end()) {
file_path_to_file_handler_[file_path] = profile_path_to_file_handler_[file_path] =
base::MakeRefCounted<FullRestoreFileHandler>(file_path); base::MakeRefCounted<FullRestoreFileHandler>(file_path);
} }
return file_path_to_file_handler_[file_path].get(); return profile_path_to_file_handler_[file_path].get();
} }
base::SequencedTaskRunner* FullRestoreSaveHandler::BackendTaskRunner( base::SequencedTaskRunner* FullRestoreSaveHandler::BackendTaskRunner(
......
...@@ -24,6 +24,7 @@ namespace full_restore { ...@@ -24,6 +24,7 @@ namespace full_restore {
struct AppLaunchInfo; struct AppLaunchInfo;
class FullRestoreFileHandler; class FullRestoreFileHandler;
class RestoreData; class RestoreData;
struct WindowInfo;
// FullRestoreSaveHandler is responsible for writing both the app launch // FullRestoreSaveHandler is responsible for writing both the app launch
// information and the app window information to disk. FullRestoreSaveHandler // information and the app window information to disk. FullRestoreSaveHandler
...@@ -41,15 +42,18 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreSaveHandler { ...@@ -41,15 +42,18 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreSaveHandler {
FullRestoreSaveHandler(const FullRestoreSaveHandler&) = delete; FullRestoreSaveHandler(const FullRestoreSaveHandler&) = delete;
FullRestoreSaveHandler& operator=(const FullRestoreSaveHandler&) = delete; FullRestoreSaveHandler& operator=(const FullRestoreSaveHandler&) = delete;
// Save |app_launch_info| to the full restore file in |profile_dir|. // Save |app_launch_info| to the full restore file in |profile_path|.
void SaveAppLaunchInfo(const base::FilePath& profile_dir, void SaveAppLaunchInfo(const base::FilePath& profile_path,
std::unique_ptr<AppLaunchInfo> app_launch_info); std::unique_ptr<AppLaunchInfo> app_launch_info);
// Save |window_info| to |profile_path_to_restore_data_|.
void SaveWindowInfo(const WindowInfo& window_info);
private: private:
// Starts the timer that invokes Save (if timer isn't already running). // Starts the timer that invokes Save (if timer isn't already running).
void MaybeStartSaveTimer(); void MaybeStartSaveTimer();
// Passes |file_path_to_file_handler_| to the backend for saving. // Passes |profile_path_to_restore_data_| to the backend for saving.
void Save(); void Save();
// Invoked when write to file operation for |file_path| is finished. // Invoked when write to file operation for |file_path| is finished.
...@@ -60,16 +64,22 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreSaveHandler { ...@@ -60,16 +64,22 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreSaveHandler {
base::SequencedTaskRunner* BackendTaskRunner(const base::FilePath& file_path); base::SequencedTaskRunner* BackendTaskRunner(const base::FilePath& file_path);
// Records whether there are new updates for saving between each saving delay. // Records whether there are new updates for saving between each saving delay.
// |ShouldUpdate| is cleared when Save is invoked. // |pending_save_profile_paths_| is cleared when Save is invoked.
std::set<base::FilePath> should_update_; std::set<base::FilePath> pending_save_profile_paths_;
// The restore data for each user's profile. The key is the profile path. // The restore data for each user's profile. The key is the profile path.
std::map<base::FilePath, RestoreData> file_path_to_restore_data_; std::map<base::FilePath, RestoreData> profile_path_to_restore_data_;
// The file handler for each user's profile to write the restore data to the // The file handler for each user's profile to write the restore data to the
// full restore file for each user. The key is the profile path. // full restore file for each user. The key is the profile path.
std::map<base::FilePath, scoped_refptr<FullRestoreFileHandler>> std::map<base::FilePath, scoped_refptr<FullRestoreFileHandler>>
file_path_to_file_handler_; profile_path_to_file_handler_;
// The map from the window id to the full restore file path and the app id.
// The window id is saved in the window property. This map is used to find the
// file path and the app id when save the window info.
std::map<int32_t, std::pair<base::FilePath, std::string>>
window_id_to_app_restore_info_;
// Timer used to delay the restore data writing to the full restore file. // Timer used to delay the restore data writing to the full restore file.
base::OneShotTimer save_timer_; base::OneShotTimer save_timer_;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace full_restore { namespace full_restore {
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kWindowIdKey, 0)
void SaveAppLaunchInfo(const base::FilePath& profile_dir, void SaveAppLaunchInfo(const base::FilePath& profile_dir,
std::unique_ptr<AppLaunchInfo> app_launch_info) { std::unique_ptr<AppLaunchInfo> app_launch_info) {
if (!ash::features::IsFullRestoreEnabled() || !app_launch_info) if (!ash::features::IsFullRestoreEnabled() || !app_launch_info)
...@@ -23,12 +25,11 @@ void SaveAppLaunchInfo(const base::FilePath& profile_dir, ...@@ -23,12 +25,11 @@ void SaveAppLaunchInfo(const base::FilePath& profile_dir,
profile_dir, std::move(app_launch_info)); profile_dir, std::move(app_launch_info));
} }
void SaveWindowInfo(std::unique_ptr<WindowInfo> window_info) { void SaveWindowInfo(const WindowInfo& window_info) {
if (!ash::features::IsFullRestoreEnabled()) if (!ash::features::IsFullRestoreEnabled())
return; return;
// TODO(crbug.com/1146900): Save the window information to the full restore FullRestoreSaveHandler::GetInstance()->SaveWindowInfo(window_info);
// file.
} }
std::unique_ptr<WindowInfo> GetWindowInfo(aura::Window* window) { std::unique_ptr<WindowInfo> GetWindowInfo(aura::Window* window) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/component_export.h" #include "base/component_export.h"
#include "ui/base/class_property.h"
class AccountId; class AccountId;
...@@ -24,6 +25,10 @@ namespace full_restore { ...@@ -24,6 +25,10 @@ namespace full_restore {
struct AppLaunchInfo; struct AppLaunchInfo;
struct WindowInfo; struct WindowInfo;
// A property key to indicate the id for the window to be saved in RestoreData.
COMPONENT_EXPORT(FULL_RESTORE)
extern const ui::ClassProperty<int32_t>* const kWindowIdKey;
// Saves the app launch parameters to the full restore file. // Saves the app launch parameters to the full restore file.
COMPONENT_EXPORT(FULL_RESTORE) COMPONENT_EXPORT(FULL_RESTORE)
void SaveAppLaunchInfo(const base::FilePath& profile_dir, void SaveAppLaunchInfo(const base::FilePath& profile_dir,
...@@ -31,7 +36,7 @@ void SaveAppLaunchInfo(const base::FilePath& profile_dir, ...@@ -31,7 +36,7 @@ void SaveAppLaunchInfo(const base::FilePath& profile_dir,
// Saves the window information to the full restore file. // Saves the window information to the full restore file.
COMPONENT_EXPORT(FULL_RESTORE) COMPONENT_EXPORT(FULL_RESTORE)
void SaveWindowInfo(std::unique_ptr<WindowInfo> window_info); void SaveWindowInfo(const WindowInfo& window_info);
// Gets the window information from the full restore file. // Gets the window information from the full restore file.
COMPONENT_EXPORT(FULL_RESTORE) COMPONENT_EXPORT(FULL_RESTORE)
......
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