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

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

Issue 10890023: Miscellaneous cleanups from several months ago I never got around to landing. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 #include "chrome/browser/speech/speech_recognition_bubble_controller.h" 5 #include "chrome/browser/speech/speech_recognition_bubble_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/tab_contents/tab_util.h" 8 #include "chrome/browser/tab_contents/tab_util.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/notification_registrar.h" 10 #include "content/public/browser/notification_registrar.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 UIRequest request(REQUEST_SET_MESSAGE); 64 UIRequest request(REQUEST_SET_MESSAGE);
65 request.message = text; 65 request.message = text;
66 ProcessRequestInUiThread(request); 66 ProcessRequestInUiThread(request);
67 } 67 }
68 68
69 bool SpeechRecognitionBubbleController::IsShowingMessage() const { 69 bool SpeechRecognitionBubbleController::IsShowingMessage() const {
70 return last_request_issued_ == REQUEST_SET_MESSAGE; 70 return last_request_issued_ == REQUEST_SET_MESSAGE;
71 } 71 }
72 72
73 void SpeechRecognitionBubbleController::SetBubbleInputVolume( 73 void SpeechRecognitionBubbleController::SetBubbleInputVolume(
74 float volume, float noise_volume) { 74 float volume,
75 float noise_volume) {
75 UIRequest request(REQUEST_SET_INPUT_VOLUME); 76 UIRequest request(REQUEST_SET_INPUT_VOLUME);
76 request.volume = volume; 77 request.volume = volume;
77 request.noise_volume = noise_volume; 78 request.noise_volume = noise_volume;
78 ProcessRequestInUiThread(request); 79 ProcessRequestInUiThread(request);
79 } 80 }
80 81
81 void SpeechRecognitionBubbleController::CloseBubble() { 82 void SpeechRecognitionBubbleController::CloseBubble() {
82 current_bubble_session_id_ = kInvalidSessionId; 83 current_bubble_session_id_ = kInvalidSessionId;
83 ProcessRequestInUiThread(UIRequest(REQUEST_CLOSE)); 84 ProcessRequestInUiThread(UIRequest(REQUEST_CLOSE));
84 } 85 }
85 86
86 int SpeechRecognitionBubbleController::GetActiveSessionID() const { 87 int SpeechRecognitionBubbleController::GetActiveSessionID() const {
87 return current_bubble_session_id_; 88 return current_bubble_session_id_;
88 } 89 }
89 90
90 bool SpeechRecognitionBubbleController::IsShowingBubbleForRenderView( 91 bool SpeechRecognitionBubbleController::IsShowingBubbleForRenderView(
91 int render_process_id, int render_view_id) { 92 int render_process_id,
93 int render_view_id) {
92 return (current_bubble_session_id_ != kInvalidSessionId) && 94 return (current_bubble_session_id_ != kInvalidSessionId) &&
93 (current_bubble_render_process_id_ == render_process_id) && 95 (current_bubble_render_process_id_ == render_process_id) &&
94 (current_bubble_render_view_id_ == render_view_id); 96 (current_bubble_render_view_id_ == render_view_id);
95 } 97 }
96 98
97 void SpeechRecognitionBubbleController::InfoBubbleButtonClicked( 99 void SpeechRecognitionBubbleController::InfoBubbleButtonClicked(
98 SpeechRecognitionBubble::Button button) { 100 SpeechRecognitionBubble::Button button) {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
100 BrowserThread::PostTask( 102 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
101 BrowserThread::IO, FROM_HERE,
102 base::Bind( 103 base::Bind(
103 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, 104 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, this,
104 this, button)); 105 button));
105 } 106 }
106 107
107 void SpeechRecognitionBubbleController::InfoBubbleFocusChanged() { 108 void SpeechRecognitionBubbleController::InfoBubbleFocusChanged() {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 BrowserThread::PostTask( 110 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
110 BrowserThread::IO, FROM_HERE, 111 base::Bind(&SpeechRecognitionBubbleController::InvokeDelegateFocusChanged,
111 base::Bind( 112 this));
112 &SpeechRecognitionBubbleController::InvokeDelegateFocusChanged,
113 this));
114 } 113 }
115 114
116 void SpeechRecognitionBubbleController::InvokeDelegateButtonClicked( 115 void SpeechRecognitionBubbleController::InvokeDelegateButtonClicked(
117 SpeechRecognitionBubble::Button button) { 116 SpeechRecognitionBubble::Button button) {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
119 DCHECK_NE(kInvalidSessionId, current_bubble_session_id_); 118 DCHECK_NE(kInvalidSessionId, current_bubble_session_id_);
120 delegate_->InfoBubbleButtonClicked(current_bubble_session_id_, button); 119 delegate_->InfoBubbleButtonClicked(current_bubble_session_id_, button);
121 } 120 }
122 121
123 void SpeechRecognitionBubbleController::InvokeDelegateFocusChanged() { 122 void SpeechRecognitionBubbleController::InvokeDelegateFocusChanged() {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
125 DCHECK_NE(kInvalidSessionId, current_bubble_session_id_); 124 DCHECK_NE(kInvalidSessionId, current_bubble_session_id_);
126 delegate_->InfoBubbleFocusChanged(current_bubble_session_id_); 125 delegate_->InfoBubbleFocusChanged(current_bubble_session_id_);
127 } 126 }
128 127
129 void SpeechRecognitionBubbleController::ProcessRequestInUiThread( 128 void SpeechRecognitionBubbleController::ProcessRequestInUiThread(
130 const UIRequest& request) { 129 const UIRequest& request) {
131 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 130 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
132 last_request_issued_ = request.type; 131 last_request_issued_ = request.type;
133 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
134 &SpeechRecognitionBubbleController::ProcessRequestInUiThread, 133 base::Bind(&SpeechRecognitionBubbleController::ProcessRequestInUiThread,
135 this, 134 this, request));
136 request));
137 return; 135 return;
138 } 136 }
139 137
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
141 139
142 switch (request.type) { 140 switch (request.type) {
143 case REQUEST_CREATE: 141 case REQUEST_CREATE:
144 bubble_.reset(SpeechRecognitionBubble::Create( 142 bubble_.reset(SpeechRecognitionBubble::Create(
145 tab_util::GetWebContentsByID(request.render_process_id, 143 tab_util::GetWebContentsByID(request.render_process_id,
146 request.render_view_id), 144 request.render_view_id),
147 this, 145 this, request.element_rect));
148 request.element_rect));
149 146
150 if (!bubble_.get()) { 147 if (!bubble_.get()) {
151 // Could be null if tab or display rect were invalid. 148 // Could be null if tab or display rect were invalid.
152 // Simulate the cancel button being clicked to inform the delegate. 149 // Simulate the cancel button being clicked to inform the delegate.
153 BrowserThread::PostTask( 150 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
154 BrowserThread::IO, FROM_HERE, base::Bind( 151 base::Bind(
155 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked, 152 &SpeechRecognitionBubbleController::InvokeDelegateButtonClicked,
156 this, SpeechRecognitionBubble::BUTTON_CANCEL)); 153 this, SpeechRecognitionBubble::BUTTON_CANCEL));
157 return; 154 return;
158 } 155 }
159 bubble_->Show(); 156 bubble_->Show();
160 bubble_->SetWarmUpMode(); 157 bubble_->SetWarmUpMode();
161 break; 158 break;
162 case REQUEST_SET_RECORDING_MODE: 159 case REQUEST_SET_RECORDING_MODE:
163 DCHECK(bubble_.get()); 160 DCHECK(bubble_.get());
164 bubble_->SetRecordingMode(); 161 bubble_->SetRecordingMode();
(...skipping 24 matching lines...) Expand all
189 volume(0.0F), 186 volume(0.0F),
190 noise_volume(0.0F), 187 noise_volume(0.0F),
191 render_process_id(0), 188 render_process_id(0),
192 render_view_id(0) { 189 render_view_id(0) {
193 } 190 }
194 191
195 SpeechRecognitionBubbleController::UIRequest::~UIRequest() { 192 SpeechRecognitionBubbleController::UIRequest::~UIRequest() {
196 } 193 }
197 194
198 } // namespace speech 195 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698