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 <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 "chromeos/chromeos_switches.h" | |
16 #include "components/arc/arc_bridge_service.h" | |
17 #include "components/arc/instance_holder.h" | |
18 #include "content/public/browser/browser_thread.h" | |
19 | |
20 namespace arc { | |
21 | |
22 class ArcVoiceInteractionService::ArcHomeObserver | |
23 : public InstanceHolder<mojom::VoiceInteractionArcHomeInstance>::Observer { | |
24 public: | |
25 explicit ArcHomeObserver(ArcVoiceInteractionService* service) | |
26 : service_(service) { | |
27 service_->arc_bridge_service()->voice_interaction_arc_home()->AddObserver( | |
28 this); | |
29 } | |
30 ~ArcHomeObserver() { | |
31 service_->arc_bridge_service() | |
32 ->voice_interaction_arc_home() | |
33 ->RemoveObserver(this); | |
34 } | |
35 void OnInstanceReady() override { service_->OnArcHomeInstanceReady(); } | |
36 void OnInstanceClosed() override { service_->OnArcHomeInstanceClosed(); } | |
37 | |
38 private: | |
39 // Owned by ArcVoinceInteractionService. | |
40 ArcVoiceInteractionService* service_; | |
xiyuan
2017/03/14 17:55:31
nit: ArcVoiceInteractionService* const service_;
Muyuan
2017/03/14 21:37:01
Done.
| |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(ArcHomeObserver); | |
43 }; | |
44 | |
45 class ArcVoiceInteractionService::CaptureObserver | |
46 : public InstanceHolder<mojom::VoiceInteractionCaptureInstance>::Observer { | |
47 public: | |
48 explicit CaptureObserver(ArcVoiceInteractionService* service) | |
49 : service_(service) { | |
50 service_->arc_bridge_service()->voice_interaction_capture()->AddObserver( | |
51 this); | |
52 } | |
53 ~CaptureObserver() { | |
54 service_->arc_bridge_service()->voice_interaction_capture()->RemoveObserver( | |
55 this); | |
56 } | |
57 void OnInstanceReady() override { service_->OnCaptureInstanceReady(); } | |
58 void OnInstanceClosed() override { service_->OnCaptureInstanceClosed(); } | |
59 | |
60 private: | |
61 // Owned by ArcVoinceInteractionService. | |
62 ArcVoiceInteractionService* service_; | |
xiyuan
2017/03/14 17:55:31
nit: ditto, use const pointer
Muyuan
2017/03/14 21:37:01
Done.
| |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(CaptureObserver); | |
65 }; | |
66 | |
67 ArcVoiceInteractionService::ArcVoiceInteractionService( | |
68 ArcBridgeService* bridge_service) | |
69 : ArcService(bridge_service), | |
70 home_observer_(base::MakeUnique<ArcHomeObserver>(this)), | |
71 capture_observer_(base::MakeUnique<CaptureObserver>(this)), | |
72 home_binding_(this), | |
73 capture_binding_(this) {} | |
74 | |
75 ArcVoiceInteractionService::~ArcVoiceInteractionService() { | |
76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
77 } | |
78 | |
79 void ArcVoiceInteractionService::OnArcHomeInstanceReady() { | |
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
81 mojom::VoiceInteractionArcHomeInstance* arc_home_instance = | |
82 ARC_GET_INSTANCE_FOR_METHOD( | |
83 arc_bridge_service()->voice_interaction_arc_home(), Init); | |
84 DCHECK(arc_home_instance); | |
85 arc_home_instance->Init(home_binding_.CreateInterfacePtrAndBind()); | |
86 } | |
87 | |
88 void ArcVoiceInteractionService::OnArcHomeInstanceClosed() { | |
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
90 } | |
91 | |
92 void ArcVoiceInteractionService::OnCaptureInstanceReady() { | |
93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
94 mojom::VoiceInteractionCaptureInstance* arc_capture_instance = | |
95 ARC_GET_INSTANCE_FOR_METHOD( | |
96 arc_bridge_service()->voice_interaction_capture(), Init); | |
97 DCHECK(arc_capture_instance); | |
98 arc_capture_instance->Init(capture_binding_.CreateInterfacePtrAndBind()); | |
99 | |
100 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
101 chromeos::switches::kEnableVoiceInteraction)) | |
102 return; | |
xiyuan
2017/03/14 17:55:31
nit: wrap with {} since condition takes more than
Muyuan
2017/03/14 21:37:01
Done.
| |
103 ash::WmShell::Get()->accelerator_controller()->Register( | |
xiyuan
2017/03/14 17:55:31
nit: insert an empty line before
Muyuan
2017/03/14 21:37:01
Done.
| |
104 {ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN)}, this); | |
105 } | |
106 | |
107 void ArcVoiceInteractionService::OnCaptureInstanceClosed() { | |
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
109 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
110 chromeos::switches::kEnableVoiceInteraction)) | |
111 return; | |
xiyuan
2017/03/14 17:55:31
nit: wrap with {}
Muyuan
2017/03/14 21:37:01
Done.
| |
112 ash::WmShell::Get()->accelerator_controller()->Unregister( | |
xiyuan
2017/03/14 17:55:31
nit: accelerator_controller()->UnregisterAll(this)
Muyuan
2017/03/14 21:37:01
Done.
| |
113 ui::Accelerator(ui::VKEY_A, ui::EF_COMMAND_DOWN), this); | |
114 } | |
115 | |
116 bool ArcVoiceInteractionService::AcceleratorPressed( | |
117 const ui::Accelerator& accelerator) { | |
118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
119 mojom::VoiceInteractionCaptureInstance* capture_instance = | |
120 ARC_GET_INSTANCE_FOR_METHOD( | |
121 arc_bridge_service()->voice_interaction_capture(), | |
122 StartVoiceInteractionSession); | |
123 DCHECK(capture_instance); | |
124 capture_instance->StartVoiceInteractionSession(); | |
125 return true; | |
126 } | |
127 | |
128 bool ArcVoiceInteractionService::CanHandleAccelerators() const { | |
129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
130 return true; | |
131 } | |
132 | |
133 void ArcVoiceInteractionService::GetVoiceInteractionStructure( | |
134 const GetVoiceInteractionStructureCallback& callback) { | |
135 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
136 LOG(ERROR) << "ArcVoiceInteractionSerivce::GetVoiceInteractionStructure " | |
xiyuan
2017/03/14 17:55:31
nit: NOTIMPLEMENTED();
Muyuan
2017/03/14 21:37:01
Done.
| |
137 << "not implemented."; | |
138 // TODO(muyuanli): The logic below is only there to prevent blocking. | |
139 // details needs to be implemented in the future. | |
140 mojom::VoiceInteractionStructurePtr structure = | |
141 mojom::VoiceInteractionStructure::New(); | |
142 structure->success = false; | |
143 callback.Run(std::move(structure)); | |
144 } | |
145 | |
146 void ArcVoiceInteractionService::CaptureFocusedWindow( | |
147 const CaptureFocusedWindowCallback& callback) { | |
148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
149 LOG(ERROR) | |
xiyuan
2017/03/14 17:55:31
nit: NOTIMPLEMENTED();
Muyuan
2017/03/14 21:37:01
Done.
| |
150 << "ArcVoiceInteractionService::CaptureFocusedWindow not implemented."; | |
151 // TODO(muyuanli): The logic below is only there to prevent blocking. | |
152 // details needs to be implemented in the future. | |
153 callback.Run({}); | |
154 } | |
155 | |
156 } // namespace arc | |
OLD | NEW |