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

Unified Diff: content/renderer/media/audio_device.h

Issue 9317001: Revert 119769 - Switch AudioDevice classes from SyncSocket to CancelableSyncSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1025/src/
Patch Set: Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.cc ('k') | content/renderer/media/audio_device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/audio_device.h
===================================================================
--- content/renderer/media/audio_device.h (revision 119920)
+++ content/renderer/media/audio_device.h (working copy)
@@ -142,6 +142,33 @@
virtual void OnVolume(double volume) OVERRIDE;
private:
+ // Encapsulate socket into separate class to avoid double-close.
+ // Class is ref-counted to avoid potential race condition if audio device
+ // is deleted simultaneously with audio thread stopping.
+ class AudioSocket : public base::RefCountedThreadSafe<AudioSocket> {
+ public:
+ explicit AudioSocket(base::SyncSocket::Handle socket_handle)
+ : socket_(socket_handle) {
+ }
+ base::SyncSocket* socket() {
+ return &socket_;
+ }
+ void Close() {
+ // Close() should be thread-safe, obtain the lock.
+ base::AutoLock auto_lock(lock_);
+ socket_.Close();
+ }
+
+ private:
+ // Magic required by ref_counted.h to avoid any code deleting the object
+ // accidentally while there are references to it.
+ friend class base::RefCountedThreadSafe<AudioSocket>;
+ ~AudioSocket() { }
+
+ base::Lock lock_;
+ base::SyncSocket socket_;
+ };
+
// Magic required by ref_counted.h to avoid any code deleting the object
// accidentally while there are references to it.
friend class base::RefCountedThreadSafe<AudioDevice>;
@@ -221,7 +248,7 @@
// These variables must only be set on the IO thread while the audio_thread_
// is not running.
base::SharedMemoryHandle shared_memory_handle_;
- scoped_ptr<base::CancelableSyncSocket> audio_socket_;
+ scoped_refptr<AudioSocket> audio_socket_;
int memory_length_;
DISALLOW_COPY_AND_ASSIGN(AudioDevice);
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.cc ('k') | content/renderer/media/audio_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698