Skip to content

Commit

Permalink
saved_desks: Hooking up DeskTemplateType when saving a template.
Browse files Browse the repository at this point in the history
Currently, all calls are producing a template so there are no semantic
changes. When the UI for capturing saved desks is ready, it will be able
to use the updated functions.

Bug: 1310311
Change-Id: I6191e0fc19ce1036bb6dcbfe7a842b77010671e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3566438
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Commit-Queue: Daniel Andersson <dandersson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988738}
  • Loading branch information
Daniel Andersson authored and Chromium LUCI CQ committed Apr 4, 2022
1 parent 1dbc44d commit 5cab0b5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ash/wm/desks/desks_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,13 @@ void DesksController::SendToDeskAtIndex(aura::Window* window, int desk_index) {

void DesksController::CaptureActiveDeskAsTemplate(
GetDeskTemplateCallback callback,
DeskTemplateType template_type,
aura::Window* root_window_to_show) const {
DCHECK(current_account_id_.is_valid());

restore_data_collector_.CaptureActiveDeskAsTemplate(
std::move(callback), base::UTF16ToUTF8(active_desk_->name()),
root_window_to_show);
std::move(callback), template_type,
base::UTF16ToUTF8(active_desk_->name()), root_window_to_show);
}

void DesksController::CreateNewDeskForTemplate(
Expand Down
14 changes: 7 additions & 7 deletions ash/wm/desks/desks_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ class ASH_EXPORT DesksController : public chromeos::DesksHelper,
int GetNumberOfDesks() const override;
void SendToDeskAtIndex(aura::Window* window, int desk_index) override;

// Captures the active desk and returns it as a desk template containing
// necessary information that can be used to create a same desk via provided
// `callback`, `root_window_to_show` is used to determine which monitor to
// show template related dialog.
void CaptureActiveDeskAsTemplate(
GetDeskTemplateCallback callback,
aura::Window* root_window_to_show = nullptr) const;
// Captures the active desk and returns it as a desk template (of type
// `template_type`) containing necessary information that can be used to
// create a same desk via provided `callback`, `root_window_to_show` is used
// to determine which monitor to show template related dialog.
void CaptureActiveDeskAsTemplate(GetDeskTemplateCallback callback,
DeskTemplateType template_type,
aura::Window* root_window_to_show) const;

// Creates (and optionally activates) a new desk for a template with name
// `template_name` or `template_name ({counter})` to resolve naming
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/desks/templates/desks_templates_presenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ void DesksTemplatesPresenter::LaunchDeskTemplate(
}

void DesksTemplatesPresenter::MaybeSaveActiveDeskAsTemplate(
DeskTemplateType template_type,
aura::Window* root_window_to_show) {
DesksController::Get()->CaptureActiveDeskAsTemplate(
base::BindOnce(&DesksTemplatesPresenter::SaveOrUpdateDeskTemplate,
weak_ptr_factory_.GetWeakPtr(),
/*is_update=*/false, root_window_to_show),
root_window_to_show);
template_type, root_window_to_show);
}

void DesksTemplatesPresenter::SaveOrUpdateDeskTemplate(
Expand Down
6 changes: 4 additions & 2 deletions ash/wm/desks/templates/desks_templates_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace ash {

class DeskTemplate;
class OverviewSession;
enum class DeskTemplateType;

// DesksTemplatesPresenter is the presenter for the desks templates UI. It
// handles all calls to the model, and lets the UI know what to show or update.
Expand Down Expand Up @@ -61,11 +62,12 @@ class ASH_EXPORT DesksTemplatesPresenter : desks_storage::DeskModelObserver {
base::TimeDelta delay,
aura::Window* root_window);

// Calls the DeskModel to capture the active desk as a template entry, with a
// Calls the DeskModel to capture the active desk as a `template_type`, with a
// callback to `OnAddOrUpdateEntry`. If there are unsupported apps on the
// active desk, a dialog will open up and we may or may not save the desk
// asynchronously based on the user's decision.
void MaybeSaveActiveDeskAsTemplate(aura::Window* root_window_to_show);
void MaybeSaveActiveDeskAsTemplate(DeskTemplateType template_type,
aura::Window* root_window_to_show);

// Saves or updates the `desk_template` to the model.
void SaveOrUpdateDeskTemplate(bool is_update,
Expand Down
3 changes: 3 additions & 0 deletions ash/wm/desks/templates/restore_data_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RestoreDataCollector::~RestoreDataCollector() = default;

void RestoreDataCollector::CaptureActiveDeskAsTemplate(
GetDeskTemplateCallback callback,
DeskTemplateType template_type,
const std::string& template_name,
aura::Window* root_window_to_show) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Expand All @@ -44,6 +45,7 @@ void RestoreDataCollector::CaptureActiveDeskAsTemplate(
if (root_window_to_show)
window_tracker_.Add(root_window_to_show);
call.root_window_to_show = root_window_to_show;
call.template_type = template_type;
call.template_name = template_name;

auto* const shell = Shell::Get();
Expand Down Expand Up @@ -126,6 +128,7 @@ void RestoreDataCollector::SendDeskTemplate(uint32_t serial) {
base::GUID::GenerateRandomV4().AsLowercaseString(),
DeskTemplateSource::kUser, call.template_name, base::Time::Now());
desk_template->set_desk_restore_data(std::move(call.data));
desk_template->set_type(call.template_type);

if (!call.unsupported_apps.empty() &&
Shell::Get()->overview_controller()->InOverviewSession()) {
Expand Down
3 changes: 3 additions & 0 deletions ash/wm/desks/templates/restore_data_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Window;
namespace ash {

class DeskTemplate;
enum class DeskTemplateType;

// Collects `AppLaunchData` from all applications that are currently active, and
// returns it in form of `DeskTemplate` record.
Expand All @@ -43,6 +44,7 @@ class RestoreDataCollector {
// Captures the active desk and returns it as a `DeskTemplate` object via the
// `callback`.
void CaptureActiveDeskAsTemplate(GetDeskTemplateCallback callback,
DeskTemplateType template_type,
const std::string& template_name,
aura::Window* root_window_to_show);

Expand All @@ -54,6 +56,7 @@ class RestoreDataCollector {
Call& operator=(Call&&);
~Call();

DeskTemplateType template_type;
std::string template_name;
aura::Window* root_window_to_show;
std::vector<aura::Window*> unsupported_apps;
Expand Down
1 change: 1 addition & 0 deletions ash/wm/overview/overview_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,7 @@ void OverviewGrid::UpdateCannotSnapWarningVisibility(bool animate) {

void OverviewGrid::OnSaveDeskAsTemplateButtonPressed() {
DesksTemplatesPresenter::Get()->MaybeSaveActiveDeskAsTemplate(
DeskTemplateType::kTemplate,
save_desk_as_template_widget_->GetNativeWindow()->GetRootWindow());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ void DesksTemplatesClient::CaptureActiveDeskAndSaveTemplate(

desks_controller_->CaptureActiveDeskAsTemplate(
base::BindOnce(&DesksTemplatesClient::OnCapturedDeskTemplate,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
ash::DeskTemplateType::kTemplate,
/*root_window_to_show=*/nullptr);
}

void DesksTemplatesClient::UpdateDeskTemplate(
Expand Down

0 comments on commit 5cab0b5

Please sign in to comment.