| 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 28 matching lines...) Expand all Loading... |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 void ReportUsage(Usage usage) { | 41 void ReportUsage(Usage usage) { |
| 42 UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage", | 42 UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage", |
| 43 static_cast<Sample>(usage), | 43 static_cast<Sample>(usage), |
| 44 static_cast<Sample>(Usage::MAX) + 1); | 44 static_cast<Sample>(Usage::MAX) + 1); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 MidiManager::MidiManager() | 49 MidiManager::MidiManager(MidiService* service) |
| 50 : initialization_state_(InitializationState::NOT_STARTED), | 50 : initialization_state_(InitializationState::NOT_STARTED), |
| 51 finalized_(false), | 51 finalized_(false), |
| 52 result_(Result::NOT_INITIALIZED) { | 52 result_(Result::NOT_INITIALIZED), |
| 53 service_(service) { |
| 53 ReportUsage(Usage::CREATED); | 54 ReportUsage(Usage::CREATED); |
| 54 } | 55 } |
| 55 | 56 |
| 56 MidiManager::~MidiManager() { | 57 MidiManager::~MidiManager() { |
| 57 // Make sure that Finalize() is called to clean up resources allocated on | 58 // Make sure that Finalize() is called to clean up resources allocated on |
| 58 // the Chrome_IOThread. | 59 // the Chrome_IOThread. |
| 59 base::AutoLock auto_lock(lock_); | 60 base::AutoLock auto_lock(lock_); |
| 60 CHECK(finalized_); | 61 CHECK(finalized_); |
| 61 } | 62 } |
| 62 | 63 |
| 63 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ | 64 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ |
| 64 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) | 65 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) |
| 65 MidiManager* MidiManager::Create() { | 66 MidiManager* MidiManager::Create(MidiService* service) { |
| 66 ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS); | 67 ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS); |
| 67 return new MidiManager; | 68 return new MidiManager(service); |
| 68 } | 69 } |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 void MidiManager::Shutdown() { | 72 void MidiManager::Shutdown() { |
| 72 UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", | 73 UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", |
| 73 static_cast<int>(result_), | 74 static_cast<int>(result_), |
| 74 static_cast<int>(Result::MAX) + 1); | 75 static_cast<int>(Result::MAX) + 1); |
| 75 base::AutoLock auto_lock(lock_); | 76 bool shutdown_synchronously = false; |
| 76 if (session_thread_runner_) { | 77 { |
| 77 session_thread_runner_->PostTask( | 78 base::AutoLock auto_lock(lock_); |
| 78 FROM_HERE, base::Bind(&MidiManager::ShutdownOnSessionThread, | 79 if (session_thread_runner_) { |
| 79 base::Unretained(this))); | 80 if (session_thread_runner_->BelongsToCurrentThread()) { |
| 80 session_thread_runner_ = nullptr; | 81 shutdown_synchronously = true; |
| 81 } else { | 82 } else { |
| 82 finalized_ = true; | 83 session_thread_runner_->PostTask( |
| 84 FROM_HERE, base::Bind(&MidiManager::ShutdownOnSessionThread, |
| 85 base::Unretained(this))); |
| 86 } |
| 87 session_thread_runner_ = nullptr; |
| 88 } else { |
| 89 finalized_ = true; |
| 90 } |
| 83 } | 91 } |
| 92 if (shutdown_synchronously) |
| 93 ShutdownOnSessionThread(); |
| 84 } | 94 } |
| 85 | 95 |
| 86 void MidiManager::StartSession(MidiManagerClient* client) { | 96 void MidiManager::StartSession(MidiManagerClient* client) { |
| 87 ReportUsage(Usage::SESSION_STARTED); | 97 ReportUsage(Usage::SESSION_STARTED); |
| 88 | 98 |
| 89 bool needs_initialization = false; | 99 bool needs_initialization = false; |
| 90 | 100 |
| 91 { | 101 { |
| 92 base::AutoLock auto_lock(lock_); | 102 base::AutoLock auto_lock(lock_); |
| 93 if (clients_.find(client) != clients_.end() || | 103 if (clients_.find(client) != clients_.end() || |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 Finalize(); | 274 Finalize(); |
| 265 base::AutoLock auto_lock(lock_); | 275 base::AutoLock auto_lock(lock_); |
| 266 finalized_ = true; | 276 finalized_ = true; |
| 267 | 277 |
| 268 // Detach all clients so that they do not call MidiManager methods any more. | 278 // Detach all clients so that they do not call MidiManager methods any more. |
| 269 for (auto* client : clients_) | 279 for (auto* client : clients_) |
| 270 client->Detach(); | 280 client->Detach(); |
| 271 } | 281 } |
| 272 | 282 |
| 273 } // namespace midi | 283 } // namespace midi |
| OLD | NEW |