Commit 4bb5dd0e authored by David Black's avatar David Black Committed by Commit Bot

Initiate screen context request.

Screen context requests are initiated and sent to the server when:
- UI is shown (when not using stylus input modality).
- Metalayer session is complete (when using stylus input modality).

Still TODO:
- Initially inactivate widget and activate after request callback runs.
- Cache/show server response.

Bug: b:111008970
Change-Id: Ibc2934be60bccc62e63a523384c2739a4ecfdabd
Reviewed-on: https://chromium-review.googlesource.com/1129390
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573446}
parent b2460031
......@@ -118,12 +118,13 @@ AssistantController::AssistantController()
assistant_ui_controller_->SetAssistantInteractionController(
assistant_interaction_controller_.get());
// Observe HighlighterController for region selections.
assistant_ui_controller_->AddModelObserver(this);
Shell::Get()->highlighter_controller()->AddObserver(this);
}
AssistantController::~AssistantController() {
Shell::Get()->highlighter_controller()->RemoveObserver(this);
assistant_ui_controller_->RemoveModelObserver(this);
// Explicitly clean up the circular dependency in the sub-controllers.
assistant_interaction_controller_->SetAssistantUiController(nullptr);
......@@ -256,10 +257,27 @@ void AssistantController::DownloadImage(
assistant_image_downloader_->Download(account_id, url, std::move(callback));
}
void AssistantController::OnUiVisibilityChanged(bool visible,
AssistantSource source) {
// We don't initiate a contextual query for caching if the UI is being hidden.
if (!visible)
return;
// We don't initiate a contextual query for caching if we are using stylus
// input modality because we will do so on metalayer session complete.
if (assistant_interaction_controller_->model()->input_modality() ==
InputModality::kStylus) {
return;
}
// TODO(dmblack): Activate the Assistant UI when the callback is run.
assistant_->RequestScreenContext(gfx::Rect(), base::DoNothing());
}
void AssistantController::OnHighlighterSelectionRecognized(
const gfx::Rect& rect) {
// TODO(muyuanli): Request screen context for |rect|.
NOTIMPLEMENTED();
// TODO(dmblack): Activate the Assistant UI when the callback is run.
assistant_->RequestScreenContext(rect, base::DoNothing());
}
void AssistantController::OnOpenUrlFromTab(const GURL& url) {
......
......@@ -10,6 +10,7 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ash/highlighter/highlighter_controller.h"
#include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_image_downloader.mojom.h"
......@@ -37,6 +38,7 @@ class AssistantUiController;
class ASH_EXPORT AssistantController
: public mojom::AssistantController,
public AssistantUiModelObserver,
public HighlighterController::Observer,
public mojom::ManagedWebContentsOpenUrlDelegate {
public:
......@@ -85,6 +87,9 @@ class ASH_EXPORT AssistantController
void RequestScreenshot(const gfx::Rect& rect,
RequestScreenshotCallback callback) override;
// AssistantUiModelObserver:
void OnUiVisibilityChanged(bool visible, AssistantSource source) override;
// HighlighterController::Observer:
void OnHighlighterSelectionRecognized(const gfx::Rect& rect) override;
......
......@@ -199,6 +199,8 @@ void AssistantUiController::ShowUi(AssistantSource source) {
container_view_->GetWidget()->AddObserver(this);
}
// TODO(dmblack): Initially show UI as inactive and only activate after the
// screen context has been sent to the server.
container_view_->GetWidget()->Show();
assistant_ui_model_.SetVisible(true, source);
}
......
......@@ -178,15 +178,17 @@ void AssistantManagerServiceImpl::RequestScreenContext(
return;
}
// We wait for the closure to execute twice: once for the screenshot and once
// for the view hierarchy.
auto on_done = base::BarrierClosure(
2, // We wait for the closure execute twice: 1 for screenshot and 1 for
// view hierarchy.
base::BindOnce(
&AssistantManagerServiceImpl::SendContextQueryAndRunCallback,
weak_factory_.GetWeakPtr(), std::move(callback)));
2, base::BindOnce(
&AssistantManagerServiceImpl::SendContextQueryAndRunCallback,
weak_factory_.GetWeakPtr(), std::move(callback)));
service_->client()->RequestAssistantStructure(
base::BindOnce(&AssistantManagerServiceImpl::OnAssistantStructureReceived,
weak_factory_.GetWeakPtr(), on_done));
// TODO(muyuanli): handle metalayer and grab only part of the screen.
service_->assistant_controller()->RequestScreenshot(
region, base::BindOnce(
......
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