OLD | NEW |
---|---|
(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" | |
hidehiko
2017/03/10 06:14:49
nit: Looks unused?
Muyuan
2017/03/10 22:36:09
Done.
| |
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, | |
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.
| |
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_; | |
xiyuan
2017/03/10 18:01:16
nit: ArcVoiceInteractionService* const service_;
s
Muyuan
2017/03/10 22:36:10
Done.
| |
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_; | |
xiyuan
2017/03/10 18:01:16
nit: ditto, use const ptr
Muyuan
2017/03/10 22:36:10
Done.
| |
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( | |
hidehiko
2017/03/10 06:14:49
Optional: How about moving these into each Observe
Muyuan
2017/03/10 22:36:10
Done.
| |
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 = | |
hidehiko
2017/03/10 06:14:49
DCHECK_CURRENTLY_ON(UI) here, too?
Muyuan
2017/03/10 22:36:10
Done.
| |
118 ARC_GET_INSTANCE_FOR_METHOD( | |
119 arc_bridge_service()->voice_interaction_capture(), | |
120 StartVoiceInteractionSession); | |
121 DCHECK(capture_instance); | |
122 capture_instance->StartVoiceInteractionSession(); | |
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 " | |
hidehiko
2017/03/10 06:14:49
Ditto.
Muyuan
2017/03/10 22:36:09
Done.
| |
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)); | |
hidehiko
2017/03/10 06:14:49
nit: Please
#include <utility>
Muyuan
2017/03/10 22:36:10
Done.
| |
140 } | |
141 | |
142 void ArcVoiceInteractionService::CaptureFocusedWindow( | |
143 const CaptureFocusedWindowCallback& callback) { | |
144 LOG(ERROR) | |
hidehiko
2017/03/10 06:14:49
Ditto.
Muyuan
2017/03/10 22:36:10
Done.
| |
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); | |
hidehiko
2017/03/10 06:14:49
nit: can be callback.Run({}); ?
Muyuan
2017/03/10 22:36:10
Done.
| |
150 } | |
151 | |
152 } // namespace arc | |
OLD | NEW |