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

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

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_input_manager.h" 5 #include "chrome/browser/speech/chrome_speech_input_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/tab_contents/tab_util.h" 16 #include "chrome/browser/tab_contents/tab_util.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/browser/resource_context.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
18 #include "content/public/common/speech_input_result.h" 20 #include "content/public/common/speech_input_result.h"
19 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
20 #include "media/audio/audio_manager.h" 22 #include "media/audio/audio_manager.h"
21 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
22 24
23 #if defined(OS_WIN) 25 #if defined(OS_WIN)
24 #include "chrome/installer/util/wmi.h" 26 #include "chrome/installer/util/wmi.h"
25 #endif 27 #endif
26 28
27 using content::BrowserThread; 29 using content::BrowserThread;
28 30
29 namespace speech_input { 31 namespace speech_input {
30 32
31 // Asynchronously fetches the PC and audio hardware/driver info if 33 // Asynchronously fetches the PC and audio hardware/driver info if
32 // the user has opted into UMA. This information is sent with speech input 34 // the user has opted into UMA. This information is sent with speech input
33 // requests to the server for identifying and improving quality issues with 35 // requests to the server for identifying and improving quality issues with
34 // specific device configurations. 36 // specific device configurations.
35 class ChromeSpeechInputManager::OptionalRequestInfo 37 class ChromeSpeechInputManager::OptionalRequestInfo
36 : public base::RefCountedThreadSafe<OptionalRequestInfo> { 38 : public base::RefCountedThreadSafe<OptionalRequestInfo> {
37 public: 39 public:
38 OptionalRequestInfo() : can_report_metrics_(false) {} 40 explicit OptionalRequestInfo(AudioManager* audio_manager)
41 : can_report_metrics_(false), audio_manager_(audio_manager) {
42 DCHECK(audio_manager_); // Fail early.
43 }
39 44
40 void Refresh() { 45 void Refresh() {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42 // UMA opt-in can be checked only from the UI thread, so switch to that. 47 // UMA opt-in can be checked only from the UI thread, so switch to that.
43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 48 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
44 base::Bind(&OptionalRequestInfo::CheckUMAAndGetHardwareInfo, this)); 49 base::Bind(&OptionalRequestInfo::CheckUMAAndGetHardwareInfo, this));
45 } 50 }
46 51
47 void CheckUMAAndGetHardwareInfo() { 52 void CheckUMAAndGetHardwareInfo() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 if (g_browser_process->local_state()->GetBoolean( 54 if (g_browser_process->local_state()->GetBoolean(
50 prefs::kMetricsReportingEnabled)) { 55 prefs::kMetricsReportingEnabled)) {
51 // Access potentially slow OS calls from the FILE thread. 56 // Access potentially slow OS calls from the FILE thread.
52 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 57 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
53 base::Bind(&OptionalRequestInfo::GetHardwareInfo, this)); 58 base::Bind(&OptionalRequestInfo::GetHardwareInfo, this));
54 } 59 }
55 } 60 }
56 61
57 void GetHardwareInfo() { 62 void GetHardwareInfo() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
59 base::AutoLock lock(lock_); 64 base::AutoLock lock(lock_);
60 can_report_metrics_ = true; 65 can_report_metrics_ = true;
61 #if defined(OS_WIN) 66 #if defined(OS_WIN)
62 value_ = UTF16ToUTF8( 67 value_ = UTF16ToUTF8(
63 installer::WMIComputerSystem::GetModel() + L"|" + 68 installer::WMIComputerSystem::GetModel() + L"|" +
64 AudioManager::GetAudioManager()->GetAudioInputDeviceModel()); 69 audio_manager_->GetAudioInputDeviceModel());
65 #else // defined(OS_WIN) 70 #else // defined(OS_WIN)
66 value_ = UTF16ToUTF8( 71 value_ = UTF16ToUTF8(
67 AudioManager::GetAudioManager()->GetAudioInputDeviceModel()); 72 audio_manager_->GetAudioInputDeviceModel());
68 #endif // defined(OS_WIN) 73 #endif // defined(OS_WIN)
69 } 74 }
70 75
71 std::string value() { 76 std::string value() {
72 base::AutoLock lock(lock_); 77 base::AutoLock lock(lock_);
73 return value_; 78 return value_;
74 } 79 }
75 80
76 bool can_report_metrics() { 81 bool can_report_metrics() {
77 base::AutoLock lock(lock_); 82 base::AutoLock lock(lock_);
78 return can_report_metrics_; 83 return can_report_metrics_;
79 } 84 }
80 85
81 private: 86 private:
82 friend class base::RefCountedThreadSafe<OptionalRequestInfo>; 87 friend class base::RefCountedThreadSafe<OptionalRequestInfo>;
83 88
84 ~OptionalRequestInfo() {} 89 ~OptionalRequestInfo() {}
85 90
86 base::Lock lock_; 91 base::Lock lock_;
87 std::string value_; 92 std::string value_;
88 bool can_report_metrics_; 93 bool can_report_metrics_;
94 scoped_refptr<AudioManager> audio_manager_;
89 95
90 DISALLOW_COPY_AND_ASSIGN(OptionalRequestInfo); 96 DISALLOW_COPY_AND_ASSIGN(OptionalRequestInfo);
91 }; 97 };
92 98
93 ChromeSpeechInputManager* ChromeSpeechInputManager::GetInstance() { 99 ChromeSpeechInputManager* ChromeSpeechInputManager::GetInstance() {
94 return Singleton<ChromeSpeechInputManager>::get(); 100 return Singleton<ChromeSpeechInputManager>::get();
95 } 101 }
96 102
97 ChromeSpeechInputManager::ChromeSpeechInputManager() 103 ChromeSpeechInputManager::ChromeSpeechInputManager()
98 : bubble_controller_(new SpeechInputBubbleController( 104 : bubble_controller_(new SpeechInputBubbleController(
99 ALLOW_THIS_IN_INITIALIZER_LIST(this))) { 105 ALLOW_THIS_IN_INITIALIZER_LIST(this))) {
100 } 106 }
101 107
102 ChromeSpeechInputManager::~ChromeSpeechInputManager() { 108 ChromeSpeechInputManager::~ChromeSpeechInputManager() {
103 } 109 }
104 110
105 void ChromeSpeechInputManager::ShowRecognitionRequested( 111 void ChromeSpeechInputManager::ShowRecognitionRequested(
106 int caller_id, 112 int caller_id,
107 int render_process_id, 113 int render_process_id,
108 int render_view_id, 114 int render_view_id,
109 const gfx::Rect& element_rect) { 115 const gfx::Rect& element_rect) {
110 bubble_controller_->CreateBubble(caller_id, render_process_id, 116 bubble_controller_->CreateBubble(caller_id, render_process_id,
111 render_view_id, element_rect); 117 render_view_id, element_rect);
112 } 118 }
113 119
114 void ChromeSpeechInputManager::GetRequestInfo( 120 void ChromeSpeechInputManager::GetRequestInfo(
115 bool* can_report_metrics, std::string* request_info) { 121 AudioManager* audio_manager,
122 bool* can_report_metrics,
123 std::string* request_info) {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
116 if (!optional_request_info_.get()) { 125 if (!optional_request_info_.get()) {
117 optional_request_info_ = new OptionalRequestInfo(); 126 optional_request_info_ = new OptionalRequestInfo(audio_manager);
118 // Since hardware info is optional with speech input requests, we start an 127 // Since hardware info is optional with speech input requests, we start an
119 // asynchronous fetch here and move on with recording audio. This first 128 // asynchronous fetch here and move on with recording audio. This first
120 // speech input request would send an empty string for hardware info and 129 // speech input request would send an empty string for hardware info and
121 // subsequent requests may have the hardware info available if the fetch 130 // subsequent requests may have the hardware info available if the fetch
122 // completed before them. This way we don't end up stalling the user with 131 // completed before them. This way we don't end up stalling the user with
123 // a long wait and disk seeks when they click on a UI element and start 132 // a long wait and disk seeks when they click on a UI element and start
124 // speaking. 133 // speaking.
125 optional_request_info_->Refresh(); 134 optional_request_info_->Refresh();
126 } 135 }
127 *can_report_metrics = optional_request_info_->can_report_metrics(); 136 *can_report_metrics = optional_request_info_->can_report_metrics();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 StartRecognitionForRequest(caller_id); 221 StartRecognitionForRequest(caller_id);
213 } 222 }
214 } 223 }
215 224
216 void ChromeSpeechInputManager::InfoBubbleFocusChanged(int caller_id) { 225 void ChromeSpeechInputManager::InfoBubbleFocusChanged(int caller_id) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
218 OnFocusChanged(caller_id); 227 OnFocusChanged(caller_id);
219 } 228 }
220 229
221 } // namespace speech_input 230 } // namespace speech_input
OLDNEW
« no previous file with comments | « chrome/browser/speech/chrome_speech_input_manager.h ('k') | chrome/browser/speech/speech_input_bubble_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698