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

Side by Side Diff: chrome/browser/chromeos/arc/arc_voice_interaction_service.cc

Issue 2731403007: add voice interaction shortcut. (Closed)
Patch Set: removed debugging prints 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/arc/arc_voice_interaction_service.h"
6
7 #include <utility>
8 #include <vector>
9
10 #include "ash/common/accelerators/accelerator_controller.h"
11 #include "ash/common/wm_shell.h"
12 #include "ash/shell.h"
13 #include "base/command_line.h"
14 #include "base/logging.h"
15 #include "components/arc/arc_bridge_service.h"
16 #include "components/arc/instance_holder.h"
17 #include "content/public/browser/browser_thread.h"
18
19 namespace arc {
20
21 namespace {
22
23 constexpr char kEnableVoiceInteraction[] = "enable-voice-interaction";
Luis Héctor Chávez 2017/03/13 17:39:34 This should be in chromeos/chromeos_switches.h
Muyuan 2017/03/14 01:38:14 Done.
24
25 } // namespace
26
27 class ArcVoiceInteractionService::ArcHomeObserver
28 : public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer {
29 public:
30 explicit ArcHomeObserver(ArcVoiceInteractionService* service)
31 : service_(service) {
32 service_->arc_bridge_service()->voice_interaction_home()->AddObserver(this);
33 }
34 ~ArcHomeObserver() {
35 service_->arc_bridge_service()->voice_interaction_home()->RemoveObserver(
36 this);
37 }
38 void OnInstanceReady() override { service_->OnArcHomeInstanceReady(); }
39 void OnInstanceClosed() override { service_->OnArcHomeInstanceClosed(); }
40
41 private:
42 ArcVoiceInteractionService* service_;
Luis Héctor Chávez 2017/03/13 17:39:34 Please make a note that ArcVoiceInteractionService
Muyuan 2017/03/14 01:38:14 Done.
43
44 DISALLOW_COPY_AND_ASSIGN(ArcHomeObserver);
45 };
46
47 class ArcVoiceInteractionService::CaptureObserver
48 : public InstanceHolder<mojom::VoiceInteractionCaptureInstance>::Observer {
49 public:
50 explicit CaptureObserver(ArcVoiceInteractionService* service)
51 : service_(service) {
52 service_->arc_bridge_service()->voice_interaction_capture()->AddObserver(
53 this);
54 }
55 ~CaptureObserver() {
56 service_->arc_bridge_service()->voice_interaction_capture()->RemoveObserver(
57 this);
58 }
59 void OnInstanceReady() override { service_->OnCaptureInstanceReady(); }
60 void OnInstanceClosed() override { service_->OnCaptureInstanceClosed(); }
61
62 private:
63 ArcVoiceInteractionService* service_;
64
65 DISALLOW_COPY_AND_ASSIGN(CaptureObserver);
66 };
67
68 ArcVoiceInteractionService::ArcVoiceInteractionService(
69 ArcBridgeService* bridge_service)
70 : ArcService(bridge_service),
71 home_observer_(base::MakeUnique<ArcHomeObserver>(this)),
72 capture_observer_(base::MakeUnique<CaptureObserver>(this)),
73 home_binding_(this),
74 capture_binding_(this) {}
75
76 ArcVoiceInteractionService::~ArcVoiceInteractionService() {
77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
78 }
79
80 void ArcVoiceInteractionService::OnArcHomeInstanceReady() {
81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
82 mojom::VoiceInteractionArcHomeInstance* arc_home_instance =
83 ARC_GET_INSTANCE_FOR_METHOD(
84 arc_bridge_service()->voice_interaction_home(), Init);
85 DCHECK(arc_home_instance);
86 arc_home_instance->Init(home_binding_.CreateInterfacePtrAndBind());
87 }
88
89 void ArcVoiceInteractionService::OnArcHomeInstanceClosed() {
90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
91 }
92
93 void ArcVoiceInteractionService::OnCaptureInstanceReady() {
94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
95 mojom::VoiceInteractionCaptureInstance* arc_capture_instance =
96 ARC_GET_INSTANCE_FOR_METHOD(
97 arc_bridge_service()->voice_interaction_capture(), Init);
98 DCHECK(arc_capture_instance);
99 arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind());
100
101 LOG(ERROR) << "Registering key: "
Luis Héctor Chávez 2017/03/13 17:39:34 this is not an error. use VLOG(1) or DVLOG(1).
Muyuan 2017/03/14 01:38:14 removed.
102 << base::CommandLine::ForCurrentProcess()->HasSwitch(
103 kEnableVoiceInteraction);
104 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
Luis Héctor Chávez 2017/03/13 17:39:34 nit: use the guard clause pattern: if (!base::Com
Muyuan 2017/03/14 01:38:14 Done.
105 kEnableVoiceInteraction)) {
106 ash::WmShell::Get()->accelerator_controller()->Register(
107 {ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN)}, this);
108 }
109 }
110
111 void ArcVoiceInteractionService::OnCaptureInstanceClosed() {
112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
113 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
Luis Héctor Chávez 2017/03/13 17:39:34 Same as above.
Muyuan 2017/03/14 01:38:14 Done.
114 kEnableVoiceInteraction)) {
115 ash::WmShell::Get()->accelerator_controller()->Unregister(
116 ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN), this);
117 }
118 }
119
120 bool ArcVoiceInteractionService::AcceleratorPressed(
121 const ui::Accelerator& accelerator) {
122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
123 mojom::VoiceInteractionCaptureInstance* capture_instance =
124 ARC_GET_INSTANCE_FOR_METHOD(
125 arc_bridge_service()->voice_interaction_capture(),
126 StartVoiceInteractionSession);
127 DCHECK(capture_instance);
128 capture_instance->StartVoiceInteractionSession();
129 return true;
130 }
131
132 bool ArcVoiceInteractionService::CanHandleAccelerators() const {
133 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
134 return true;
135 }
136
137 void ArcVoiceInteractionService::GetVoiceInteractionStructure(
138 const GetVoiceInteractionStructureCallback& callback) {
139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
140 LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure "
141 << "not implemented.";
142 // TODO(muyuanli): The logic below is only there to prevent blocking.
143 // details needs to be implemented in the future.
144 mojom::VoiceInteractionStructurePtr structure =
145 mojom::VoiceInteractionStructure::New();
146 structure->success = false;
147 callback.Run(std::move(structure));
148 }
149
150 void ArcVoiceInteractionService::CaptureFocusedWindow(
151 const CaptureFocusedWindowCallback& callback) {
152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
153 LOG(ERROR)
154 << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented.";
155 // TODO(muyuanli): The logic below is only there to prevent blocking.
156 // details needs to be implemented in the future.
157 callback.Run({});
158 }
159
160 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698