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

Side by Side Diff: media/midi/midi_manager.cc

Issue 23379002: Web MIDI: fix multi-threading problem around message buffer handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review #12 (for submmit) Created 7 years, 3 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
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "media/midi/midi_manager.h" 5 #include "media/midi/midi_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
9 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
10 11
11 namespace media { 12 namespace media {
12 13
13 #if !defined(OS_MACOSX) 14 #if !defined(OS_MACOSX)
14 // TODO(crogers): implement MIDIManager for other platforms. 15 // TODO(crogers): implement MIDIManager for other platforms.
15 MIDIManager* MIDIManager::Create() { 16 MIDIManager* MIDIManager::Create() {
16 return NULL; 17 return NULL;
17 } 18 }
18 #endif 19 #endif
(...skipping 26 matching lines...) Expand all
45 46
46 void MIDIManager::AddInputPort(const MIDIPortInfo& info) { 47 void MIDIManager::AddInputPort(const MIDIPortInfo& info) {
47 input_ports_.push_back(info); 48 input_ports_.push_back(info);
48 } 49 }
49 50
50 void MIDIManager::AddOutputPort(const MIDIPortInfo& info) { 51 void MIDIManager::AddOutputPort(const MIDIPortInfo& info) {
51 output_ports_.push_back(info); 52 output_ports_.push_back(info);
52 } 53 }
53 54
54 void MIDIManager::ReceiveMIDIData( 55 void MIDIManager::ReceiveMIDIData(
55 int port_index, 56 uint32 port_index,
56 const uint8* data, 57 const uint8* data,
57 size_t length, 58 size_t length,
58 double timestamp) { 59 double timestamp) {
59 base::AutoLock auto_lock(clients_lock_); 60 base::AutoLock auto_lock(clients_lock_);
60 61
61 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) 62 for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i)
62 (*i)->ReceiveMIDIData(port_index, data, length, timestamp); 63 (*i)->ReceiveMIDIData(port_index, data, length, timestamp);
63 } 64 }
64 65
66 bool MIDIManager::CurrentlyOnMIDISendThread() {
67 return send_thread_->message_loop() == base::MessageLoop::current();
68 }
69
65 void MIDIManager::DispatchSendMIDIData(MIDIManagerClient* client, 70 void MIDIManager::DispatchSendMIDIData(MIDIManagerClient* client,
66 int port_index, 71 uint32 port_index,
67 const uint8* data, 72 const std::vector<uint8>& data,
68 size_t length,
69 double timestamp) { 73 double timestamp) {
70 // Lazily create the thread when first needed. 74 // Lazily create the thread when first needed.
71 if (!send_thread_) { 75 if (!send_thread_) {
72 send_thread_.reset(new base::Thread("MIDISendThread")); 76 send_thread_.reset(new base::Thread("MIDISendThread"));
73 send_thread_->Start(); 77 send_thread_->Start();
74 send_message_loop_ = send_thread_->message_loop_proxy(); 78 send_message_loop_ = send_thread_->message_loop_proxy();
75 } 79 }
76 80
77 send_message_loop_->PostTask( 81 send_message_loop_->PostTask(
78 FROM_HERE, 82 FROM_HERE,
79 base::Bind(&MIDIManager::SendMIDIData, base::Unretained(this), 83 base::Bind(&MIDIManager::SendMIDIData, base::Unretained(this),
80 client, port_index, data, length, timestamp)); 84 client, port_index, data, timestamp));
81 } 85 }
82 86
83 } // namespace media 87 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698