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

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
86 void InvokeDelegateButtonClicked(int caller_id, 94 void InvokeDelegateButtonClicked(int caller_id,
87 SpeechInputBubble::Button button); 95 SpeechInputBubble::Button button);
88 void InvokeDelegateFocusChanged(int caller_id); 96 void InvokeDelegateFocusChanged(int caller_id);
89 void ProcessRequestInUiThread(int caller_id, 97 void ProcessRequestInUiThread(int caller_id,
90 RequestType type, 98 RequestType type,
91 const string16& text, 99 const string16& text,
92 float volume); 100 float volume);
93 101
102 // Whether the given bubble (IDed by caller_id) is the only one in our list
103 // linked to that TabContents. Returns false if there are more such bubbles
104 // in our list.
105 bool IsOnlyBubbleForTab(int caller_id);
106
94 // Only accessed in the IO thread. 107 // Only accessed in the IO thread.
95 Delegate* delegate_; 108 Delegate* delegate_;
96 109
97 //*** The following are accessed only in the UI thread. 110 //*** The following are accessed only in the UI thread.
98 111
99 // The caller id for currently visible bubble (since only one bubble is 112 // The caller id for currently visible bubble (since only one bubble is
100 // visible at any time). 113 // visible at any time).
101 int current_bubble_caller_id_; 114 int current_bubble_caller_id_;
102 115
103 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by 116 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by
104 // this object and get destroyed by |CloseBubble|. 117 // this object and get destroyed by |CloseBubble|.
105 std::map<int, SpeechInputBubble*> bubbles_; 118 typedef std::map<int, SpeechInputBubble*> BubbleCallerIdMap;
119 BubbleCallerIdMap bubbles_;
120
121 scoped_ptr<NotificationRegistrar> registrar_;
bulach 2011/01/06 12:32:39 I think this is normally used directly rather than
Satish 2011/01/06 12:57:02 A few reviewers suggested in the past to reduce th
106 }; 122 };
107 123
108 // This typedef is to workaround the issue with certain versions of 124 // This typedef is to workaround the issue with certain versions of
109 // Visual Studio where it gets confused between multiple Delegate 125 // Visual Studio where it gets confused between multiple Delegate
110 // 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 -
111 // the workaround was not needed for my machine). 127 // the workaround was not needed for my machine).
112 typedef SpeechInputBubbleController::Delegate 128 typedef SpeechInputBubbleController::Delegate
113 SpeechInputBubbleControllerDelegate; 129 SpeechInputBubbleControllerDelegate;
114 130
115 } // namespace speech_input 131 } // namespace speech_input
116 132
117 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ 133 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698