Skip to content

Commit

Permalink
[Projector] Add ProjectorControllerClient in chrome/browser
Browse files Browse the repository at this point in the history
There will be some dependencies between ash/ and chrome/browser/
code. An example of these dependencies is speech recognition
that takes place in chrome/browser/speech/cros_speech_recognition*
path. This cl creates a client in chrome for the ProjectorController
in ash to handle the dependencies.

Bug: 1165437
Change-Id: Iacc6ca33a29c394db7276dc224fbe7395af0267e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2699030
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Li Lin <llin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#855028}
  • Loading branch information
yilkal authored and Chromium LUCI CQ committed Feb 18, 2021
1 parent b74ba5b commit 378bd67
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 36 deletions.
4 changes: 2 additions & 2 deletions ash/BUILD.gn
Expand Up @@ -726,8 +726,8 @@ component("ash") {
"policy/policy_recommendation_restorer.h",
"power/hid_battery_util.cc",
"power/hid_battery_util.h",
"projector/projector_controller.cc",
"projector/projector_controller.h",
"projector/projector_controller_impl.cc",
"projector/projector_controller_impl.h",
"projector/projector_feature_pod_controller.cc",
"projector/projector_feature_pod_controller.h",
"projector/projector_metadata_controller.cc",
Expand Down
Expand Up @@ -2,42 +2,48 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"

#include "ash/projector/projector_metadata_controller.h"
#include "ash/projector/projector_ui_controller.h"
#include "ash/public/cpp/projector/projector_client.h"
#include "ash/shell.h"

namespace ash {

ProjectorController::ProjectorController()
ProjectorControllerImpl::ProjectorControllerImpl()
: ui_controller_(std::make_unique<ash::ProjectorUiController>()),
metadata_controller_(
std::make_unique<ash::ProjectorMetadataController>()) {}

ProjectorController::~ProjectorController() = default;
ProjectorControllerImpl::~ProjectorControllerImpl() = default;

void ProjectorController::ShowToolbar() {
void ProjectorControllerImpl::SetClient(ProjectorClient* client) {
client_ = client;
}

void ProjectorControllerImpl::ShowToolbar() {
ui_controller_->ShowToolbar();
}

void ProjectorController::SetCaptionState(bool is_on) {
void ProjectorControllerImpl::SetCaptionState(bool is_on) {
if (is_on == is_caption_on_)
return;

is_caption_on_ = is_on;
}

void ProjectorController::OnRecordingStarted() {
void ProjectorControllerImpl::OnRecordingStarted() {
StartSpeechRecognition();
metadata_controller_->OnRecordingStarted();
}

void ProjectorController::SaveScreencast(
void ProjectorControllerImpl::SaveScreencast(
const base::FilePath& saved_video_path) {
metadata_controller_->SaveMetadata(saved_video_path);
}

void ProjectorController::OnTranscription(
void ProjectorControllerImpl::OnTranscription(
chromeos::machine_learning::mojom::SpeechRecognizerEventPtr
speech_recognizer_event) {
bool is_final = speech_recognizer_event->is_final_result();
Expand Down Expand Up @@ -74,23 +80,33 @@ void ProjectorController::OnTranscription(
}
}

void ProjectorController::SetProjectorUiControllerForTest(
void ProjectorControllerImpl::SetProjectorUiControllerForTest(
std::unique_ptr<ProjectorUiController> ui_controller) {
ui_controller_ = std::move(ui_controller);
}

void ProjectorController::SetProjectorMetadataControllerForTest(
void ProjectorControllerImpl::SetProjectorMetadataControllerForTest(
std::unique_ptr<ProjectorMetadataController> metadata_controller) {
metadata_controller_ = std::move(metadata_controller);
}

void ProjectorController::MarkKeyIdea() {
void ProjectorControllerImpl::MarkKeyIdea() {
metadata_controller_->RecordKeyIdea();
ui_controller_->OnKeyIdeaMarked();
}

void ProjectorController::StartSpeechRecognition() {
// TODO(crbug.com/1165437): Enable speech reognition for mic input.
void ProjectorControllerImpl::StartSpeechRecognition() {
DCHECK(!is_speech_recognition_on_);
DCHECK_NE(client_, nullptr);
client_->StartSpeechRecognition();
is_speech_recognition_on_ = true;
}

void ProjectorControllerImpl::StopSpeechRecognition() {
DCHECK(is_speech_recognition_on_);
DCHECK_NE(client_, nullptr);
client_->StopSpeechRecognition();
is_speech_recognition_on_ = false;
}

} // namespace ash
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PROJECTOR_PROJECTOR_CONTROLLER_H_
#define ASH_PROJECTOR_PROJECTOR_CONTROLLER_H_
#ifndef ASH_PROJECTOR_PROJECTOR_CONTROLLER_IMPL_H_
#define ASH_PROJECTOR_PROJECTOR_CONTROLLER_IMPL_H_

#include <string>
#include <vector>

#include "ash/ash_export.h"
#include "ash/public/cpp/projector/projector_controller.h"
#include "chromeos/services/machine_learning/public/mojom/soda.mojom.h"

namespace base {
Expand All @@ -17,19 +18,24 @@ class FilePath;

namespace ash {

class ProjectorClient;
class ProjectorUiController;
class ProjectorMetadataController;

// A controller to handle projector functionalities.
class ASH_EXPORT ProjectorController {
class ASH_EXPORT ProjectorControllerImpl : public ProjectorController {
public:
ProjectorController();
ProjectorController(const ProjectorController&) = delete;
ProjectorController& operator=(const ProjectorController&) = delete;
~ProjectorController();
ProjectorControllerImpl();
ProjectorControllerImpl(const ProjectorControllerImpl&) = delete;
ProjectorControllerImpl& operator=(const ProjectorControllerImpl&) = delete;
~ProjectorControllerImpl() override;

// ProjectorController:
void SetClient(ash::ProjectorClient* client) override;

// Shows projector toolbar.
void ShowToolbar();

// Set caption on/off state.
void SetCaptionState(bool is_on);
// Mark a key idea.
Expand All @@ -47,6 +53,8 @@ class ASH_EXPORT ProjectorController {
// available.
// Invoked when transcription result is available to record the transcript
// and maybe update the UI.
// TODO(yilkal): Make this method an inherited method from
// ProjectorController.
void OnTranscription(
chromeos::machine_learning::mojom::SpeechRecognizerEventPtr
speech_recognizer_event);
Expand All @@ -59,15 +67,18 @@ class ASH_EXPORT ProjectorController {
ProjectorUiController* ui_controller() { return ui_controller_.get(); }

private:
// Starts the speech recognition session.
// Starts or stops the speech recognition session.
void StartSpeechRecognition();
void StopSpeechRecognition();

ProjectorClient* client_ = nullptr;
std::unique_ptr<ProjectorUiController> ui_controller_;
std::unique_ptr<ProjectorMetadataController> metadata_controller_;

bool is_caption_on_ = false;
bool is_speech_recognition_on_ = false;
};

} // namespace ash

#endif // ASH_PROJECTOR_PROJECTOR_CONTROLLER_H_
#endif // ASH_PROJECTOR_PROJECTOR_CONTROLLER_IMPL_H_
6 changes: 3 additions & 3 deletions ash/projector/projector_controller_unittest.cc
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -80,7 +80,7 @@ class ProjectorControllerTest : public AshTestBase {
void SetUp() override {
AshTestBase::SetUp();

controller_ = std::make_unique<ProjectorController>();
controller_ = std::make_unique<ProjectorControllerImpl>();

auto mock_ui_controller = std::make_unique<MockProjectorUiController>();
mock_ui_controller_ = mock_ui_controller.get();
Expand All @@ -96,7 +96,7 @@ class ProjectorControllerTest : public AshTestBase {
protected:
MockProjectorUiController* mock_ui_controller_ = nullptr;
MockProjectorMetadataController* mock_metadata_controller_ = nullptr;
std::unique_ptr<ProjectorController> controller_;
std::unique_ptr<ProjectorControllerImpl> controller_;
};

TEST_F(ProjectorControllerTest, ShowToolbar) {
Expand Down
2 changes: 1 addition & 1 deletion ash/projector/projector_feature_pod_controller.cc
Expand Up @@ -4,7 +4,7 @@

#include "ash/projector/projector_feature_pod_controller.h"

#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"
#include "ash/projector/projector_ui_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/projector/projector_metadata_controller.cc
Expand Up @@ -4,7 +4,7 @@

#include "ash/projector/projector_metadata_controller.h"

#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/projector/projector_ui_controller.cc
Expand Up @@ -4,7 +4,7 @@

#include "ash/projector/projector_ui_controller.h"

#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"
#include "ash/public/cpp/toast_data.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
Expand Down
3 changes: 3 additions & 0 deletions ash/public/cpp/BUILD.gn
Expand Up @@ -224,6 +224,9 @@ component("cpp") {
"presentation_time_recorder.h",
"privacy_screen_dlp_helper.cc",
"privacy_screen_dlp_helper.h",
"projector/projector_client.h",
"projector/projector_controller.cc",
"projector/projector_controller.h",
"quick_answers/controller/quick_answers_browser_client.cc",
"quick_answers/controller/quick_answers_browser_client.h",
"quick_answers/controller/quick_answers_controller.cc",
Expand Down
27 changes: 27 additions & 0 deletions ash/public/cpp/projector/projector_client.h
@@ -0,0 +1,27 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CLIENT_H_
#define ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CLIENT_H_

#include "ash/public/cpp/ash_public_export.h"

namespace ash {

// Creates interface to access Browser side functionalities for the
// ProjectorControllerImpl.
class ASH_PUBLIC_EXPORT ProjectorClient {
public:
ProjectorClient() = default;
ProjectorClient(const ProjectorClient&) = delete;
ProjectorClient& operator=(const ProjectorClient&) = delete;
virtual ~ProjectorClient() = default;

virtual void StartSpeechRecognition() = 0;
virtual void StopSpeechRecognition() = 0;
};

} // namespace ash

#endif // ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CLIENT_H_
30 changes: 30 additions & 0 deletions ash/public/cpp/projector/projector_controller.cc
@@ -0,0 +1,30 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/public/cpp/projector/projector_controller.h"

#include "base/check_op.h"

namespace ash {

namespace {
ProjectorController* g_instance = nullptr;
}

ProjectorController::ProjectorController() {
DCHECK_EQ(nullptr, g_instance);
g_instance = this;
}

ProjectorController::~ProjectorController() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}

// static
ProjectorController* ProjectorController::Get() {
return g_instance;
}

} // namespace ash
34 changes: 34 additions & 0 deletions ash/public/cpp/projector/projector_controller.h
@@ -0,0 +1,34 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CONTROLLER_H_
#define ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CONTROLLER_H_

#include "ash/public/cpp/ash_public_export.h"

namespace ash {

class ProjectorClient;

// Interface to control projector in ash.
class ASH_PUBLIC_EXPORT ProjectorController {
public:
ProjectorController();
ProjectorController(const ProjectorController&) = delete;
ProjectorController& operator=(const ProjectorController&) = delete;
virtual ~ProjectorController();

static ProjectorController* Get();

// Make sure the client is set before attempting to use to the
// ProjectorController.
virtual void SetClient(ProjectorClient* client) = 0;

// TODO(ylkal): Add OnTranscriptionResult method to receive transcription
// results here.
};

} // namespace ash

#endif // ASH_PUBLIC_CPP_PROJECTOR_PROJECTOR_CONTROLLER_H_
4 changes: 2 additions & 2 deletions ash/shell.cc
Expand Up @@ -77,7 +77,7 @@
#include "ash/metrics/login_unlock_throughput_recorder.h"
#include "ash/multi_device_setup/multi_device_notification_presenter.h"
#include "ash/policy/policy_recommendation_restorer.h"
#include "ash/projector/projector_controller.h"
#include "ash/projector/projector_controller_impl.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_prefs.h"
Expand Down Expand Up @@ -1274,7 +1274,7 @@ void Shell::Init(
}

if (chromeos::features::IsProjectorEnabled()) {
projector_controller_ = std::make_unique<ProjectorController>();
projector_controller_ = std::make_unique<ProjectorControllerImpl>();
}

// Injects the factory which fulfills the implementation of the text context
Expand Down
6 changes: 3 additions & 3 deletions ash/shell.h
Expand Up @@ -162,7 +162,7 @@ class PowerEventObserver;
class PowerPrefs;
class PrivacyScreenController;
class ProjectingObserver;
class ProjectorController;
class ProjectorControllerImpl;
class QuickAnswersController;
class ResizeShadowController;
class ResolutionNotificationController;
Expand Down Expand Up @@ -561,7 +561,7 @@ class ASH_EXPORT Shell : public SessionObserver,
return frame_throttling_controller_.get();
}

ProjectorController* projector_controller() {
ProjectorControllerImpl* projector_controller() {
return projector_controller_.get();
}

Expand Down Expand Up @@ -859,7 +859,7 @@ class ASH_EXPORT Shell : public SessionObserver,

std::unique_ptr<FrameThrottlingController> frame_throttling_controller_;

std::unique_ptr<ProjectorController> projector_controller_;
std::unique_ptr<ProjectorControllerImpl> projector_controller_;

// For testing only: simulate that a modal window is open
bool simulate_modal_window_open_for_test_ = false;
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Expand Up @@ -2051,6 +2051,8 @@ static_library("ui") {
"ash/network/network_state_notifier.h",
"ash/network/tether_notification_presenter.cc",
"ash/network/tether_notification_presenter.h",
"ash/projector/projector_client_impl.cc",
"ash/projector/projector_client_impl.h",
"ash/quick_answers/quick_answers_browser_client_impl.cc",
"ash/quick_answers/quick_answers_browser_client_impl.h",
"ash/screen_orientation_delegate_chromeos.cc",
Expand Down

0 comments on commit 378bd67

Please sign in to comment.