| OLD | NEW |
| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 session_thread_runner_->PostTask( | 182 session_thread_runner_->PostTask( |
| 183 FROM_HERE, base::Bind(&MidiManager::CompleteInitializationInternal, | 183 FROM_HERE, base::Bind(&MidiManager::CompleteInitializationInternal, |
| 184 base::Unretained(this), result)); | 184 base::Unretained(this), result)); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void MidiManager::AddInputPort(const MidiPortInfo& info) { | 188 void MidiManager::AddInputPort(const MidiPortInfo& info) { |
| 189 ReportUsage(Usage::INPUT_PORT_ADDED); | 189 ReportUsage(Usage::INPUT_PORT_ADDED); |
| 190 base::AutoLock auto_lock(lock_); | 190 base::AutoLock auto_lock(lock_); |
| 191 input_ports_.push_back(info); | 191 input_ports_.push_back(info); |
| 192 for (auto client : clients_) | 192 for (auto* client : clients_) |
| 193 client->AddInputPort(info); | 193 client->AddInputPort(info); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void MidiManager::AddOutputPort(const MidiPortInfo& info) { | 196 void MidiManager::AddOutputPort(const MidiPortInfo& info) { |
| 197 ReportUsage(Usage::OUTPUT_PORT_ADDED); | 197 ReportUsage(Usage::OUTPUT_PORT_ADDED); |
| 198 base::AutoLock auto_lock(lock_); | 198 base::AutoLock auto_lock(lock_); |
| 199 output_ports_.push_back(info); | 199 output_ports_.push_back(info); |
| 200 for (auto client : clients_) | 200 for (auto* client : clients_) |
| 201 client->AddOutputPort(info); | 201 client->AddOutputPort(info); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void MidiManager::SetInputPortState(uint32_t port_index, MidiPortState state) { | 204 void MidiManager::SetInputPortState(uint32_t port_index, MidiPortState state) { |
| 205 base::AutoLock auto_lock(lock_); | 205 base::AutoLock auto_lock(lock_); |
| 206 DCHECK_LT(port_index, input_ports_.size()); | 206 DCHECK_LT(port_index, input_ports_.size()); |
| 207 input_ports_[port_index].state = state; | 207 input_ports_[port_index].state = state; |
| 208 for (auto client : clients_) | 208 for (auto* client : clients_) |
| 209 client->SetInputPortState(port_index, state); | 209 client->SetInputPortState(port_index, state); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void MidiManager::SetOutputPortState(uint32_t port_index, MidiPortState state) { | 212 void MidiManager::SetOutputPortState(uint32_t port_index, MidiPortState state) { |
| 213 base::AutoLock auto_lock(lock_); | 213 base::AutoLock auto_lock(lock_); |
| 214 DCHECK_LT(port_index, output_ports_.size()); | 214 DCHECK_LT(port_index, output_ports_.size()); |
| 215 output_ports_[port_index].state = state; | 215 output_ports_[port_index].state = state; |
| 216 for (auto client : clients_) | 216 for (auto* client : clients_) |
| 217 client->SetOutputPortState(port_index, state); | 217 client->SetOutputPortState(port_index, state); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MidiManager::ReceiveMidiData(uint32_t port_index, | 220 void MidiManager::ReceiveMidiData(uint32_t port_index, |
| 221 const uint8_t* data, | 221 const uint8_t* data, |
| 222 size_t length, | 222 size_t length, |
| 223 double timestamp) { | 223 double timestamp) { |
| 224 base::AutoLock auto_lock(lock_); | 224 base::AutoLock auto_lock(lock_); |
| 225 | 225 |
| 226 for (auto client : clients_) | 226 for (auto* client : clients_) |
| 227 client->ReceiveMidiData(port_index, data, length, timestamp); | 227 client->ReceiveMidiData(port_index, data, length, timestamp); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void MidiManager::CompleteInitializationInternal(Result result) { | 230 void MidiManager::CompleteInitializationInternal(Result result) { |
| 231 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); | 231 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| 232 ReportUsage(Usage::INITIALIZED); | 232 ReportUsage(Usage::INITIALIZED); |
| 233 UMA_HISTOGRAM_ENUMERATION("Media.Midi.InputPorts", | 233 UMA_HISTOGRAM_ENUMERATION("Media.Midi.InputPorts", |
| 234 static_cast<Sample>(input_ports_.size()), | 234 static_cast<Sample>(input_ports_.size()), |
| 235 kMaxUmaDevices + 1); | 235 kMaxUmaDevices + 1); |
| 236 UMA_HISTOGRAM_ENUMERATION("Media.Midi.OutputPorts", | 236 UMA_HISTOGRAM_ENUMERATION("Media.Midi.OutputPorts", |
| 237 static_cast<Sample>(output_ports_.size()), | 237 static_cast<Sample>(output_ports_.size()), |
| 238 kMaxUmaDevices + 1); | 238 kMaxUmaDevices + 1); |
| 239 | 239 |
| 240 base::AutoLock auto_lock(lock_); | 240 base::AutoLock auto_lock(lock_); |
| 241 DCHECK(clients_.empty()); | 241 DCHECK(clients_.empty()); |
| 242 DCHECK(!initialized_); | 242 DCHECK(!initialized_); |
| 243 initialized_ = true; | 243 initialized_ = true; |
| 244 result_ = result; | 244 result_ = result; |
| 245 | 245 |
| 246 for (auto client : pending_clients_) { | 246 for (auto* client : pending_clients_) { |
| 247 if (result_ == Result::OK) { | 247 if (result_ == Result::OK) { |
| 248 AddInitialPorts(client); | 248 AddInitialPorts(client); |
| 249 clients_.insert(client); | 249 clients_.insert(client); |
| 250 } | 250 } |
| 251 client->CompleteStartSession(result_); | 251 client->CompleteStartSession(result_); |
| 252 } | 252 } |
| 253 pending_clients_.clear(); | 253 pending_clients_.clear(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void MidiManager::AddInitialPorts(MidiManagerClient* client) { | 256 void MidiManager::AddInitialPorts(MidiManagerClient* client) { |
| 257 lock_.AssertAcquired(); | 257 lock_.AssertAcquired(); |
| 258 | 258 |
| 259 for (const auto& info : input_ports_) | 259 for (const auto& info : input_ports_) |
| 260 client->AddInputPort(info); | 260 client->AddInputPort(info); |
| 261 for (const auto& info : output_ports_) | 261 for (const auto& info : output_ports_) |
| 262 client->AddOutputPort(info); | 262 client->AddOutputPort(info); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void MidiManager::ShutdownOnSessionThread() { | 265 void MidiManager::ShutdownOnSessionThread() { |
| 266 Finalize(); | 266 Finalize(); |
| 267 base::AutoLock auto_lock(lock_); | 267 base::AutoLock auto_lock(lock_); |
| 268 finalized_ = true; | 268 finalized_ = true; |
| 269 | 269 |
| 270 // Detach all clients so that they do not call MidiManager methods any more. | 270 // Detach all clients so that they do not call MidiManager methods any more. |
| 271 for (auto client : clients_) | 271 for (auto* client : clients_) |
| 272 client->Detach(); | 272 client->Detach(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace midi | 275 } // namespace midi |
| 276 } // namespace media | 276 } // namespace media |
| OLD | NEW |