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

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

Issue 6115001: Listen for tab close notifications and cancel active speech sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_INPUT_BUBBLE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "chrome/browser/speech/speech_input_bubble.h" 13 #include "chrome/browser/speech/speech_input_bubble.h"
14 #include "chrome/common/notification_observer.h"
14 15
15 namespace gfx { 16 namespace gfx {
16 class Rect; 17 class Rect;
17 } 18 }
19 class NotificationRegistrar;
18 20
19 namespace speech_input { 21 namespace speech_input {
20 22
21 // This class handles the speech input popup UI on behalf of SpeechInputManager. 23 // This class handles the speech input popup UI on behalf of SpeechInputManager.
22 // SpeechInputManager invokes methods in the IO thread and this class processes 24 // SpeechInputManager invokes methods in the IO thread and this class processes
23 // those requests in the UI thread. There could be multiple bubble objects alive 25 // those requests in the UI thread. There could be multiple bubble objects alive
24 // at the same time but only one of them is visible to the user. User actions on 26 // at the same time but only one of them is visible to the user. User actions on
25 // that bubble are reported to the delegate. 27 // that bubble are reported to the delegate.
26 class SpeechInputBubbleController 28 class SpeechInputBubbleController
27 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, 29 : public base::RefCountedThreadSafe<SpeechInputBubbleController>,
28 public SpeechInputBubbleDelegate { 30 public SpeechInputBubbleDelegate,
31 public NotificationObserver {
29 public: 32 public:
30 // All methods of this delegate are called in the IO thread. 33 // All methods of this delegate are called in the IO thread.
31 class Delegate { 34 class Delegate {
32 public: 35 public:
33 // Invoked when the user clicks on a button in the speech input UI. 36 // Invoked when the user clicks on a button in the speech input UI.
34 virtual void InfoBubbleButtonClicked(int caller_id, 37 virtual void InfoBubbleButtonClicked(int caller_id,
35 SpeechInputBubble::Button button) = 0; 38 SpeechInputBubble::Button button) = 0;
36 39
37 // Invoked when the user clicks outside the speech input info bubble causing 40 // Invoked when the user clicks outside the speech input info bubble causing
38 // it to close and input focus to change. 41 // it to close and input focus to change.
(...skipping 27 matching lines...) Expand all
66 69
67 // Updates the current captured audio volume displayed on screen. 70 // Updates the current captured audio volume displayed on screen.
68 void SetBubbleInputVolume(int caller_id, float volume); 71 void SetBubbleInputVolume(int caller_id, float volume);
69 72
70 void CloseBubble(int caller_id); 73 void CloseBubble(int caller_id);
71 74
72 // SpeechInputBubble::Delegate methods. 75 // SpeechInputBubble::Delegate methods.
73 virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button); 76 virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button);
74 virtual void InfoBubbleFocusChanged(); 77 virtual void InfoBubbleFocusChanged();
75 78
79 // NotificationObserver implementation.
80 virtual void Observe(NotificationType type,
81 const NotificationSource& source,
82 const NotificationDetails& details);
83
76 private: 84 private:
77 // The various calls received by this object and handled in the UI thread. 85 // The various calls received by this object and handled in the UI thread.
78 enum RequestType { 86 enum RequestType {
79 REQUEST_SET_RECORDING_MODE, 87 REQUEST_SET_RECORDING_MODE,
80 REQUEST_SET_RECOGNIZING_MODE, 88 REQUEST_SET_RECOGNIZING_MODE,
81 REQUEST_SET_MESSAGE, 89 REQUEST_SET_MESSAGE,
82 REQUEST_SET_INPUT_VOLUME, 90 REQUEST_SET_INPUT_VOLUME,
83 REQUEST_CLOSE, 91 REQUEST_CLOSE,
84 }; 92 };
85 93
94 enum ManageSubscriptionAction {
95 BUBBLE_ADDED,
96 BUBBLE_REMOVED
97 };
98
86 void InvokeDelegateButtonClicked(int caller_id, 99 void InvokeDelegateButtonClicked(int caller_id,
87 SpeechInputBubble::Button button); 100 SpeechInputBubble::Button button);
88 void InvokeDelegateFocusChanged(int caller_id); 101 void InvokeDelegateFocusChanged(int caller_id);
89 void ProcessRequestInUiThread(int caller_id, 102 void ProcessRequestInUiThread(int caller_id,
90 RequestType type, 103 RequestType type,
91 const string16& text, 104 const string16& text,
92 float volume); 105 float volume);
93 106
107 // Called whenever a bubble was added to or removed from the list. If the
108 // bubble was being added, this method registers for close notifications with
109 // the TabContents if this was the first bubble for the tab. Similarly if the
110 // bubble was being removed, this method unregisters from TabContents if this
111 // was the last bubble associated with that tab.
112 void UpdateTabContentsSubscription(int caller_id,
113 ManageSubscriptionAction action);
114
115 // Whether the given bubble (IDed by caller_id) is the only one in our list
116 // linked to that TabContents. Returns false if there are more such bubbles
117 // in our list.
118 bool IsOnlyBubbleForTab(int caller_id);
bulach 2011/01/06 14:31:44 remove?
Satish 2011/01/07 10:57:34 Done.
119
94 // Only accessed in the IO thread. 120 // Only accessed in the IO thread.
95 Delegate* delegate_; 121 Delegate* delegate_;
96 122
97 //*** The following are accessed only in the UI thread. 123 //*** The following are accessed only in the UI thread.
98 124
99 // The caller id for currently visible bubble (since only one bubble is 125 // The caller id for currently visible bubble (since only one bubble is
100 // visible at any time). 126 // visible at any time).
101 int current_bubble_caller_id_; 127 int current_bubble_caller_id_;
102 128
103 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by 129 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by
104 // this object and get destroyed by |CloseBubble|. 130 // this object and get destroyed by |CloseBubble|.
105 std::map<int, SpeechInputBubble*> bubbles_; 131 typedef std::map<int, SpeechInputBubble*> BubbleCallerIdMap;
132 BubbleCallerIdMap bubbles_;
133
134 scoped_ptr<NotificationRegistrar> registrar_;
106 }; 135 };
107 136
108 // This typedef is to workaround the issue with certain versions of 137 // This typedef is to workaround the issue with certain versions of
109 // Visual Studio where it gets confused between multiple Delegate 138 // Visual Studio where it gets confused between multiple Delegate
110 // classes and gives a C2500 error. (I saw this error on the try bots - 139 // classes and gives a C2500 error. (I saw this error on the try bots -
111 // the workaround was not needed for my machine). 140 // the workaround was not needed for my machine).
112 typedef SpeechInputBubbleController::Delegate 141 typedef SpeechInputBubbleController::Delegate
113 SpeechInputBubbleControllerDelegate; 142 SpeechInputBubbleControllerDelegate;
114 143
115 } // namespace speech_input 144 } // namespace speech_input
116 145
117 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ 146 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_input_bubble.cc ('k') | chrome/browser/speech/speech_input_bubble_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698