| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_service.h" | 5 #include "media/midi/midi_service.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "media/midi/midi_manager.h" | 10 #include "media/midi/midi_manager.h" |
| 11 #include "media/midi/midi_switches.h" | 11 #include "media/midi/midi_switches.h" |
| 12 #include "media/midi/task_service.h" |
| 12 | 13 |
| 13 namespace midi { | 14 namespace midi { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 bool IsDynamicInstantiationEnabled() { | 18 bool IsDynamicInstantiationEnabled() { |
| 18 // TODO(toyoshim): Support on all platforms. See https://crbug.com/672793. | 19 // TODO(toyoshim): Support on all platforms. See https://crbug.com/672793. |
| 19 #if defined(OS_LINUX) || defined(OS_WIN) | 20 #if defined(OS_LINUX) || defined(OS_WIN) |
| 20 return true; | 21 return true; |
| 21 #else | 22 #else |
| 22 return base::FeatureList::IsEnabled( | 23 return base::FeatureList::IsEnabled( |
| 23 features::kMidiManagerDynamicInstantiation); | 24 features::kMidiManagerDynamicInstantiation); |
| 24 #endif | 25 #endif |
| 25 } | 26 } |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 MidiService::MidiService(void) | 30 MidiService::MidiService(void) |
| 30 : is_dynamic_instantiation_enabled_(IsDynamicInstantiationEnabled()), | 31 : task_service_(base::MakeUnique<TaskService>()), |
| 32 is_dynamic_instantiation_enabled_(IsDynamicInstantiationEnabled()), |
| 31 active_clients_(0u) { | 33 active_clients_(0u) { |
| 32 base::AutoLock lock(lock_); | 34 base::AutoLock lock(lock_); |
| 33 | 35 |
| 34 if (!is_dynamic_instantiation_enabled_) | 36 if (!is_dynamic_instantiation_enabled_) |
| 35 manager_ = base::WrapUnique(MidiManager::Create(this)); | 37 manager_ = base::WrapUnique(MidiManager::Create(this)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 MidiService::MidiService(std::unique_ptr<MidiManager> manager) | 40 MidiService::MidiService(std::unique_ptr<MidiManager> manager) |
| 39 : is_dynamic_instantiation_enabled_(false), active_clients_(0u) { | 41 : task_service_(base::MakeUnique<TaskService>()), |
| 42 is_dynamic_instantiation_enabled_(false), |
| 43 active_clients_(0u) { |
| 40 base::AutoLock lock(lock_); | 44 base::AutoLock lock(lock_); |
| 41 | 45 |
| 42 manager_ = std::move(manager); | 46 manager_ = std::move(manager); |
| 43 } | 47 } |
| 44 | 48 |
| 45 MidiService::~MidiService() { | 49 MidiService::~MidiService() { |
| 46 base::AutoLock lock(lock_); | 50 base::AutoLock lock(lock_); |
| 47 | 51 |
| 48 manager_.reset(); | 52 manager_.reset(); |
| 49 | 53 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 base::StringPrintf("MidiServiceThread(%zu)", runner_id)); | 116 base::StringPrintf("MidiServiceThread(%zu)", runner_id)); |
| 113 #if defined(OS_WIN) | 117 #if defined(OS_WIN) |
| 114 threads_[runner_id]->init_com_with_mta(true); | 118 threads_[runner_id]->init_com_with_mta(true); |
| 115 #endif | 119 #endif |
| 116 threads_[runner_id]->Start(); | 120 threads_[runner_id]->Start(); |
| 117 } | 121 } |
| 118 return threads_[runner_id]->task_runner(); | 122 return threads_[runner_id]->task_runner(); |
| 119 } | 123 } |
| 120 | 124 |
| 121 } // namespace midi | 125 } // namespace midi |
| OLD | NEW |