Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/speech/speech_recognition_bubble_controller.h

Issue 10663018: Changing tab closure handling logic in speech recognition code and cleaning bubble controller. (Spe… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Relaxed thread checks for tests. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_ 6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
10
11 #include "base/basictypes.h" 9 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/speech/speech_recognition_bubble.h" 11 #include "chrome/browser/speech/speech_recognition_bubble.h"
15 #include "content/public/browser/notification_observer.h" 12 #include "ui/gfx/rect.h"
16
17 namespace gfx {
18 class Rect;
19 }
20
21 namespace content {
22 class NotificationRegistrar;
23 }
24 13
25 namespace speech { 14 namespace speech {
26 15
27 // This class handles the speech recognition popup UI on behalf of 16 // This class handles the speech recognition popup UI on behalf of
28 // SpeechRecognitionManager, which invokes methods in the IO thread, processing 17 // SpeechRecognitionManager, which invokes methods on the IO thread, processing
29 // those requests in the UI thread. There could be multiple bubble objects alive 18 // those requests on the UI thread. At most one bubble can be active.
30 // at the same time but only one of them is visible to the user. User actions on
31 // that bubble are reported to the delegate.
32 class SpeechRecognitionBubbleController 19 class SpeechRecognitionBubbleController
33 : public base::RefCountedThreadSafe<SpeechRecognitionBubbleController>, 20 : public base::RefCountedThreadSafe<SpeechRecognitionBubbleController>,
34 public SpeechRecognitionBubbleDelegate, 21 public SpeechRecognitionBubbleDelegate {
35 public content::NotificationObserver {
36 public: 22 public:
37 // All methods of this delegate are called in the IO thread. 23 // All methods of this delegate are called on the IO thread.
38 class Delegate { 24 class Delegate {
39 public: 25 public:
40 // Invoked when the user clicks on a button in the speech recognition UI. 26 // Invoked when the user clicks on a button in the speech recognition UI.
41 virtual void InfoBubbleButtonClicked( 27 virtual void InfoBubbleButtonClicked(
42 int session_id, SpeechRecognitionBubble::Button button) = 0; 28 int session_id, SpeechRecognitionBubble::Button button) = 0;
43 29
44 // Invoked when the user clicks outside the speech recognition info bubble 30 // Invoked when the user clicks outside the speech recognition info bubble
45 // causing it to close and input focus to change. 31 // causing it to close and input focus to change.
46 virtual void InfoBubbleFocusChanged(int session_id) = 0; 32 virtual void InfoBubbleFocusChanged(int session_id) = 0;
47 33
48 protected: 34 protected:
49 virtual ~Delegate() {} 35 virtual ~Delegate() {}
50 }; 36 };
51 37
52 explicit SpeechRecognitionBubbleController(Delegate* delegate); 38 explicit SpeechRecognitionBubbleController(Delegate* delegate);
53 39
54 // Creates a new speech recognition UI bubble. One of the SetXxxx methods 40 // Creates and shows a new speech recognition UI bubble in warmup mode.
55 // below need to be called to specify what to display.
56 void CreateBubble(int session_id, 41 void CreateBubble(int session_id,
57 int render_process_id, 42 int render_process_id,
58 int render_view_id, 43 int render_view_id,
59 const gfx::Rect& element_rect); 44 const gfx::Rect& element_rect);
60 45
61 // Indicates to the user that audio hardware is warming up. This also makes 46 // Indicates to the user that audio recording is in progress.
62 // the bubble visible if not already visible. 47 void SetBubbleRecordingMode();
63 void SetBubbleWarmUpMode(int session_id);
64 48
65 // Indicates to the user that audio recording is in progress. This also makes 49 // Indicates to the user that recognition is in progress.
66 // the bubble visible if not already visible. 50 void SetBubbleRecognizingMode();
67 void SetBubbleRecordingMode(int session_id);
68 51
69 // Indicates to the user that recognition is in progress. If the bubble is 52 // Displays the given string with the 'Try again' and 'Cancel' buttons.
70 // hidden, |Show| must be called to make it appear on screen. 53 void SetBubbleMessage(const string16& text);
71 void SetBubbleRecognizingMode(int session_id);
72 54
73 // Displays the given string with the 'Try again' and 'Cancel' buttons. If the 55 // Checks whether the bubble is active and is showing a message.
74 // bubble is hidden, |Show| must be called to make it appear on screen. 56 bool IsShowingMessage() const;
75 void SetBubbleMessage(int session_id, const string16& text);
76 57
77 // Updates the current captured audio volume displayed on screen. 58 // Updates the current captured audio volume displayed on screen.
78 void SetBubbleInputVolume(int session_id, float volume, float noise_volume); 59 void SetBubbleInputVolume(float volume, float noise_volume);
79 60
80 void CloseBubble(int session_id); 61 void CloseBubble();
62
63 // Retrieves the session ID associated to the active bubble (if any).
64 // Returns 0 if no bubble is currently shown.
65 int GetActiveSessionID() const;
66
67 // Checks whether a bubble is being shown on the renderer identified by the
68 // tuple {|render_process_id|,|render_view_id|}
69 bool IsShowingBubbleOn(int render_process_id, int render_view_id);
81 70
82 // SpeechRecognitionBubble::Delegate methods. 71 // SpeechRecognitionBubble::Delegate methods.
83 virtual void InfoBubbleButtonClicked( 72 virtual void InfoBubbleButtonClicked(
84 SpeechRecognitionBubble::Button button) OVERRIDE; 73 SpeechRecognitionBubble::Button button) OVERRIDE;
85 virtual void InfoBubbleFocusChanged() OVERRIDE; 74 virtual void InfoBubbleFocusChanged() OVERRIDE;
86 75
87 // content::NotificationObserver implementation.
88 virtual void Observe(int type,
89 const content::NotificationSource& source,
90 const content::NotificationDetails& details) OVERRIDE;
91
92 private: 76 private:
93 friend class base::RefCountedThreadSafe<SpeechRecognitionBubbleController>; 77 friend class base::RefCountedThreadSafe<SpeechRecognitionBubbleController>;
94 78
95 // The various calls received by this object and handled in the UI thread. 79 // The various calls received by this object and handled on the UI thread.
96 enum RequestType { 80 enum RequestType {
97 REQUEST_SET_WARM_UP_MODE, 81 REQUEST_CREATE,
98 REQUEST_SET_RECORDING_MODE, 82 REQUEST_SET_RECORDING_MODE,
99 REQUEST_SET_RECOGNIZING_MODE, 83 REQUEST_SET_RECOGNIZING_MODE,
100 REQUEST_SET_MESSAGE, 84 REQUEST_SET_MESSAGE,
101 REQUEST_SET_INPUT_VOLUME, 85 REQUEST_SET_INPUT_VOLUME,
102 REQUEST_CLOSE, 86 REQUEST_CLOSE,
103 }; 87 };
104 88
105 enum ManageSubscriptionAction { 89 struct UIRequest {
106 BUBBLE_ADDED, 90 RequestType type;
107 BUBBLE_REMOVED 91 string16 message;
92 gfx::Rect element_rect;
93 float volume;
94 float noise_volume;
95 int render_process_id;
96 int render_view_id;
97
98 explicit UIRequest(RequestType type_value);
99 ~UIRequest();
108 }; 100 };
109 101
110 virtual ~SpeechRecognitionBubbleController(); 102 virtual ~SpeechRecognitionBubbleController();
111 103
112 void InvokeDelegateButtonClicked(int session_id, 104 void InvokeDelegateButtonClicked(SpeechRecognitionBubble::Button button);
113 SpeechRecognitionBubble::Button button); 105 void InvokeDelegateFocusChanged();
114 void InvokeDelegateFocusChanged(int session_id); 106 void ProcessRequestInUiThread(const UIRequest& request);
115 void ProcessRequestInUiThread(int session_id,
116 RequestType type,
117 const string16& text,
118 float volume,
119 float noise_volume);
120 107
121 // Called whenever a bubble was added to or removed from the list. If the 108 // *** The following are accessed only on the IO thread.
122 // bubble was being added, this method registers for close notifications with
123 // the WebContents if this was the first bubble for the tab. Similarly if the
124 // bubble was being removed, this method unregisters from WebContents if this
125 // was the last bubble associated with that tab.
126 void UpdateTabContentsSubscription(int session_id,
127 ManageSubscriptionAction action);
128
129 // Only accessed in the IO thread.
130 Delegate* delegate_; 109 Delegate* delegate_;
131 110
132 // *** The following are accessed only in the UI thread. 111 // The session id for currently visible bubble.
133
134 // The session id for currently visible bubble (since only one bubble is
135 // visible at any time).
136 int current_bubble_session_id_; 112 int current_bubble_session_id_;
137 113
138 // Map of session-ids to bubble objects. The bubbles are weak pointers owned 114 // The render process and view ids for the currently visible bubble.
139 // by this object and get destroyed by |CloseBubble|. 115 int current_bubble_render_process_id_;
140 typedef std::map<int, SpeechRecognitionBubble*> BubbleSessionIdMap; 116 int current_bubble_render_view_id_;
141 BubbleSessionIdMap bubbles_;
142 117
143 scoped_ptr<content::NotificationRegistrar> registrar_; 118 RequestType last_request_issued_;
119
120 // *** The following are accessed only on the UI thread.
121 scoped_ptr<SpeechRecognitionBubble> bubble_;
144 }; 122 };
145 123
146 // This typedef is to workaround the issue with certain versions of 124 // This typedef is to workaround the issue with certain versions of
147 // Visual Studio where it gets confused between multiple Delegate 125 // Visual Studio where it gets confused between multiple Delegate
148 // classes and gives a C2500 error. (I saw this error on the try bots - 126 // classes and gives a C2500 error. (I saw this error on the try bots -
149 // the workaround was not needed for my machine). 127 // the workaround was not needed for my machine).
150 typedef SpeechRecognitionBubbleController::Delegate 128 typedef SpeechRecognitionBubbleController::Delegate
151 SpeechRecognitionBubbleControllerDelegate; 129 SpeechRecognitionBubbleControllerDelegate;
152 130
153 } // namespace speech 131 } // namespace speech
154 132
155 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_ 133 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698