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

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

Issue 2731403007: add voice interaction shortcut. (Closed)
Patch Set: Changed mojom comments 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..1fe49584a7f89e3590b62a791c302085414b3af4
--- /dev/null
+++ b/chrome/browser/chromeos/arc/arc_voice_interaction_service.cc
@@ -0,0 +1,152 @@
+// 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"
hidehiko 2017/03/10 06:14:49 nit: Looks unused?
Muyuan 2017/03/10 22:36:09 Done.
+#include "content/public/browser/browser_thread.h"
+
+namespace arc {
+
+namespace {
+
+constexpr char kEnableVoiceInteraction[] = "enable-voice-interaction";
+
+const ui::Accelerator kVoiceInteractionAccelerator(ui::VKEY_A,
xiyuan 2017/03/10 18:01:16 Move this close to where it is used since it is on
Muyuan 2017/03/10 22:36:10 Done.
+ ui::EF_COMMAND_DOWN);
+
+} // namespace
+
+class ArcVoiceInteractionService::ArcHomeObserver
+ : public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer {
+ public:
+ explicit ArcHomeObserver(ArcVoiceInteractionService* service)
+ : service_(service) {}
+ void OnInstanceReady() override { service_->OnArcHomeInstanceReady(); }
+ void OnInstanceClosed() override { service_->OnArcHomeInstanceClosed(); }
+
+ private:
+ ArcVoiceInteractionService* service_;
xiyuan 2017/03/10 18:01:16 nit: ArcVoiceInteractionService* const service_; s
Muyuan 2017/03/10 22:36:10 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(ArcHomeObserver);
+};
+
+class ArcVoiceInteractionService::CaptureObserver
+ : public InstanceHolder<mojom::VoiceInteractionCaptureInstance>::Observer {
+ public:
+ explicit CaptureObserver(ArcVoiceInteractionService* service)
+ : service_(service) {}
+ void OnInstanceReady() override { service_->OnCaptureInstanceReady(); }
+ void OnInstanceClosed() override { service_->OnCaptureInstanceClosed(); }
+
+ private:
+ ArcVoiceInteractionService* service_;
xiyuan 2017/03/10 18:01:16 nit: ditto, use const ptr
Muyuan 2017/03/10 22:36:10 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) {
+ arc_bridge_service()->voice_interaction_capture()->AddObserver(
hidehiko 2017/03/10 06:14:49 Optional: How about moving these into each Observe
Muyuan 2017/03/10 22:36:10 Done.
+ capture_observer_.get());
+ arc_bridge_service()->voice_interaction_home()->AddObserver(
+ home_observer_.get());
+}
+
+ArcVoiceInteractionService::~ArcVoiceInteractionService() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ arc_bridge_service()->voice_interaction_home()->RemoveObserver(
+ home_observer_.get());
+ arc_bridge_service()->voice_interaction_capture()->RemoveObserver(
+ capture_observer_.get());
+}
+
+void ArcVoiceInteractionService::OnArcHomeInstanceReady() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::VoiceInteractionArcHomeInstance* arc_home_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->voice_interaction_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(
+ kEnableVoiceInteraction)) {
+ ash::WmShell::Get()->accelerator_controller()->Register(
+ {kVoiceInteractionAccelerator}, this);
+ }
+}
+
+void ArcVoiceInteractionService::OnCaptureInstanceClosed() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ kEnableVoiceInteraction)) {
+ ash::WmShell::Get()->accelerator_controller()->Unregister(
+ kVoiceInteractionAccelerator, this);
+ }
+}
+
+bool ArcVoiceInteractionService::AcceleratorPressed(
+ const ui::Accelerator& accelerator) {
+ mojom::VoiceInteractionCaptureInstance* capture_instance =
hidehiko 2017/03/10 06:14:49 DCHECK_CURRENTLY_ON(UI) here, too?
Muyuan 2017/03/10 22:36:10 Done.
+ ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->voice_interaction_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 "
hidehiko 2017/03/10 06:14:49 Ditto.
Muyuan 2017/03/10 22:36:09 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));
hidehiko 2017/03/10 06:14:49 nit: Please #include <utility>
Muyuan 2017/03/10 22:36:10 Done.
+}
+
+void ArcVoiceInteractionService::CaptureFocusedWindow(
+ const CaptureFocusedWindowCallback& callback) {
+ LOG(ERROR)
hidehiko 2017/03/10 06:14:49 Ditto.
Muyuan 2017/03/10 22:36:10 Done.
+ << "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);
hidehiko 2017/03/10 06:14:49 nit: can be callback.Run({}); ?
Muyuan 2017/03/10 22:36:10 Done.
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698