Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(893)

Unified Diff: chrome/browser/chromeos/arc/arc_voice_interaction_service.cc

Issue 2731403007: add voice interaction shortcut. (Closed)
Patch Set: add voice interaction shortcut. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..11f44fefcb23116834a2f00833af294f4b12cd40
--- /dev/null
+++ b/chrome/browser/chromeos/arc/arc_voice_interaction_service.cc
@@ -0,0 +1,156 @@
+// 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 <utility>
+#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 "chromeos/chromeos_switches.h"
+#include "components/arc/arc_bridge_service.h"
+#include "components/arc/instance_holder.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace arc {
+
+class ArcVoiceInteractionService::ArcHomeObserver
+ : public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer {
+ public:
+ explicit ArcHomeObserver(ArcVoiceInteractionService* service)
+ : service_(service) {
+ service_->arc_bridge_service()->voice_interaction_arc_home()->AddObserver(
+ this);
+ }
+ ~ArcHomeObserver() {
+ service_->arc_bridge_service()
+ ->voice_interaction_arc_home()
+ ->RemoveObserver(this);
+ }
+ void OnInstanceReady() override { service_->OnArcHomeInstanceReady(); }
+ void OnInstanceClosed() override { service_->OnArcHomeInstanceClosed(); }
+
+ private:
+ // Owned by ArcVoinceInteractionService.
+ ArcVoiceInteractionService* service_;
xiyuan 2017/03/14 17:55:31 nit: ArcVoiceInteractionService* const service_;
Muyuan 2017/03/14 21:37:01 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(ArcHomeObserver);
+};
+
+class ArcVoiceInteractionService::CaptureObserver
+ : public InstanceHolder<mojom::VoiceInteractionCaptureInstance>::Observer {
+ public:
+ explicit CaptureObserver(ArcVoiceInteractionService* service)
+ : service_(service) {
+ service_->arc_bridge_service()->voice_interaction_capture()->AddObserver(
+ this);
+ }
+ ~CaptureObserver() {
+ service_->arc_bridge_service()->voice_interaction_capture()->RemoveObserver(
+ this);
+ }
+ void OnInstanceReady() override { service_->OnCaptureInstanceReady(); }
+ void OnInstanceClosed() override { service_->OnCaptureInstanceClosed(); }
+
+ private:
+ // Owned by ArcVoinceInteractionService.
+ ArcVoiceInteractionService* service_;
xiyuan 2017/03/14 17:55:31 nit: ditto, use const pointer
Muyuan 2017/03/14 21:37:01 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(CaptureObserver);
+};
+
+ArcVoiceInteractionService::ArcVoiceInteractionService(
+ ArcBridgeService* bridge_service)
+ : ArcService(bridge_service),
+ home_observer_(base::MakeUnique<ArcHomeObserver>(this)),
+ capture_observer_(base::MakeUnique<CaptureObserver>(this)),
+ home_binding_(this),
+ capture_binding_(this) {}
+
+ArcVoiceInteractionService::~ArcVoiceInteractionService() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+}
+
+void ArcVoiceInteractionService::OnArcHomeInstanceReady() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::VoiceInteractionArcHomeInstance* arc_home_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->voice_interaction_arc_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()->voice_interaction_capture(), Init);
+ DCHECK(arc_capture_instance);
+ arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind());
+
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kEnableVoiceInteraction))
+ return;
xiyuan 2017/03/14 17:55:31 nit: wrap with {} since condition takes more than
Muyuan 2017/03/14 21:37:01 Done.
+ ash::WmShell::Get()->accelerator_controller()->Register(
xiyuan 2017/03/14 17:55:31 nit: insert an empty line before
Muyuan 2017/03/14 21:37:01 Done.
+ {ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN)}, this);
+}
+
+void ArcVoiceInteractionService::OnCaptureInstanceClosed() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kEnableVoiceInteraction))
+ return;
xiyuan 2017/03/14 17:55:31 nit: wrap with {}
Muyuan 2017/03/14 21:37:01 Done.
+ ash::WmShell::Get()->accelerator_controller()->Unregister(
xiyuan 2017/03/14 17:55:31 nit: accelerator_controller()->UnregisterAll(this)
Muyuan 2017/03/14 21:37:01 Done.
+ ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN), this);
+}
+
+bool ArcVoiceInteractionService::AcceleratorPressed(
+ const ui::Accelerator& accelerator) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::VoiceInteractionCaptureInstance* capture_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->voice_interaction_capture(),
+ StartVoiceInteractionSession);
+ DCHECK(capture_instance);
+ capture_instance->StartVoiceInteractionSession();
+ return true;
+}
+
+bool ArcVoiceInteractionService::CanHandleAccelerators() const {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ return true;
+}
+
+void ArcVoiceInteractionService::GetVoiceInteractionStructure(
+ const GetVoiceInteractionStructureCallback& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure "
xiyuan 2017/03/14 17:55:31 nit: NOTIMPLEMENTED();
Muyuan 2017/03/14 21:37:01 Done.
+ << "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) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ LOG(ERROR)
xiyuan 2017/03/14 17:55:31 nit: NOTIMPLEMENTED();
Muyuan 2017/03/14 21:37:01 Done.
+ << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented.";
+ // TODO(muyuanli): The logic below is only there to prevent blocking.
+ // details needs to be implemented in the future.
+ callback.Run({});
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698