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

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

Issue 1892483002: Drop support for uploading hardware info with speech recognition requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devirtualize_speechrecognitionengine
Patch Set: Created 4 years, 8 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
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_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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // this task (from the UI thread) and this call (on the IO thread). In this 57 // this task (from the UI thread) and this call (on the IO thread). In this
58 // case we just return. 58 // case we just return.
59 if (!manager) 59 if (!manager)
60 return; 60 return;
61 61
62 manager->AbortAllSessionsForRenderView(render_process_id, render_view_id); 62 manager->AbortAllSessionsForRenderView(render_process_id, render_view_id);
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67
68 // Asynchronously fetches the PC and audio hardware/driver info if
69 // the user has opted into UMA. This information is sent with speech input
70 // requests to the server for identifying and improving quality issues with
71 // specific device configurations.
72 class ChromeSpeechRecognitionManagerDelegate::OptionalRequestInfo
73 : public base::RefCountedThreadSafe<OptionalRequestInfo> {
74 public:
75 OptionalRequestInfo() : can_report_metrics_(false) {
76 }
77
78 void Refresh() {
79 DCHECK_CURRENTLY_ON(BrowserThread::IO);
80 // UMA opt-in can be checked only from the UI thread, so switch to that.
81 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
82 base::Bind(&OptionalRequestInfo::CheckUMAAndGetHardwareInfo, this));
83 }
84
85 void CheckUMAAndGetHardwareInfo() {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI);
87 // TODO(hans): Move this check to where hardware info gets sent
88 // crbug.com/533496
89 if (ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) {
90 // Access potentially slow OS calls from the FILE thread.
91 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
92 base::Bind(&OptionalRequestInfo::GetHardwareInfo, this));
93 }
94 }
95
96 void GetHardwareInfo() {
97 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
98 base::AutoLock lock(lock_);
99 can_report_metrics_ = true;
100 base::string16 device_model =
101 SpeechRecognitionManager::GetInstance()->GetAudioInputDeviceModel();
102 #if defined(OS_WIN)
103 value_ = base::UTF16ToUTF8(
104 installer::WMIComputerSystem::GetModel() + L"|" + device_model);
105 #else // defined(OS_WIN)
106 value_ = base::UTF16ToUTF8(device_model);
107 #endif // defined(OS_WIN)
108 }
109
110 std::string value() {
111 base::AutoLock lock(lock_);
112 return value_;
113 }
114
115 bool can_report_metrics() {
116 base::AutoLock lock(lock_);
117 return can_report_metrics_;
118 }
119
120 private:
121 friend class base::RefCountedThreadSafe<OptionalRequestInfo>;
122
123 ~OptionalRequestInfo() {}
124
125 base::Lock lock_;
126 std::string value_;
127 bool can_report_metrics_;
128
129 DISALLOW_COPY_AND_ASSIGN(OptionalRequestInfo);
130 };
131
132 // Simple utility to get notified when a WebContent (a tab or an extension's 67 // Simple utility to get notified when a WebContent (a tab or an extension's
133 // background page) is closed or crashes. The callback will always be called on 68 // background page) is closed or crashes. The callback will always be called on
134 // the UI thread. 69 // the UI thread.
135 // There is no restriction on the constructor, however this class must be 70 // There is no restriction on the constructor, however this class must be
136 // destroyed on the UI thread, due to the NotificationRegistrar dependency. 71 // destroyed on the UI thread, due to the NotificationRegistrar dependency.
137 class ChromeSpeechRecognitionManagerDelegate::TabWatcher 72 class ChromeSpeechRecognitionManagerDelegate::TabWatcher
138 : public base::RefCountedThreadSafe<TabWatcher> { 73 : public base::RefCountedThreadSafe<TabWatcher> {
139 public: 74 public:
140 typedef base::Callback<void(int render_process_id, int render_view_id)> 75 typedef base::Callback<void(int render_process_id, int render_view_id)>
141 TabClosedCallback; 76 TabClosedCallback;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 int session_id, const content::SpeechRecognitionError& error) { 259 int session_id, const content::SpeechRecognitionError& error) {
325 } 260 }
326 261
327 void ChromeSpeechRecognitionManagerDelegate::OnAudioLevelsChange( 262 void ChromeSpeechRecognitionManagerDelegate::OnAudioLevelsChange(
328 int session_id, float volume, float noise_volume) { 263 int session_id, float volume, float noise_volume) {
329 } 264 }
330 265
331 void ChromeSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) { 266 void ChromeSpeechRecognitionManagerDelegate::OnRecognitionEnd(int session_id) {
332 } 267 }
333 268
334 void ChromeSpeechRecognitionManagerDelegate::GetDiagnosticInformation(
335 bool* can_report_metrics,
336 std::string* hardware_info) {
337 DCHECK_CURRENTLY_ON(BrowserThread::IO);
338 if (!optional_request_info_.get()) {
339 optional_request_info_ = new OptionalRequestInfo();
340 // Since hardware info is optional with speech input requests, we start an
341 // asynchronous fetch here and move on with recording audio. This first
342 // speech input request would send an empty string for hardware info and
343 // subsequent requests may have the hardware info available if the fetch
344 // completed before them. This way we don't end up stalling the user with
345 // a long wait and disk seeks when they click on a UI element and start
346 // speaking.
347 optional_request_info_->Refresh();
348 }
349 *can_report_metrics = optional_request_info_->can_report_metrics();
350 *hardware_info = optional_request_info_->value();
351 }
352
353 void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed( 269 void ChromeSpeechRecognitionManagerDelegate::CheckRecognitionIsAllowed(
354 int session_id, 270 int session_id,
355 base::Callback<void(bool ask_user, bool is_allowed)> callback) { 271 base::Callback<void(bool ask_user, bool is_allowed)> callback) {
356 DCHECK_CURRENTLY_ON(BrowserThread::IO); 272 DCHECK_CURRENTLY_ON(BrowserThread::IO);
357 273
358 const content::SpeechRecognitionSessionContext& context = 274 const content::SpeechRecognitionSessionContext& context =
359 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); 275 SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
360 276
361 // Make sure that initiators (extensions/web pages) properly set the 277 // Make sure that initiators (extensions/web pages) properly set the
362 // |render_process_id| field, which is needed later to retrieve the profile. 278 // |render_process_id| field, which is needed later to retrieve the profile.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Otherwise this should be a regular tab contents. 352 // Otherwise this should be a regular tab contents.
437 allowed = true; 353 allowed = true;
438 check_permission = true; 354 check_permission = true;
439 #endif 355 #endif
440 356
441 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 357 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
442 base::Bind(callback, check_permission, allowed)); 358 base::Bind(callback, check_permission, allowed));
443 } 359 }
444 360
445 } // namespace speech 361 } // namespace speech
OLDNEW
« no previous file with comments | « chrome/browser/speech/chrome_speech_recognition_manager_delegate.h ('k') | content/browser/speech/speech_recognition_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698