summaryrefslogtreecommitdiffstats
path: root/chrome/browser/speech/speech_recognition_bubble_controller.h
diff options
context:
space:
mode:
authorprimiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-06 12:10:34 +0000
committerprimiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-06 12:10:34 +0000
commit07c45ddfad280a47b4e450edfd89ab2ba233932f (patch)
tree1f33d38dd7de1e9c54c7fc12fd585db5b4d12e55 /chrome/browser/speech/speech_recognition_bubble_controller.h
parente8dbb2d8c69118518f7d02cfeea004b538fbbbbc (diff)
downloadchromium_src-07c45ddfad280a47b4e450edfd89ab2ba233932f.zip
chromium_src-07c45ddfad280a47b4e450edfd89ab2ba233932f.tar.gz
chromium_src-07c45ddfad280a47b4e450edfd89ab2ba233932f.tar.bz2
Changing tab closure handling logic in speech recognition code and cleaning bubble controller. (Speech CL2.6)
- Introduced TabWatcher facility class to handle de/registration for tab closure events. - Tab closure is now handled directly in the ChromeSpeechRecognitionManagerDelegate, aborting all sessions for the corresponding renderer. - Cleaned-up SpeechRecognitionBubbleController code: removed support for multiple bubbles (not used anymore) and tab events registration. BUG=116954,132627 TEST=none Review URL: https://chromiumcodereview.appspot.com/10663018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/speech/speech_recognition_bubble_controller.h')
-rw-r--r--chrome/browser/speech/speech_recognition_bubble_controller.h122
1 files changed, 50 insertions, 72 deletions
diff --git a/chrome/browser/speech/speech_recognition_bubble_controller.h b/chrome/browser/speech/speech_recognition_bubble_controller.h
index cdc042d..e5b18a5 100644
--- a/chrome/browser/speech/speech_recognition_bubble_controller.h
+++ b/chrome/browser/speech/speech_recognition_bubble_controller.h
@@ -6,35 +6,21 @@
#define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_
#pragma once
-#include <map>
-
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
#include "chrome/browser/speech/speech_recognition_bubble.h"
-#include "content/public/browser/notification_observer.h"
-
-namespace gfx {
-class Rect;
-}
-
-namespace content {
-class NotificationRegistrar;
-}
+#include "ui/gfx/rect.h"
namespace speech {
// This class handles the speech recognition popup UI on behalf of
-// SpeechRecognitionManager, which invokes methods in the IO thread, processing
-// those requests in the UI thread. There could be multiple bubble objects alive
-// at the same time but only one of them is visible to the user. User actions on
-// that bubble are reported to the delegate.
+// SpeechRecognitionManager, which invokes methods on the IO thread, processing
+// those requests on the UI thread. At most one bubble can be active.
class SpeechRecognitionBubbleController
: public base::RefCountedThreadSafe<SpeechRecognitionBubbleController>,
- public SpeechRecognitionBubbleDelegate,
- public content::NotificationObserver {
+ public SpeechRecognitionBubbleDelegate {
public:
- // All methods of this delegate are called in the IO thread.
+ // All methods of this delegate are called on the IO thread.
class Delegate {
public:
// Invoked when the user clicks on a button in the speech recognition UI.
@@ -51,50 +37,48 @@ class SpeechRecognitionBubbleController
explicit SpeechRecognitionBubbleController(Delegate* delegate);
- // Creates a new speech recognition UI bubble. One of the SetXxxx methods
- // below need to be called to specify what to display.
+ // Creates and shows a new speech recognition UI bubble in warmup mode.
void CreateBubble(int session_id,
int render_process_id,
int render_view_id,
const gfx::Rect& element_rect);
- // Indicates to the user that audio hardware is warming up. This also makes
- // the bubble visible if not already visible.
- void SetBubbleWarmUpMode(int session_id);
+ // Indicates to the user that audio recording is in progress.
+ void SetBubbleRecordingMode();
- // Indicates to the user that audio recording is in progress. This also makes
- // the bubble visible if not already visible.
- void SetBubbleRecordingMode(int session_id);
+ // Indicates to the user that recognition is in progress.
+ void SetBubbleRecognizingMode();
- // Indicates to the user that recognition is in progress. If the bubble is
- // hidden, |Show| must be called to make it appear on screen.
- void SetBubbleRecognizingMode(int session_id);
+ // Displays the given string with the 'Try again' and 'Cancel' buttons.
+ void SetBubbleMessage(const string16& text);
- // Displays the given string with the 'Try again' and 'Cancel' buttons. If the
- // bubble is hidden, |Show| must be called to make it appear on screen.
- void SetBubbleMessage(int session_id, const string16& text);
+ // Checks whether the bubble is active and is showing a message.
+ bool IsShowingMessage() const;
// Updates the current captured audio volume displayed on screen.
- void SetBubbleInputVolume(int session_id, float volume, float noise_volume);
+ void SetBubbleInputVolume(float volume, float noise_volume);
+
+ void CloseBubble();
+
+ // Retrieves the session ID associated to the active bubble (if any).
+ // Returns 0 if no bubble is currently shown.
+ int GetActiveSessionID() const;
- void CloseBubble(int session_id);
+ // Checks whether a bubble is being shown on the RenderView (tab/extension)
+ // identified by the tuple {|render_process_id|,|render_view_id|}
+ bool IsShowingBubbleForRenderView(int render_process_id, int render_view_id);
// SpeechRecognitionBubble::Delegate methods.
virtual void InfoBubbleButtonClicked(
SpeechRecognitionBubble::Button button) OVERRIDE;
virtual void InfoBubbleFocusChanged() OVERRIDE;
- // content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
private:
friend class base::RefCountedThreadSafe<SpeechRecognitionBubbleController>;
- // The various calls received by this object and handled in the UI thread.
+ // The various calls received by this object and handled on the UI thread.
enum RequestType {
- REQUEST_SET_WARM_UP_MODE,
+ REQUEST_CREATE,
REQUEST_SET_RECORDING_MODE,
REQUEST_SET_RECOGNIZING_MODE,
REQUEST_SET_MESSAGE,
@@ -102,45 +86,39 @@ class SpeechRecognitionBubbleController
REQUEST_CLOSE,
};
- enum ManageSubscriptionAction {
- BUBBLE_ADDED,
- BUBBLE_REMOVED
+ struct UIRequest {
+ RequestType type;
+ string16 message;
+ gfx::Rect element_rect;
+ float volume;
+ float noise_volume;
+ int render_process_id;
+ int render_view_id;
+
+ explicit UIRequest(RequestType type_value);
+ ~UIRequest();
};
virtual ~SpeechRecognitionBubbleController();
- void InvokeDelegateButtonClicked(int session_id,
- SpeechRecognitionBubble::Button button);
- void InvokeDelegateFocusChanged(int session_id);
- void ProcessRequestInUiThread(int session_id,
- RequestType type,
- const string16& text,
- float volume,
- float noise_volume);
-
- // Called whenever a bubble was added to or removed from the list. If the
- // bubble was being added, this method registers for close notifications with
- // the WebContents if this was the first bubble for the tab. Similarly if the
- // bubble was being removed, this method unregisters from WebContents if this
- // was the last bubble associated with that tab.
- void UpdateTabContentsSubscription(int session_id,
- ManageSubscriptionAction action);
-
- // Only accessed in the IO thread.
- Delegate* delegate_;
+ void InvokeDelegateButtonClicked(SpeechRecognitionBubble::Button button);
+ void InvokeDelegateFocusChanged();
+ void ProcessRequestInUiThread(const UIRequest& request);
- // *** The following are accessed only in the UI thread.
+ // *** The following are accessed only on the IO thread.
+ Delegate* delegate_;
- // The session id for currently visible bubble (since only one bubble is
- // visible at any time).
+ // The session id for currently visible bubble.
int current_bubble_session_id_;
- // Map of session-ids to bubble objects. The bubbles are weak pointers owned
- // by this object and get destroyed by |CloseBubble|.
- typedef std::map<int, SpeechRecognitionBubble*> BubbleSessionIdMap;
- BubbleSessionIdMap bubbles_;
+ // The render process and view ids for the currently visible bubble.
+ int current_bubble_render_process_id_;
+ int current_bubble_render_view_id_;
+
+ RequestType last_request_issued_;
- scoped_ptr<content::NotificationRegistrar> registrar_;
+ // *** The following are accessed only on the UI thread.
+ scoped_ptr<SpeechRecognitionBubble> bubble_;
};
// This typedef is to workaround the issue with certain versions of