Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/media/audio_debug_recordings_handler.h" | 5 #include "chrome/browser/media/audio_debug_recordings_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/media/webrtc/webrtc_log_list.h" | 15 #include "chrome/browser/media/webrtc/webrtc_log_list.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "media/audio/audio_manager.h" | |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 // Keys used to attach handler to the RenderProcessHost | 24 // Keys used to attach handler to the RenderProcessHost |
| 24 const char AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey[] = | 25 const char AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey[] = |
| 25 "kAudioDebugRecordingsHandlerKey"; | 26 "kAudioDebugRecordingsHandlerKey"; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Returns a path name to be used as prefix for audio debug recordings files. | 30 // Returns a path name to be used as prefix for audio debug recordings files. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 if (is_audio_debug_recordings_in_progress_) { | 100 if (is_audio_debug_recordings_in_progress_) { |
| 100 error_callback.Run("Audio debug recordings already in progress"); | 101 error_callback.Run("Audio debug recordings already in progress"); |
| 101 return; | 102 return; |
| 102 } | 103 } |
| 103 | 104 |
| 104 is_audio_debug_recordings_in_progress_ = true; | 105 is_audio_debug_recordings_in_progress_ = true; |
| 105 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( | 106 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( |
| 106 log_directory, ++current_audio_debug_recordings_id_); | 107 log_directory, ++current_audio_debug_recordings_id_); |
| 107 host->EnableAudioDebugRecordings(prefix_path); | 108 host->EnableAudioDebugRecordings(prefix_path); |
| 108 | 109 |
| 110 // AudioManager is deleted on the audio thread, and the AudioManager outlives | |
| 111 // this object, so it's safe to post unretained. | |
|
o1ka
2017/01/31 11:00:11
Add why media::AudioManager::Get() is safe (or bet
Henrik Grunell
2017/02/08 11:29:37
Changed to a pointer injected.
| |
| 112 media::AudioManager* audio_manager = media::AudioManager::Get(); | |
|
Max Morin
2017/01/30 10:24:01
The AudioManager::Get() pointer is nulled on the U
Henrik Grunell
2017/01/30 14:11:26
I'll double check that tomorrow.
Henrik Grunell
2017/02/08 11:29:37
This class lives on the UI thread, which is implic
| |
| 113 audio_manager->GetTaskRunner()->PostTask( | |
| 114 FROM_HERE, base::Bind(&media::AudioManager::EnableOutputDebugRecording, | |
| 115 base::Unretained(audio_manager), prefix_path)); | |
| 116 | |
| 109 if (delay.is_zero()) { | 117 if (delay.is_zero()) { |
| 110 const bool is_stopped = false, is_manual_stop = false; | 118 const bool is_stopped = false, is_manual_stop = false; |
| 111 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 119 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 112 return; | 120 return; |
| 113 } | 121 } |
| 114 | 122 |
| 115 const bool is_manual_stop = false; | 123 const bool is_manual_stop = false; |
| 116 BrowserThread::PostDelayedTask( | 124 BrowserThread::PostDelayedTask( |
| 117 BrowserThread::UI, FROM_HERE, | 125 BrowserThread::UI, FROM_HERE, |
| 118 base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this, | 126 base::Bind(&AudioDebugRecordingsHandler::DoStopAudioDebugRecordings, this, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 142 const bool is_stopped = false; | 150 const bool is_stopped = false; |
| 143 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 151 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 144 return; | 152 return; |
| 145 } | 153 } |
| 146 | 154 |
| 147 if (!is_audio_debug_recordings_in_progress_) { | 155 if (!is_audio_debug_recordings_in_progress_) { |
| 148 error_callback.Run("No audio debug recording in progress"); | 156 error_callback.Run("No audio debug recording in progress"); |
| 149 return; | 157 return; |
| 150 } | 158 } |
| 151 | 159 |
| 160 // AudioManager is deleted on the audio thread, and the AudioManager outlives | |
| 161 // this object, so it's safe to post unretained. | |
| 162 media::AudioManager* audio_manager = media::AudioManager::Get(); | |
| 163 audio_manager->GetTaskRunner()->PostTask( | |
| 164 FROM_HERE, base::Bind(&media::AudioManager::DisableOutputDebugRecording, | |
| 165 base::Unretained(audio_manager))); | |
| 166 | |
| 152 host->DisableAudioDebugRecordings(); | 167 host->DisableAudioDebugRecordings(); |
| 168 | |
| 153 is_audio_debug_recordings_in_progress_ = false; | 169 is_audio_debug_recordings_in_progress_ = false; |
| 154 const bool is_stopped = true; | 170 const bool is_stopped = true; |
| 155 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); | 171 callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop); |
| 156 } | 172 } |
| OLD | NEW |