Chromium Code Reviews| Index: chrome/browser/chromeos/arc/arc_voice_interaction_service.cc |
| diff --git a/chrome/browser/chromeos/arc/arc_voice_interaction_service.cc b/chrome/browser/chromeos/arc/arc_voice_interaction_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..99d062a0ba14d93fb45404f23ab95b272048f1c1 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/arc_voice_interaction_service.cc |
| @@ -0,0 +1,125 @@ |
| +// Copyright 2017 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 "chrome/browser/chromeos/arc/arc_voice_interaction_service.h" |
| + |
| +#include <vector> |
| + |
| +#include "ash/common/accelerators/accelerator_controller.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/shell.h" |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| +#include "components/arc/arc_bridge_service.h" |
| +#include "components/arc/arc_features.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +constexpr std::string kEnableVoiceInteraction = "enable-voice-interaction"; |
|
Luis Héctor Chávez
2017/03/08 15:22:40
std::string does not support being a constexpr. Th
Muyuan
2017/03/09 00:41:03
Done.
|
| + |
| +} // namespace |
| + |
| +void ArcHomeObserver::OnInstanceReady() { |
| + service_->OnArcHomeInstanceReady(); |
| +} |
| + |
| +void ArcHomeObserver::OnInstanceClosed() { |
| + service_->OnArcHomeInstanceClosed(); |
| +} |
| + |
| +void CaptureObserver::OnInstanceReady() { |
| + service_->OnCaptureInstanceReady(); |
| +} |
| + |
| +void CaptureObserver::OnInstanceClosed() { |
| + service_->OnCaptureInstanceClosed(); |
| +} |
| + |
| +ArcVoiceInteractionService::ArcVoiceInteractionService( |
| + ArcBridgeService* bridge_service) |
| + : ArcService(bridge_service), home_binding_(this), capture_binding_(this) { |
| + home_observer_ = base::MakeUnique<ArcHomeObserver>(this); |
|
Luis Héctor Chávez
2017/03/08 15:22:40
nit: you can also initialize the observers on the
Muyuan
2017/03/09 00:41:03
Done.
|
| + capture_observer_ = base::MakeUnique<CaptureObserver>(this); |
| + arc_bridge_service()->vi_capture()->AddObserver(capture_observer_.get()); |
| + arc_bridge_service()->vi_home()->AddObserver(home_observer_.get()); |
| +} |
| + |
| +ArcVoiceInteractionService::~ArcVoiceInteractionService() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + arc_bridge_service()->vi_capture()->RemoveObserver(capture_observer_.get()); |
|
Luis Héctor Chávez
2017/03/08 15:22:40
nit: Remove the observers in the opposite order in
Muyuan
2017/03/09 00:41:03
Done.
|
| + arc_bridge_service()->vi_home()->RemoveObserver(home_observer_.get()); |
| +} |
| + |
| +void ArcVoiceInteractionService::OnArcHomeInstanceReady() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + mojom::VoiceInteractionArcHomeInstance* arc_home_instance = |
| + ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_home(), Init); |
| + DCHECK(arc_home_instance); |
| + arc_home_instance->Init(home_binding_.CreateInterfacePtrAndBind()); |
| +} |
| + |
| +void ArcVoiceInteractionService::OnArcHomeInstanceClosed() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| +} |
| + |
| +void ArcVoiceInteractionService::OnCaptureInstanceReady() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + mojom::VoiceInteractionCaptureInstance* arc_capture_instance = |
| + ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_capture(), Init); |
| + DCHECK(arc_capture_instance); |
| + arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind()); |
| + |
| + std::vector<ui::Accelerator> accelerators; |
| + ui::Accelerator acc(ui::VKEY_A, ui::EF_COMMAND_DOWN); |
| + accelerators.push_back(std::move(acc)); |
|
xiyuan
2017/03/08 17:37:59
nit: You can use {} syntax to save creating a vect
Muyuan
2017/03/09 00:41:03
Done.
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + kEnableVoiceInteraction)) { |
| + ash::WmShell::Get()->accelerator_controller()->Register(accelerators, this); |
| + } |
| +} |
| + |
| +void ArcVoiceInteractionService::OnCaptureInstanceClosed() { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
|
xiyuan
2017/03/08 17:37:59
Do we need to unregister the accelerator (or have
Muyuan
2017/03/09 00:41:03
Done.
|
| +} |
| + |
| +bool ArcVoiceInteractionService::AcceleratorPressed( |
| + const ui::Accelerator& accelerator) { |
| + mojom::VoiceInteractionCaptureInstance* capture_instance_ = |
| + ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_capture(), |
| + StartVoiceInteractionSession); |
| + DCHECK(capture_instance_); |
| + capture_instance_->StartVoiceInteractionSession(); |
| + return true; |
| +} |
| + |
| +bool ArcVoiceInteractionService::CanHandleAccelerators() const { |
| + return true; |
| +} |
| + |
| +void ArcVoiceInteractionService::GetVoiceInteractionStructure( |
| + const GetVoiceInteractionStructureCallback& callback) { |
| + LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure " |
| + << "not implemented."; |
| + // TODO(muyuanli): The logic below is only there to prevent blocking. |
| + // details needs to be implemented in the future. |
| + mojom::VoiceInteractionStructurePtr structure = |
| + mojom::VoiceInteractionStructure::New(); |
| + structure->success = false; |
| + callback.Run(std::move(structure)); |
| +} |
| + |
| +void ArcVoiceInteractionService::CaptureFocusedWindow( |
| + const CaptureFocusedWindowCallback& callback) { |
| + LOG(ERROR) |
| + << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented."; |
| + // TODO(muyuanli): The logic below is only there to prevent blocking. |
| + // details needs to be implemented in the future. |
| + std::vector<uint8_t> result; |
| + callback.Run(result); |
| +} |
| + |
| +} // namespace arc |