Commit f6bedc98 authored by David Black's avatar David Black Committed by Commit Bot

Adds auto-close timer.

When hidden, we automatically close ourselves after 5 min.

Bug: b:113129833
Change-Id: I2edb3a73cc31e93234eb7747a91f4314dde56943
Reviewed-on: https://chromium-review.googlesource.com/1188759
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586417}
parent ed2c4514
...@@ -22,6 +22,9 @@ namespace ash { ...@@ -22,6 +22,9 @@ namespace ash {
namespace { namespace {
// When hidden, Assistant will automatically close after |kAutoCloseThreshold|.
constexpr base::TimeDelta kAutoCloseThreshold = base::TimeDelta::FromMinutes(5);
// Toast ----------------------------------------------------------------------- // Toast -----------------------------------------------------------------------
constexpr int kToastDurationMs = 2500; constexpr int kToastDurationMs = 2500;
...@@ -40,7 +43,7 @@ void ShowToast(const std::string& id, int message_id) { ...@@ -40,7 +43,7 @@ void ShowToast(const std::string& id, int message_id) {
AssistantUiController::AssistantUiController( AssistantUiController::AssistantUiController(
AssistantController* assistant_controller) AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) { : assistant_controller_(assistant_controller), weak_factory_(this) {
AddModelObserver(this); AddModelObserver(this);
assistant_controller_->AddObserver(this); assistant_controller_->AddObserver(this);
Shell::Get()->highlighter_controller()->AddObserver(this); Shell::Get()->highlighter_controller()->AddObserver(this);
...@@ -215,6 +218,18 @@ void AssistantUiController::OnUiVisibilityChanged( ...@@ -215,6 +218,18 @@ void AssistantUiController::OnUiVisibilityChanged(
? mojom::VoiceInteractionState::RUNNING ? mojom::VoiceInteractionState::RUNNING
: mojom::VoiceInteractionState::STOPPED); : mojom::VoiceInteractionState::STOPPED);
if (new_visibility == AssistantVisibility::kHidden) {
// When hiding the UI, start a timer to automatically close ourselves after
// |kAutoCloseThreshold|. This is to give the user an opportunity to resume
// their previous session before it is automatically finished.
auto_close_timer_.Start(FROM_HERE, kAutoCloseThreshold,
base::BindRepeating(&AssistantUiController::CloseUi,
weak_factory_.GetWeakPtr(),
AssistantSource::kUnspecified));
} else {
auto_close_timer_.Stop();
}
// Metalayer should not be sticky. Disable when the UI is no longer visible. // Metalayer should not be sticky. Disable when the UI is no longer visible.
if (old_visibility == AssistantVisibility::kVisible) if (old_visibility == AssistantVisibility::kVisible)
Shell::Get()->highlighter_controller()->AbortSession(); Shell::Get()->highlighter_controller()->AbortSession();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ash/assistant/ui/dialog_plate/dialog_plate.h" #include "ash/assistant/ui/dialog_plate/dialog_plate.h"
#include "ash/highlighter/highlighter_controller.h" #include "ash/highlighter/highlighter_controller.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/timer/timer.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
namespace chromeos { namespace chromeos {
...@@ -120,6 +121,12 @@ class ASH_EXPORT AssistantUiController ...@@ -120,6 +121,12 @@ class ASH_EXPORT AssistantUiController
AssistantContainerView* container_view_ = AssistantContainerView* container_view_ =
nullptr; // Owned by view hierarchy. nullptr; // Owned by view hierarchy.
// When hidden, Assistant automatically closes itself to finish the previous
// session. We delay this behavior to allow the user an opportunity to resume.
base::OneShotTimer auto_close_timer_;
base::WeakPtrFactory<AssistantUiController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AssistantUiController); DISALLOW_COPY_AND_ASSIGN(AssistantUiController);
}; };
......
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