Commit 8d3e7cc1 authored by Nancy Wang's avatar Nancy Wang Committed by Chromium LUCI CQ

Implement the GetWindowInfo interface.

Modify FullRestoreReadHandler to get the window information from the
restore data read from the full restore file.

BUG=1146900

Change-Id: Idf18d6ba486011f63e0893ff7c9bb8078b9c9e48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639425
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845483}
parent 2ed086fc
......@@ -8,7 +8,7 @@ include_rules = [
]
specific_include_rules = {
"full_restore_save_handler\.cc": [
"full_restore_(read|save)_handler\.cc": [
"+components/sessions/core/session_id.h",
],
}
......@@ -277,4 +277,25 @@ void AppRestoreData::ModifyWindowInfo(const WindowInfo& window_info) {
window_state_type = window_info.window_state_type.value();
}
std::unique_ptr<WindowInfo> AppRestoreData::GetWindowInfo() {
auto window_info = std::make_unique<WindowInfo>();
if (activation_index.has_value())
window_info->activation_index = activation_index;
if (desk_id.has_value())
window_info->desk_id = desk_id.value();
if (restore_bounds.has_value())
window_info->restore_bounds = restore_bounds.value();
if (current_bounds.has_value())
window_info->current_bounds = current_bounds.value();
if (window_state_type.has_value())
window_info->window_state_type = window_state_type.value();
return window_info;
}
} // namespace full_restore
......@@ -59,6 +59,9 @@ struct COMPONENT_EXPORT(FULL_RESTORE) AppRestoreData {
// Modify the window's information based on |window_info|.
void ModifyWindowInfo(const WindowInfo& window_info);
// Gets the window information.
std::unique_ptr<WindowInfo> GetWindowInfo();
// App launch parameters.
base::Optional<int32_t> event_flag;
base::Optional<int32_t> container;
......
......@@ -12,7 +12,11 @@
#include "base/task/post_task.h"
#include "base/threading/thread_task_runner_handle.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/window_info.h"
#include "components/sessions/core/session_id.h"
#include "ui/aura/window.h"
namespace full_restore {
......@@ -46,13 +50,44 @@ void FullRestoreReadHandler::RemoveApp(const base::FilePath& profile_path,
it->second->RemoveApp(app_id);
}
std::unique_ptr<WindowInfo> FullRestoreReadHandler::GetWindowInfo(
aura::Window* window) {
if (!window)
return nullptr;
// TODO(crbug.com/1146900): Handle ARC app windows.
int32_t restore_window_id =
window->GetProperty(::full_restore::kRestoreWindowIdKey);
if (!SessionID::IsValidValue(restore_window_id))
return nullptr;
auto it = window_id_to_app_restore_info_.find(restore_window_id);
if (it == window_id_to_app_restore_info_.end())
return nullptr;
return profile_path_to_restore_data_[it->second.first]->GetWindowInfo(
it->second.second, restore_window_id);
}
void FullRestoreReadHandler::OnGetRestoreData(
const base::FilePath& profile_path,
Callback callback,
std::unique_ptr<RestoreData> restore_data) {
if (restore_data)
if (restore_data) {
profile_path_to_restore_data_[profile_path] = restore_data->Clone();
for (auto it = restore_data->app_id_to_launch_list().begin();
it != restore_data->app_id_to_launch_list().end(); it++) {
for (auto data_it = it->second.begin(); data_it != it->second.end();
data_it++) {
window_id_to_app_restore_info_[data_it->first] =
std::make_pair(profile_path, it->first);
}
}
}
std::move(callback).Run(std::move(restore_data));
}
......
......@@ -12,6 +12,10 @@
#include "base/component_export.h"
#include "base/memory/weak_ptr.h"
namespace aura {
class Window;
} // namespace aura
namespace base {
class FilePath;
} // namespace base
......@@ -20,6 +24,7 @@ namespace full_restore {
class FullRestoreFileHandler;
class RestoreData;
struct WindowInfo;
// FullRestoreSaveHandler is responsible for reading |RestoreData| from the full
// restore data file. RestoreHandler runs on the main thread and creates
......@@ -47,6 +52,9 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreReadHandler {
// from |profile_path_to_restore_data_| for |profile_path| .
void RemoveApp(const base::FilePath& profile_path, const std::string& app_id);
// Gets the window information for |window|.
std::unique_ptr<WindowInfo> GetWindowInfo(aura::Window* window);
private:
// Invoked when reading the restore data from |profile_path| is finished, and
// calls |callback| to notify that the reading operation is done.
......@@ -58,6 +66,13 @@ class COMPONENT_EXPORT(FULL_RESTORE) FullRestoreReadHandler {
std::map<base::FilePath, std::unique_ptr<RestoreData>>
profile_path_to_restore_data_;
// The map from the window id to the full restore file path and the
// app id. The window id id is saved in the window property
// |kRestoreWindowIdKey|. This map is used to find the file path and the app
// id when get the window info.
std::map<int32_t, std::pair<base::FilePath, std::string>>
window_id_to_app_restore_info_;
base::WeakPtrFactory<FullRestoreReadHandler> weak_factory_{this};
};
......
......@@ -9,6 +9,7 @@
#include "components/account_id/account_id.h"
#include "components/full_restore/app_launch_info.h"
#include "components/full_restore/full_restore_info.h"
#include "components/full_restore/full_restore_read_handler.h"
#include "components/full_restore/full_restore_save_handler.h"
#include "components/full_restore/window_info.h"
......@@ -37,11 +38,7 @@ std::unique_ptr<WindowInfo> GetWindowInfo(aura::Window* window) {
if (!ash::features::IsFullRestoreEnabled())
return nullptr;
auto window_info = std::make_unique<WindowInfo>();
// TODO(crbug.com/1146900): Get the window information from the full restore
// file.
return window_info;
return FullRestoreReadHandler::GetInstance()->GetWindowInfo(window);
}
bool ShouldRestore(const AccountId& account_id) {
......
......@@ -121,4 +121,18 @@ void RestoreData::RemoveApp(const std::string& app_id) {
app_id_to_launch_list_.erase(app_id);
}
std::unique_ptr<WindowInfo> RestoreData::GetWindowInfo(
const std::string& app_id,
int window_id) {
auto it = app_id_to_launch_list_.find(app_id);
if (it == app_id_to_launch_list_.end())
return nullptr;
auto data_it = it->second.find(window_id);
if (data_it == it->second.end())
return nullptr;
return data_it->second->GetWindowInfo();
}
} // namespace full_restore
......@@ -94,6 +94,10 @@ class COMPONENT_EXPORT(FULL_RESTORE) RestoreData {
// Remove the launch list for |app_id|.
void RemoveApp(const std::string& app_id);
// Gets the window information with |window_id| for |app_id|.
std::unique_ptr<WindowInfo> GetWindowInfo(const std::string& app_id,
int window_id);
const AppIdToLaunchList& app_id_to_launch_list() const {
return app_id_to_launch_list_;
}
......
......@@ -356,4 +356,40 @@ TEST_F(RestoreDataTest, ConvertNullData) {
EXPECT_TRUE(app_id_to_launch_list(*restore_data).empty());
}
TEST_F(RestoreDataTest, GetWindowInfo) {
// The app id and window id doesn't exist;
auto window_info = restore_data().GetWindowInfo(kAppId1, kWindowId1);
EXPECT_FALSE(window_info);
// Add the app launch info, but do not modify the window info.
AddAppLaunchInfos();
window_info = restore_data().GetWindowInfo(kAppId1, kWindowId1);
EXPECT_TRUE(window_info);
EXPECT_FALSE(window_info->activation_index.has_value());
EXPECT_FALSE(window_info->desk_id.has_value());
EXPECT_FALSE(window_info->restore_bounds.has_value());
EXPECT_FALSE(window_info->current_bounds.has_value());
EXPECT_FALSE(window_info->window_state_type.has_value());
// Modify the window info.
ModifyWindowInfos();
window_info = restore_data().GetWindowInfo(kAppId1, kWindowId1);
EXPECT_TRUE(window_info);
EXPECT_TRUE(window_info->activation_index.has_value());
EXPECT_EQ(kActivationIndex1, window_info->activation_index.value());
EXPECT_TRUE(window_info->desk_id.has_value());
EXPECT_EQ(kDeskId1, window_info->desk_id.value());
EXPECT_TRUE(window_info->restore_bounds.has_value());
EXPECT_EQ(kRestoreBounds1, window_info->restore_bounds.value());
EXPECT_TRUE(window_info->current_bounds.has_value());
EXPECT_EQ(kCurrentBounds1, window_info->current_bounds.value());
EXPECT_TRUE(window_info->window_state_type.has_value());
EXPECT_EQ(kWindowStateType1, window_info->window_state_type.value());
}
} // namespace 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