ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / content / public / browser / speech_recognition_manager.h
blobf72e75fd9b83e084a178250728fdf4cbc83afa79
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.
5 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
8 #include "base/callback.h"
9 #include "base/strings/string16.h"
10 #include "content/common/content_export.h"
11 #include "content/public/common/speech_recognition_result.h"
13 namespace content {
15 class SpeechRecognitionEventListener;
16 struct SpeechRecognitionSessionConfig;
17 struct SpeechRecognitionSessionContext;
19 // The SpeechRecognitionManager (SRM) is a singleton class that handles SR
20 // functionalities within Chrome. Everyone that needs to perform SR should
21 // interface exclusively with the SRM, receiving events through the callback
22 // interface SpeechRecognitionEventListener.
23 // Since many different sources can use SR in different times (some overlapping
24 // is allowed while waiting for results), the SRM has the further responsibility
25 // of handling separately and reliably (taking into account also call sequences
26 // that might not make sense, e.g., two subsequent AbortSession calls).
27 // In this sense a session, within the SRM, models the ongoing evolution of a
28 // SR request from the viewpoint of the end-user, abstracting all the concrete
29 // operations that must be carried out, that will be handled by inner classes.
30 class SpeechRecognitionManager {
31 public:
32 enum { kSessionIDInvalid = 0 };
34 // Returns the singleton instance.
35 static CONTENT_EXPORT SpeechRecognitionManager* GetInstance();
37 // Singleton manager setter useful for tests.
38 static void CONTENT_EXPORT SetManagerForTesting(
39 SpeechRecognitionManager* manager);
41 // Creates a new recognition session.
42 virtual int CreateSession(const SpeechRecognitionSessionConfig& config) = 0;
44 // Starts/restarts recognition for an existing session, after performing a
45 // premilinary check on the delegate (CheckRecognitionIsAllowed).
46 virtual void StartSession(int session_id) = 0;
48 // Aborts recognition for an existing session, without providing any result.
49 virtual void AbortSession(int session_id) = 0;
51 // Aborts all sessions for a given render process,
52 // without providing any result.
53 virtual void AbortAllSessionsForRenderProcess(int render_process_id) = 0;
55 // Aborts all sessions for a given RenderView, without providing any result.
56 virtual void AbortAllSessionsForRenderView(int render_process_id,
57 int render_view_id) = 0;
59 // Stops audio capture for an existing session. The audio captured before the
60 // call will be processed, possibly ending up with a result.
61 virtual void StopAudioCaptureForSession(int session_id) = 0;
63 // Retrieves the configuration of a session, as provided by the caller
64 // upon CreateSession.
65 virtual const SpeechRecognitionSessionConfig& GetSessionConfig(int session_id)
66 const = 0;
68 // Retrieves the context associated to a session.
69 virtual SpeechRecognitionSessionContext GetSessionContext(
70 int session_id) const = 0;
72 // Looks-up an existing session from the context tuple
73 // {render_view_id, render_view_id, request_id}.
74 virtual int GetSession(int render_process_id,
75 int render_view_id,
76 int request_id) const = 0;
78 // Returns true if the OS reports existence of audio recording devices.
79 virtual bool HasAudioInputDevices() = 0;
81 // Returns a human readable string for the model/make of the active audio
82 // input device for this computer.
83 virtual base::string16 GetAudioInputDeviceModel() = 0;
85 // Invokes the platform provided microphone settings UI in a non-blocking way,
86 // via the BrowserThread::FILE thread.
87 virtual void ShowAudioInputSettings() = 0;
89 protected:
90 virtual ~SpeechRecognitionManager() {}
92 private:
93 static SpeechRecognitionManager* manager_for_tests_;
96 } // namespace content
98 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_