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

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

Issue 2731403007: add voice interaction shortcut. (Closed)
Patch Set: Updated docs for mojom fields; Changed coding according to 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 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 <vector>
8
9 #include "ash/common/accelerators/accelerator_controller.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/shell.h"
12 #include "base/command_line.h"
13 #include "base/logging.h"
14 #include "components/arc/arc_bridge_service.h"
15 #include "components/arc/arc_features.h"
16 #include "content/public/browser/browser_thread.h"
17
18 namespace arc {
19
20 namespace {
21
22 constexpr char kEnableVoiceInteraction[] = "enable-voice-interaction";
23
24 const ui::Accelerator kVoiceInteractionAccelerator(ui::VKEY_A,
25 ui::EF_COMMAND_DOWN);
26
27 } // namespace
28
29 class ArcVoiceInteractionService::ArcHomeObserver
30 : public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer {
31 public:
32 explicit ArcHomeObserver(ArcVoiceInteractionService* service)
33 : service_(service) {}
34 void OnInstanceReady() override { service_->OnArcHomeInstanceReady(); }
35 void OnInstanceClosed() override { service_->OnArcHomeInstanceClosed(); }
36
37 private:
38 ArcVoiceInteractionService* service_;
39
40 DISALLOW_COPY_AND_ASSIGN(ArcHomeObserver);
41 };
42
43 class ArcVoiceInteractionService::CaptureObserver
44 : public InstanceHolder<mojom::VoiceInteractionCaptureInstance>::Observer {
45 public:
46 explicit CaptureObserver(ArcVoiceInteractionService* service)
47 : service_(service) {}
48 void OnInstanceReady() override { service_->OnCaptureInstanceReady(); }
49 void OnInstanceClosed() override { service_->OnCaptureInstanceClosed(); }
50
51 private:
52 ArcVoiceInteractionService* service_;
53
54 DISALLOW_COPY_AND_ASSIGN(CaptureObserver);
55 };
56
57 ArcVoiceInteractionService::ArcVoiceInteractionService(
58 ArcBridgeService* bridge_service)
59 : ArcService(bridge_service),
60 home_observer_(base::MakeUnique<ArcHomeObserver>(this)),
61 capture_observer_(base::MakeUnique<CaptureObserver>(this)),
62 home_binding_(this),
63 capture_binding_(this) {
64 arc_bridge_service()->voice_interaction_capture()->AddObserver(
65 capture_observer_.get());
66 arc_bridge_service()->voice_interaction_home()->AddObserver(
67 home_observer_.get());
68 }
69
70 ArcVoiceInteractionService::~ArcVoiceInteractionService() {
71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
72 arc_bridge_service()->voice_interaction_home()->RemoveObserver(
73 home_observer_.get());
74 arc_bridge_service()->voice_interaction_capture()->RemoveObserver(
75 capture_observer_.get());
76 }
77
78 void ArcVoiceInteractionService::OnArcHomeInstanceReady() {
79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
80 mojom::VoiceInteractionArcHomeInstance* arc_home_instance =
81 ARC_GET_INSTANCE_FOR_METHOD(
82 arc_bridge_service()->voice_interaction_home(), Init);
83 DCHECK(arc_home_instance);
84 arc_home_instance->Init(home_binding_.CreateInterfacePtrAndBind());
85 }
86
87 void ArcVoiceInteractionService::OnArcHomeInstanceClosed() {
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
89 }
90
91 void ArcVoiceInteractionService::OnCaptureInstanceReady() {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
93 mojom::VoiceInteractionCaptureInstance* arc_capture_instance =
94 ARC_GET_INSTANCE_FOR_METHOD(
95 arc_bridge_service()->voice_interaction_capture(), Init);
96 DCHECK(arc_capture_instance);
97 arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind());
98
99 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
100 kEnableVoiceInteraction)) {
101 ash::WmShell::Get()->accelerator_controller()->Register(
102 {kVoiceInteractionAccelerator}, this);
103 }
104 }
105
106 void ArcVoiceInteractionService::OnCaptureInstanceClosed() {
107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
108 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
109 kEnableVoiceInteraction)) {
110 ash::WmShell::Get()->accelerator_controller()->Unregister(
111 kVoiceInteractionAccelerator, this);
112 }
113 }
114
115 bool ArcVoiceInteractionService::AcceleratorPressed(
116 const ui::Accelerator& accelerator) {
117 mojom::VoiceInteractionCaptureInstance* capture_instance_ =
xc 2017/03/09 05:05:47 no surfix _ for local variable
Muyuan 2017/03/09 20:44:44 Done.
118 ARC_GET_INSTANCE_FOR_METHOD(
119 arc_bridge_service()->voice_interaction_capture(),
120 StartVoiceInteractionSession);
121 DCHECK(capture_instance_);
122 capture_instance_->StartVoiceInteractionSession();
xc 2017/03/09 05:05:47 I think we need to explicitly check null here. ot
Muyuan 2017/03/09 20:44:44 The key is registered only after the Arc instance
123 return true;
124 }
125
126 bool ArcVoiceInteractionService::CanHandleAccelerators() const {
127 return true;
128 }
129
130 void ArcVoiceInteractionService::GetVoiceInteractionStructure(
131 const GetVoiceInteractionStructureCallback& callback) {
132 LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure "
133 << "not implemented.";
134 // TODO(muyuanli): The logic below is only there to prevent blocking.
135 // details needs to be implemented in the future.
136 mojom::VoiceInteractionStructurePtr structure =
137 mojom::VoiceInteractionStructure::New();
138 structure->success = false;
139 callback.Run(std::move(structure));
140 }
141
142 void ArcVoiceInteractionService::CaptureFocusedWindow(
143 const CaptureFocusedWindowCallback& callback) {
144 LOG(ERROR)
145 << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented.";
146 // TODO(muyuanli): The logic below is only there to prevent blocking.
147 // details needs to be implemented in the future.
148 std::vector<uint8_t> result;
149 callback.Run(result);
150 }
151
152 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698