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

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

Issue 664843002: Web MIDI: distributes MIDIPort information asynchronously (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lifecycle
Patch Set: . => -> Created 6 years, 2 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
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_unittest.cc » ('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/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // CompleteInitialization() will be called asynchronously when platform 70 // CompleteInitialization() will be called asynchronously when platform
71 // dependent initialization is finished. 71 // dependent initialization is finished.
72 return; 72 return;
73 } 73 }
74 74
75 // Platform dependent initialization was already finished for previously 75 // Platform dependent initialization was already finished for previously
76 // initialized clients. 76 // initialized clients.
77 MidiResult result; 77 MidiResult result;
78 { 78 {
79 base::AutoLock auto_lock(lock_); 79 base::AutoLock auto_lock(lock_);
80 if (result_ == MIDI_OK) 80 if (result_ == MIDI_OK) {
81 AddInitialPorts(client);
81 clients_.insert(client); 82 clients_.insert(client);
83 }
82 result = result_; 84 result = result_;
83 } 85 }
84 client->CompleteStartSession(result); 86 client->CompleteStartSession(result);
85 } 87 }
86 88
87 void MidiManager::EndSession(MidiManagerClient* client) { 89 void MidiManager::EndSession(MidiManagerClient* client) {
88 // At this point, |client| can be in the destruction process, and calling 90 // At this point, |client| can be in the destruction process, and calling
89 // any method of |client| is dangerous. 91 // any method of |client| is dangerous.
90 base::AutoLock auto_lock(lock_); 92 base::AutoLock auto_lock(lock_);
91 clients_.erase(client); 93 clients_.erase(client);
(...skipping 16 matching lines...) Expand all
108 // It is safe to post a task to the IO thread from here because the IO thread 110 // It is safe to post a task to the IO thread from here because the IO thread
109 // should have stopped if the MidiManager is going to be destructed. 111 // should have stopped if the MidiManager is going to be destructed.
110 session_thread_runner_->PostTask( 112 session_thread_runner_->PostTask(
111 FROM_HERE, 113 FROM_HERE,
112 base::Bind(&MidiManager::CompleteInitializationInternal, 114 base::Bind(&MidiManager::CompleteInitializationInternal,
113 base::Unretained(this), 115 base::Unretained(this),
114 result)); 116 result));
115 } 117 }
116 118
117 void MidiManager::AddInputPort(const MidiPortInfo& info) { 119 void MidiManager::AddInputPort(const MidiPortInfo& info) {
120 base::AutoLock auto_lock(lock_);
118 input_ports_.push_back(info); 121 input_ports_.push_back(info);
122 for (auto client : clients_)
123 client->AddInputPort(info);
119 } 124 }
120 125
121 void MidiManager::AddOutputPort(const MidiPortInfo& info) { 126 void MidiManager::AddOutputPort(const MidiPortInfo& info) {
127 base::AutoLock auto_lock(lock_);
122 output_ports_.push_back(info); 128 output_ports_.push_back(info);
129 for (auto client : clients_)
130 client->AddOutputPort(info);
123 } 131 }
124 132
125 void MidiManager::ReceiveMidiData( 133 void MidiManager::ReceiveMidiData(
126 uint32 port_index, 134 uint32 port_index,
127 const uint8* data, 135 const uint8* data,
128 size_t length, 136 size_t length,
129 double timestamp) { 137 double timestamp) {
130 base::AutoLock auto_lock(lock_); 138 base::AutoLock auto_lock(lock_);
131 139
132 for (MidiManagerClient* client : clients_) 140 for (auto client : clients_)
133 client->ReceiveMidiData(port_index, data, length, timestamp); 141 client->ReceiveMidiData(port_index, data, length, timestamp);
134 } 142 }
135 143
136 void MidiManager::CompleteInitializationInternal(MidiResult result) { 144 void MidiManager::CompleteInitializationInternal(MidiResult result) {
137 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); 145 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization");
138 146
139 base::AutoLock auto_lock(lock_); 147 base::AutoLock auto_lock(lock_);
140 DCHECK(clients_.empty()); 148 DCHECK(clients_.empty());
141 DCHECK(!initialized_); 149 DCHECK(!initialized_);
142 initialized_ = true; 150 initialized_ = true;
143 result_ = result; 151 result_ = result;
144 152
145 for (MidiManagerClient* client : pending_clients_) { 153 for (auto client : pending_clients_) {
146 if (result_ == MIDI_OK) 154 if (result_ == MIDI_OK) {
155 AddInitialPorts(client);
147 clients_.insert(client); 156 clients_.insert(client);
157 }
148 client->CompleteStartSession(result_); 158 client->CompleteStartSession(result_);
149 } 159 }
150 pending_clients_.clear(); 160 pending_clients_.clear();
151 } 161 }
152 162
163 void MidiManager::AddInitialPorts(MidiManagerClient* client) {
164 lock_.AssertAcquired();
165
166 for (const auto& info : input_ports_)
167 client->AddInputPort(info);
168 for (const auto& info : output_ports_)
169 client->AddOutputPort(info);
170 }
171
153 } // namespace media 172 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698