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

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

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