crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "media/midi/midi_manager.h" |
| 6 | |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 7 | #include "base/bind.h" |
fdoray | a05bf57 | 2016-06-09 08:42:38 -0700 | [diff] [blame] | 8 | #include "base/location.h" |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 9 | #include "base/metrics/histogram_macros.h" |
fdoray | a05bf57 | 2016-06-09 08:42:38 -0700 | [diff] [blame] | 10 | #include "base/single_thread_task_runner.h" |
| 11 | #include "base/threading/thread_task_runner_handle.h" |
ssid | 9134444 | 2015-01-28 04:13:15 -0800 | [diff] [blame] | 12 | #include "base/trace_event/trace_event.h" |
avi | 793390d | 2015-12-22 22:22:36 -0800 | [diff] [blame] | 13 | #include "build/build_config.h" |
crogers@google.com | 542a43a | 2013-07-31 05:16:49 +0000 | [diff] [blame] | 14 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 15 | namespace midi { |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 16 | |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 17 | namespace { |
| 18 | |
| 19 | using Sample = base::HistogramBase::Sample; |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 20 | using midi::mojom::PortState; |
toyoshim | 2f3a48f | 2016-10-17 01:54:13 -0700 | [diff] [blame] | 21 | using midi::mojom::Result; |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 22 | |
| 23 | // If many users have more devices, this number will be increased. |
| 24 | // But the number is expected to be big enough for now. |
toyoshim | e4aa38e | 2017-04-09 22:59:52 -0700 | [diff] [blame] | 25 | constexpr Sample kMaxUmaDevices = 31; |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 26 | |
Takashi Toyoshima | 6fb495c | 2017-06-27 15:25:17 +0900 | [diff] [blame] | 27 | // Used to count events for usage histogram. The item order should not be |
| 28 | // changed, and new items should be just appended. |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 29 | enum class Usage { |
| 30 | CREATED, |
| 31 | CREATED_ON_UNSUPPORTED_PLATFORMS, |
| 32 | SESSION_STARTED, |
| 33 | SESSION_ENDED, |
| 34 | INITIALIZED, |
| 35 | INPUT_PORT_ADDED, |
| 36 | OUTPUT_PORT_ADDED, |
| 37 | |
| 38 | // New items should be inserted here, and |MAX| should point the last item. |
toyoshim | e4aa38e | 2017-04-09 22:59:52 -0700 | [diff] [blame] | 39 | MAX = OUTPUT_PORT_ADDED, |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Takashi Toyoshima | 6fb495c | 2017-06-27 15:25:17 +0900 | [diff] [blame] | 42 | // Used to count events for transaction usage histogram. The item order should |
| 43 | // not be changed, and new items should be just appended. |
| 44 | enum class SendReceiveUsage { |
| 45 | NO_USE, |
| 46 | SENT, |
| 47 | RECEIVED, |
| 48 | SENT_AND_RECEIVED, |
| 49 | |
| 50 | // New items should be inserted here, and |MAX| should point the last item. |
| 51 | MAX = SENT_AND_RECEIVED, |
| 52 | }; |
| 53 | |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 54 | void ReportUsage(Usage usage) { |
Takashi Toyoshima | 6fb495c | 2017-06-27 15:25:17 +0900 | [diff] [blame] | 55 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage", usage, |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 56 | static_cast<Sample>(Usage::MAX) + 1); |
| 57 | } |
| 58 | |
| 59 | } // namespace |
| 60 | |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 61 | MidiManager::MidiManager(MidiService* service) : service_(service) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 62 | ReportUsage(Usage::CREATED); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 63 | } |
| 64 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 65 | MidiManager::~MidiManager() { |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 66 | base::AutoLock auto_lock(lock_); |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 67 | if (session_thread_runner_) { |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 68 | DCHECK(session_thread_runner_->BelongsToCurrentThread()); |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 69 | session_thread_runner_ = nullptr; |
| 70 | } |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 71 | |
Takashi Toyoshima | 6fb495c | 2017-06-27 15:25:17 +0900 | [diff] [blame] | 72 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", result_, |
| 73 | static_cast<Sample>(Result::MAX) + 1); |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 74 | |
| 75 | UMA_HISTOGRAM_ENUMERATION( |
| 76 | "Media.Midi.SendReceiveUsage", |
| 77 | data_sent_ ? (data_received_ ? SendReceiveUsage::SENT_AND_RECEIVED |
| 78 | : SendReceiveUsage::SENT) |
| 79 | : (data_received_ ? SendReceiveUsage::RECEIVED |
| 80 | : SendReceiveUsage::NO_USE), |
| 81 | static_cast<Sample>(SendReceiveUsage::MAX) + 1); |
| 82 | |
| 83 | // Detach all clients so that they do not call MidiManager methods any more. |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 84 | for (auto* client : pending_clients_) |
| 85 | client->Detach(); |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 86 | for (auto* client : clients_) |
| 87 | client->Detach(); |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Takashi Toyoshima | e8240ab | 2018-10-03 09:30:11 +0000 | [diff] [blame] | 90 | #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ |
| 91 | !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) |
| 92 | MidiManager* MidiManager::Create(MidiService* service) { |
| 93 | ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS); |
| 94 | return new MidiManager(service); |
| 95 | } |
| 96 | #endif |
| 97 | |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 98 | void MidiManager::StartSession(MidiManagerClient* client) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 99 | ReportUsage(Usage::SESSION_STARTED); |
| 100 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 101 | bool needs_initialization = false; |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 102 | |
| 103 | { |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 104 | base::AutoLock auto_lock(lock_); |
Takashi Toyoshima | 408b79f | 2018-01-09 20:30:07 +0900 | [diff] [blame] | 105 | |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 106 | if (clients_.find(client) != clients_.end() || |
| 107 | pending_clients_.find(client) != pending_clients_.end()) { |
| 108 | // Should not happen. But just in case the renderer is compromised. |
| 109 | NOTREACHED(); |
| 110 | return; |
| 111 | } |
toyoshim@chromium.org | fc2002e | 2014-05-07 08:10:34 +0000 | [diff] [blame] | 112 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 113 | if (initialization_state_ == InitializationState::COMPLETED) { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 114 | // Platform dependent initialization was already finished for previously |
| 115 | // initialized clients. |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 116 | if (result_ == Result::OK) { |
| 117 | for (const auto& info : input_ports_) |
| 118 | client->AddInputPort(info); |
| 119 | for (const auto& info : output_ports_) |
| 120 | client->AddOutputPort(info); |
| 121 | } |
Takashi Toyoshima | ec05edf | 2017-11-28 11:21:20 +0000 | [diff] [blame] | 122 | |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 123 | // Complete synchronously with |result_|; |
Takashi Toyoshima | ec05edf | 2017-11-28 11:21:20 +0000 | [diff] [blame] | 124 | clients_.insert(client); |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 125 | client->CompleteStartSession(result_); |
ochang | ae3bae9 | 2016-01-12 19:42:10 -0800 | [diff] [blame] | 126 | return; |
| 127 | } |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 128 | |
| 129 | // Do not accept a new request if the pending client list contains too |
| 130 | // many clients. |
| 131 | if (pending_clients_.size() >= kMaxPendingClientCount) { |
| 132 | client->CompleteStartSession(Result::INITIALIZATION_ERROR); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | if (initialization_state_ == InitializationState::NOT_STARTED) { |
| 137 | // Set fields protected by |lock_| here and call StartInitialization() |
| 138 | // later. |
| 139 | needs_initialization = true; |
| 140 | session_thread_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 141 | initialization_state_ = InitializationState::STARTED; |
| 142 | } |
| 143 | |
| 144 | pending_clients_.insert(client); |
toyoshim@chromium.org | f77a1e6 | 2014-04-11 13:16:24 +0000 | [diff] [blame] | 145 | } |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 146 | |
shaochuan | 8ba1cb6 | 2016-10-24 04:34:31 -0700 | [diff] [blame] | 147 | if (needs_initialization) { |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 148 | // Lazily initialize the MIDI back-end. |
| 149 | TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 150 | // CompleteInitialization() will be called asynchronously when platform |
| 151 | // dependent initialization is finished. |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 152 | StartInitialization(); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 153 | } |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Takashi Toyoshima | 150b443 | 2017-08-21 12:08:09 +0000 | [diff] [blame] | 156 | bool MidiManager::EndSession(MidiManagerClient* client) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 157 | ReportUsage(Usage::SESSION_ENDED); |
| 158 | |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 159 | // At this point, |client| can be in the destruction process, and calling |
ochang | ae3bae9 | 2016-01-12 19:42:10 -0800 | [diff] [blame] | 160 | // any method of |client| is dangerous. Calls on clients *must* be protected |
| 161 | // by |lock_| to prevent race conditions. |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 162 | base::AutoLock auto_lock(lock_); |
Takashi Toyoshima | 150b443 | 2017-08-21 12:08:09 +0000 | [diff] [blame] | 163 | if (clients_.find(client) == clients_.end() && |
| 164 | pending_clients_.find(client) == pending_clients_.end()) { |
| 165 | return false; |
| 166 | } |
| 167 | |
toyoshim@chromium.org | 1fa678a | 2014-06-13 09:40:33 +0000 | [diff] [blame] | 168 | clients_.erase(client); |
| 169 | pending_clients_.erase(client); |
Takashi Toyoshima | 150b443 | 2017-08-21 12:08:09 +0000 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | |
| 173 | bool MidiManager::HasOpenSession() { |
| 174 | base::AutoLock auto_lock(lock_); |
| 175 | return clients_.size() != 0u; |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 176 | } |
| 177 | |
toyoshim@chromium.org | c82e66e | 2014-02-04 07:05:47 +0000 | [diff] [blame] | 178 | void MidiManager::DispatchSendMidiData(MidiManagerClient* client, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 179 | uint32_t port_index, |
| 180 | const std::vector<uint8_t>& data, |
tzik | 925e2c6 | 2018-02-02 07:39:45 +0000 | [diff] [blame] | 181 | base::TimeTicks timestamp) { |
yhirano@chromium.org | c6d5b7b | 2013-12-20 07:27:23 +0000 | [diff] [blame] | 182 | NOTREACHED(); |
| 183 | } |
| 184 | |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 185 | void MidiManager::StartInitialization() { |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 186 | CompleteInitialization(Result::NOT_SUPPORTED); |
toyoshim@chromium.org | 51c7f53 | 2014-05-01 17:17:32 +0000 | [diff] [blame] | 187 | } |
| 188 | |
toyoshim | f1b8896 | 2015-07-09 14:14:51 -0700 | [diff] [blame] | 189 | void MidiManager::CompleteInitialization(Result result) { |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 190 | DCHECK_EQ(InitializationState::STARTED, initialization_state_); |
| 191 | |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 192 | TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| 193 | ReportUsage(Usage::INITIALIZED); |
| 194 | |
| 195 | base::AutoLock auto_lock(lock_); |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 196 | if (!session_thread_runner_) |
| 197 | return; |
| 198 | DCHECK(session_thread_runner_->BelongsToCurrentThread()); |
| 199 | |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 200 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.InputPorts", input_ports_.size(), |
| 201 | kMaxUmaDevices + 1); |
| 202 | UMA_HISTOGRAM_ENUMERATION("Media.Midi.OutputPorts", output_ports_.size(), |
| 203 | kMaxUmaDevices + 1); |
| 204 | |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 205 | DCHECK(clients_.empty()); |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 206 | initialization_state_ = InitializationState::COMPLETED; |
| 207 | result_ = result; |
| 208 | |
| 209 | for (auto* client : pending_clients_) { |
| 210 | if (result_ == Result::OK) { |
| 211 | for (const auto& info : input_ports_) |
| 212 | client->AddInputPort(info); |
| 213 | for (const auto& info : output_ports_) |
| 214 | client->AddOutputPort(info); |
toyoshim | d28b59c | 2017-02-20 11:07:37 -0800 | [diff] [blame] | 215 | } |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 216 | |
| 217 | clients_.insert(client); |
| 218 | client->CompleteStartSession(result_); |
toyoshim | 7a80966 | 2015-10-06 00:54:21 -0700 | [diff] [blame] | 219 | } |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 220 | pending_clients_.clear(); |
yhirano@chromium.org | c6d5b7b | 2013-12-20 07:27:23 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Adithya Srinivasan | 3325273 | 2018-10-17 15:59:40 +0000 | [diff] [blame] | 223 | void MidiManager::AddInputPort(const mojom::PortInfo& info) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 224 | ReportUsage(Usage::INPUT_PORT_ADDED); |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 225 | base::AutoLock auto_lock(lock_); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 226 | input_ports_.push_back(info); |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 227 | for (auto* client : clients_) |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 228 | client->AddInputPort(info); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Adithya Srinivasan | 3325273 | 2018-10-17 15:59:40 +0000 | [diff] [blame] | 231 | void MidiManager::AddOutputPort(const mojom::PortInfo& info) { |
toyoshim | 715385c | 2015-08-09 23:00:26 -0700 | [diff] [blame] | 232 | ReportUsage(Usage::OUTPUT_PORT_ADDED); |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 233 | base::AutoLock auto_lock(lock_); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 234 | output_ports_.push_back(info); |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 235 | for (auto* client : clients_) |
toyoshim | a62d674 | 2014-10-23 09:05:03 -0700 | [diff] [blame] | 236 | client->AddOutputPort(info); |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 237 | } |
| 238 | |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 239 | void MidiManager::SetInputPortState(uint32_t port_index, PortState state) { |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 240 | base::AutoLock auto_lock(lock_); |
| 241 | DCHECK_LT(port_index, input_ports_.size()); |
| 242 | input_ports_[port_index].state = state; |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 243 | for (auto* client : clients_) |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 244 | client->SetInputPortState(port_index, state); |
| 245 | } |
| 246 | |
toyoshim | ec2570a | 2016-10-21 02:15:27 -0700 | [diff] [blame] | 247 | void MidiManager::SetOutputPortState(uint32_t port_index, PortState state) { |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 248 | base::AutoLock auto_lock(lock_); |
| 249 | DCHECK_LT(port_index, output_ports_.size()); |
| 250 | output_ports_[port_index].state = state; |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 251 | for (auto* client : clients_) |
toyoshim | 5c6fe4b | 2015-02-18 23:28:09 -0800 | [diff] [blame] | 252 | client->SetOutputPortState(port_index, state); |
| 253 | } |
| 254 | |
Takashi Toyoshima | 5a6e6a3 | 2018-09-27 11:20:52 +0000 | [diff] [blame] | 255 | mojom::PortState MidiManager::GetOutputPortState(uint32_t port_index) { |
| 256 | base::AutoLock auto_lock(lock_); |
| 257 | DCHECK_LT(port_index, output_ports_.size()); |
| 258 | return output_ports_[port_index].state; |
| 259 | } |
| 260 | |
| 261 | void MidiManager::AccumulateMidiBytesSent(MidiManagerClient* client, size_t n) { |
| 262 | base::AutoLock auto_lock(lock_); |
| 263 | data_sent_ = true; |
| 264 | if (clients_.find(client) == clients_.end()) |
| 265 | return; |
| 266 | |
| 267 | // Continue to hold lock_ here in case another thread is currently doing |
| 268 | // EndSession. |
| 269 | client->AccumulateMidiBytesSent(n); |
| 270 | } |
| 271 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 272 | void MidiManager::ReceiveMidiData(uint32_t port_index, |
| 273 | const uint8_t* data, |
| 274 | size_t length, |
tzik | 925e2c6 | 2018-02-02 07:39:45 +0000 | [diff] [blame] | 275 | base::TimeTicks timestamp) { |
toyoshim@chromium.org | c1e05fb | 2014-05-06 16:39:20 +0000 | [diff] [blame] | 276 | base::AutoLock auto_lock(lock_); |
Takashi Toyoshima | 6fb495c | 2017-06-27 15:25:17 +0900 | [diff] [blame] | 277 | data_received_ = true; |
crogers@google.com | 27356e4 | 2013-06-22 04:03:03 +0000 | [diff] [blame] | 278 | |
vmpstr | 0205abb | 2016-06-28 18:50:56 -0700 | [diff] [blame] | 279 | for (auto* client : clients_) |
toyoshim | a485ff9 | 2014-10-23 00:17:59 -0700 | [diff] [blame] | 280 | client->ReceiveMidiData(port_index, data, length, timestamp); |
crogers@google.com | 542a43a | 2013-07-31 05:16:49 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Takashi Toyoshima | d4f37cd | 2018-10-01 07:43:39 +0000 | [diff] [blame] | 283 | size_t MidiManager::GetClientCountForTesting() { |
| 284 | base::AutoLock auto_lock(lock_); |
| 285 | return clients_.size(); |
| 286 | } |
| 287 | |
| 288 | size_t MidiManager::GetPendingClientCountForTesting() { |
| 289 | return pending_clients_.size(); |
| 290 | } |
| 291 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 292 | } // namespace midi |