OLD | NEW |
---|---|
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/chrome_speech_recognition_manager_delegate.h" | 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 | 268 |
269 // Note, the session might have been destroyed, therefore avoid calls to the | 269 // Note, the session might have been destroyed, therefore avoid calls to the |
270 // manager which imply its existance (e.g., GetSessionContext()). | 270 // manager which imply its existance (e.g., GetSessionContext()). |
271 GetBubbleController()->CloseBubble(); | 271 GetBubbleController()->CloseBubble(); |
272 last_session_config_.reset(); | 272 last_session_config_.reset(); |
273 | 273 |
274 // Clicking outside the bubble means we should abort. | 274 // Clicking outside the bubble means we should abort. |
275 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); | 275 SpeechRecognitionManager::GetInstance()->AbortSession(session_id); |
276 } | 276 } |
277 | 277 |
278 void ChromeSpeechRecognitionManagerDelegate::RestartLastSession() { | 278 void ChromeSpeechRecognitionManagerDelegate::RestartLastSession() { |
tommi (sloooow) - chröme
2013/03/28 10:38:46
Hmm... rename to MaybeRestartLastSession?
| |
279 DCHECK(last_session_config_.get()); | 279 if (!last_session_config_.get()) |
280 return; | |
tommi (sloooow) - chröme
2013/03/28 10:38:46
what effect does this have on the functionality?
A
| |
281 | |
280 SpeechRecognitionManager* manager = SpeechRecognitionManager::GetInstance(); | 282 SpeechRecognitionManager* manager = SpeechRecognitionManager::GetInstance(); |
281 const int new_session_id = manager->CreateSession(*last_session_config_); | 283 const int new_session_id = manager->CreateSession(*last_session_config_); |
282 DCHECK_NE(SpeechRecognitionManager::kSessionIDInvalid, new_session_id); | 284 DCHECK_NE(SpeechRecognitionManager::kSessionIDInvalid, new_session_id); |
283 last_session_config_.reset(); | 285 last_session_config_.reset(); |
284 manager->StartSession(new_session_id); | 286 manager->StartSession(new_session_id); |
285 } | 287 } |
286 | 288 |
287 void ChromeSpeechRecognitionManagerDelegate::TabClosedCallback( | 289 void ChromeSpeechRecognitionManagerDelegate::TabClosedCallback( |
288 int render_process_id, int render_view_id) { | 290 int render_process_id, int render_view_id) { |
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 14 matching lines...) Expand all Loading... | |
304 } | 306 } |
305 } | 307 } |
306 | 308 |
307 void ChromeSpeechRecognitionManagerDelegate::OnRecognitionStart( | 309 void ChromeSpeechRecognitionManagerDelegate::OnRecognitionStart( |
308 int session_id) { | 310 int session_id) { |
309 const content::SpeechRecognitionSessionContext& context = | 311 const content::SpeechRecognitionSessionContext& context = |
310 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); | 312 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); |
311 | 313 |
312 if (RequiresBubble(session_id)) { | 314 if (RequiresBubble(session_id)) { |
313 // Copy the configuration of the session (for the "try again" button). | 315 // Copy the configuration of the session (for the "try again" button). |
314 last_session_config_.reset(new content::SpeechRecognitionSessionConfig( | 316 last_session_config_.reset(new content::SpeechRecognitionSessionConfig( |
tommi (sloooow) - chröme
2013/03/28 10:38:46
I'm looking for this constructor in the code but I
| |
315 SpeechRecognitionManager::GetInstance()->GetSessionConfig(session_id))); | 317 SpeechRecognitionManager::GetInstance()->GetSessionConfig(session_id))); |
316 | 318 |
317 // Create and show the bubble. | 319 // Create and show the bubble. |
318 GetBubbleController()->CreateBubble(session_id, | 320 GetBubbleController()->CreateBubble(session_id, |
319 context.render_process_id, | 321 context.render_process_id, |
320 context.render_view_id, | 322 context.render_view_id, |
321 context.element_rect); | 323 context.element_rect); |
322 } | 324 } |
323 | 325 |
324 // Register callback to auto abort session on tab closure. | 326 // Register callback to auto abort session on tab closure. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 context.render_process_id, | 467 context.render_process_id, |
466 context.render_view_id, | 468 context.render_view_id, |
467 RequiresTrayIcon(session_id))); | 469 RequiresTrayIcon(session_id))); |
468 } | 470 } |
469 | 471 |
470 content::SpeechRecognitionEventListener* | 472 content::SpeechRecognitionEventListener* |
471 ChromeSpeechRecognitionManagerDelegate::GetEventListener() { | 473 ChromeSpeechRecognitionManagerDelegate::GetEventListener() { |
472 return this; | 474 return this; |
473 } | 475 } |
474 | 476 |
477 void ChromeSpeechRecognitionManagerDelegate::OnAbortSessionsForListener( | |
478 SpeechRecognitionEventListener* listener) { | |
tommi (sloooow) - chröme
2013/03/28 10:38:46
Passing the listener here feels hacky. I would ra
| |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
480 if (last_session_config_->event_listener == listener) | |
481 last_session_config_.reset(); | |
482 } | |
483 | |
475 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( | 484 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( |
476 base::Callback<void(bool ask_user, bool is_allowed)> callback, | 485 base::Callback<void(bool ask_user, bool is_allowed)> callback, |
477 int render_process_id, | 486 int render_process_id, |
478 int render_view_id, | 487 int render_view_id, |
479 bool js_api) { | 488 bool js_api) { |
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
481 const content::RenderViewHost* render_view_host = | 490 const content::RenderViewHost* render_view_host = |
482 content::RenderViewHost::FromID(render_process_id, render_view_id); | 491 content::RenderViewHost::FromID(render_process_id, render_view_id); |
483 | 492 |
484 bool allowed = false; | 493 bool allowed = false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 } | 532 } |
524 | 533 |
525 SpeechRecognitionBubbleController* | 534 SpeechRecognitionBubbleController* |
526 ChromeSpeechRecognitionManagerDelegate::GetBubbleController() { | 535 ChromeSpeechRecognitionManagerDelegate::GetBubbleController() { |
527 if (!bubble_controller_.get()) | 536 if (!bubble_controller_.get()) |
528 bubble_controller_ = new SpeechRecognitionBubbleController(this); | 537 bubble_controller_ = new SpeechRecognitionBubbleController(this); |
529 return bubble_controller_.get(); | 538 return bubble_controller_.get(); |
530 } | 539 } |
531 | 540 |
532 } // namespace speech | 541 } // namespace speech |
OLD | NEW |