OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_API_H_ | |
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_API_H_ | |
7 | |
8 #include "chrome/browser/extensions/extension_function.h" | |
9 #include "content/public/browser/notification_observer.h" | |
10 #include "content/public/browser/notification_registrar.h" | |
11 | |
12 // Handles asynchronous operations such as starting or stopping speech | |
13 // recognition in the framework of the extension API state machine. | |
14 class SpeechInputAsyncFunction : public AsyncExtensionFunction, | |
15 public content::NotificationObserver { | |
16 public: | |
17 // content::NotificationObserver. | |
18 virtual void Observe(int type, | |
19 const content::NotificationSource& source, | |
20 const content::NotificationDetails& details) OVERRIDE; | |
21 | |
22 protected: | |
23 SpeechInputAsyncFunction(int start_state, int transition_state, | |
24 int end_state, int transition_notification); | |
25 virtual ~SpeechInputAsyncFunction(); | |
26 | |
27 // ExtensionFunction: | |
28 virtual void Run() OVERRIDE; | |
29 virtual bool RunImpl() = 0; | |
30 | |
31 private: | |
32 // To be defined on construction by derived classes. | |
33 int start_state_; | |
34 int transition_state_; | |
35 int end_state_; | |
36 int transition_notification_; | |
37 | |
38 content::NotificationRegistrar registrar_; | |
39 bool expecting_transition_; | |
40 bool failed_; | |
41 }; | |
42 | |
43 // Implements experimental.speechInput.start. | |
44 class StartSpeechInputFunction : public SpeechInputAsyncFunction { | |
45 public: | |
46 DECLARE_EXTENSION_FUNCTION("experimental.speechInput.start", | |
47 EXPERIMENTAL_SPEECHINPUT_START) | |
48 | |
49 StartSpeechInputFunction(); | |
50 | |
51 protected: | |
52 // SpeechInputAsyncFunction: | |
53 virtual bool RunImpl() OVERRIDE; | |
54 | |
55 private: | |
56 virtual ~StartSpeechInputFunction() {} | |
57 }; | |
58 | |
59 // Implements experimental.speechInput.stop. | |
60 class StopSpeechInputFunction : public SpeechInputAsyncFunction { | |
61 public: | |
62 DECLARE_EXTENSION_FUNCTION("experimental.speechInput.stop", | |
63 EXPERIMENTAL_SPEECHINPUT_STOP) | |
64 | |
65 StopSpeechInputFunction(); | |
66 | |
67 protected: | |
68 // SpeechInputAsyncFunction: | |
69 virtual bool RunImpl() OVERRIDE; | |
70 | |
71 private: | |
72 virtual ~StopSpeechInputFunction() {} | |
73 }; | |
74 | |
75 // Implements experimental.speechInput.isRecording. | |
76 class IsRecordingSpeechInputFunction : public SyncExtensionFunction { | |
77 public: | |
78 DECLARE_EXTENSION_FUNCTION("experimental.speechInput.isRecording", | |
79 EXPERIMENTAL_SPEECHINPUT_ISRECORDING) | |
80 | |
81 // Called back from SpeechInputExtensionManager in the UI thread. | |
82 void SetIsRecordingResult(bool result); | |
83 | |
84 protected: | |
85 // ExtensionFunction: | |
86 virtual void Run() OVERRIDE; | |
87 virtual bool RunImpl() OVERRIDE; | |
88 | |
89 private: | |
90 virtual ~IsRecordingSpeechInputFunction() {} | |
91 }; | |
92 | |
93 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_EXTENSION_API_H_ | |
OLD | NEW |