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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 const std::vector<uint8_t>& data, | 178 const std::vector<uint8_t>& data, |
179 double timestamp) { | 179 double timestamp) { |
180 NOTREACHED(); | 180 NOTREACHED(); |
181 } | 181 } |
182 | 182 |
183 void MidiManager::StartInitialization() { | 183 void MidiManager::StartInitialization() { |
184 CompleteInitialization(Result::NOT_SUPPORTED); | 184 CompleteInitialization(Result::NOT_SUPPORTED); |
185 } | 185 } |
186 | 186 |
187 void MidiManager::CompleteInitialization(Result result) { | 187 void MidiManager::CompleteInitialization(Result result) { |
188 base::AutoLock auto_lock(lock_); | 188 bool complete_asynchronously = false; |
189 if (session_thread_runner_) { | 189 { |
190 session_thread_runner_->PostTask( | 190 base::AutoLock auto_lock(lock_); |
191 FROM_HERE, base::Bind(&MidiManager::CompleteInitializationInternal, | 191 if (session_thread_runner_) { |
192 base::Unretained(this), result)); | 192 if (session_thread_runner_->BelongsToCurrentThread()) { |
| 193 complete_asynchronously = true; |
| 194 } else { |
| 195 session_thread_runner_->PostTask( |
| 196 FROM_HERE, base::Bind(&MidiManager::CompleteInitializationInternal, |
| 197 base::Unretained(this), result)); |
| 198 } |
| 199 } |
193 } | 200 } |
| 201 if (complete_asynchronously) |
| 202 CompleteInitializationInternal(result); |
194 } | 203 } |
195 | 204 |
196 void MidiManager::AddInputPort(const MidiPortInfo& info) { | 205 void MidiManager::AddInputPort(const MidiPortInfo& info) { |
197 ReportUsage(Usage::INPUT_PORT_ADDED); | 206 ReportUsage(Usage::INPUT_PORT_ADDED); |
198 base::AutoLock auto_lock(lock_); | 207 base::AutoLock auto_lock(lock_); |
199 input_ports_.push_back(info); | 208 input_ports_.push_back(info); |
200 for (auto* client : clients_) | 209 for (auto* client : clients_) |
201 client->AddInputPort(info); | 210 client->AddInputPort(info); |
202 } | 211 } |
203 | 212 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 Finalize(); | 283 Finalize(); |
275 base::AutoLock auto_lock(lock_); | 284 base::AutoLock auto_lock(lock_); |
276 finalized_ = true; | 285 finalized_ = true; |
277 | 286 |
278 // Detach all clients so that they do not call MidiManager methods any more. | 287 // Detach all clients so that they do not call MidiManager methods any more. |
279 for (auto* client : clients_) | 288 for (auto* client : clients_) |
280 client->Detach(); | 289 client->Detach(); |
281 } | 290 } |
282 | 291 |
283 } // namespace midi | 292 } // namespace midi |
OLD | NEW |