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" | |
16 #include "content/public/browser/browser_thread.h" | |
17 | |
18 namespace arc { | |
19 | |
20 namespace { | |
21 | |
22 constexpr std::string kEnableVoiceInteraction = "enable-voice-interaction"; | |
Luis Héctor Chávez
2017/03/08 15:22:40
std::string does not support being a constexpr. Th
Muyuan
2017/03/09 00:41:03
Done.
| |
23 | |
24 } // namespace | |
25 | |
26 void ArcHomeObserver::OnInstanceReady() { | |
27 service_->OnArcHomeInstanceReady(); | |
28 } | |
29 | |
30 void ArcHomeObserver::OnInstanceClosed() { | |
31 service_->OnArcHomeInstanceClosed(); | |
32 } | |
33 | |
34 void CaptureObserver::OnInstanceReady() { | |
35 service_->OnCaptureInstanceReady(); | |
36 } | |
37 | |
38 void CaptureObserver::OnInstanceClosed() { | |
39 service_->OnCaptureInstanceClosed(); | |
40 } | |
41 | |
42 ArcVoiceInteractionService::ArcVoiceInteractionService( | |
43 ArcBridgeService* bridge_service) | |
44 : ArcService(bridge_service), home_binding_(this), capture_binding_(this) { | |
45 home_observer_ = base::MakeUnique<ArcHomeObserver>(this); | |
Luis Héctor Chávez
2017/03/08 15:22:40
nit: you can also initialize the observers on the
Muyuan
2017/03/09 00:41:03
Done.
| |
46 capture_observer_ = base::MakeUnique<CaptureObserver>(this); | |
47 arc_bridge_service()->vi_capture()->AddObserver(capture_observer_.get()); | |
48 arc_bridge_service()->vi_home()->AddObserver(home_observer_.get()); | |
49 } | |
50 | |
51 ArcVoiceInteractionService::~ArcVoiceInteractionService() { | |
52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
53 arc_bridge_service()->vi_capture()->RemoveObserver(capture_observer_.get()); | |
Luis Héctor Chávez
2017/03/08 15:22:40
nit: Remove the observers in the opposite order in
Muyuan
2017/03/09 00:41:03
Done.
| |
54 arc_bridge_service()->vi_home()->RemoveObserver(home_observer_.get()); | |
55 } | |
56 | |
57 void ArcVoiceInteractionService::OnArcHomeInstanceReady() { | |
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
59 mojom::VoiceInteractionArcHomeInstance* arc_home_instance = | |
60 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_home(), Init); | |
61 DCHECK(arc_home_instance); | |
62 arc_home_instance->Init(home_binding_.CreateInterfacePtrAndBind()); | |
63 } | |
64 | |
65 void ArcVoiceInteractionService::OnArcHomeInstanceClosed() { | |
66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
67 } | |
68 | |
69 void ArcVoiceInteractionService::OnCaptureInstanceReady() { | |
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
71 mojom::VoiceInteractionCaptureInstance* arc_capture_instance = | |
72 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_capture(), Init); | |
73 DCHECK(arc_capture_instance); | |
74 arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind()); | |
75 | |
76 std::vector<ui::Accelerator> accelerators; | |
77 ui::Accelerator acc(ui::VKEY_A, ui::EF_COMMAND_DOWN); | |
78 accelerators.push_back(std::move(acc)); | |
xiyuan
2017/03/08 17:37:59
nit: You can use {} syntax to save creating a vect
Muyuan
2017/03/09 00:41:03
Done.
| |
79 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
80 kEnableVoiceInteraction)) { | |
81 ash::WmShell::Get()->accelerator_controller()->Register(accelerators, this); | |
82 } | |
83 } | |
84 | |
85 void ArcVoiceInteractionService::OnCaptureInstanceClosed() { | |
86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
xiyuan
2017/03/08 17:37:59
Do we need to unregister the accelerator (or have
Muyuan
2017/03/09 00:41:03
Done.
| |
87 } | |
88 | |
89 bool ArcVoiceInteractionService::AcceleratorPressed( | |
90 const ui::Accelerator& accelerator) { | |
91 mojom::VoiceInteractionCaptureInstance* capture_instance_ = | |
92 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->vi_capture(), | |
93 StartVoiceInteractionSession); | |
94 DCHECK(capture_instance_); | |
95 capture_instance_->StartVoiceInteractionSession(); | |
96 return true; | |
97 } | |
98 | |
99 bool ArcVoiceInteractionService::CanHandleAccelerators() const { | |
100 return true; | |
101 } | |
102 | |
103 void ArcVoiceInteractionService::GetVoiceInteractionStructure( | |
104 const GetVoiceInteractionStructureCallback& callback) { | |
105 LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure " | |
106 << "not implemented."; | |
107 // TODO(muyuanli): The logic below is only there to prevent blocking. | |
108 // details needs to be implemented in the future. | |
109 mojom::VoiceInteractionStructurePtr structure = | |
110 mojom::VoiceInteractionStructure::New(); | |
111 structure->success = false; | |
112 callback.Run(std::move(structure)); | |
113 } | |
114 | |
115 void ArcVoiceInteractionService::CaptureFocusedWindow( | |
116 const CaptureFocusedWindowCallback& callback) { | |
117 LOG(ERROR) | |
118 << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented."; | |
119 // TODO(muyuanli): The logic below is only there to prevent blocking. | |
120 // details needs to be implemented in the future. | |
121 std::vector<uint8_t> result; | |
122 callback.Run(result); | |
123 } | |
124 | |
125 } // namespace arc | |
OLD | NEW |