Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Unified Diff: media/midi/midi_manager.cc

Issue 1315793008: Web MIDI: introduce MidiManager::Shutdown to shutdown gracefully (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make sure to run Finalize() Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_mac_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_manager.cc
diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc
index 6e8c1a266fa86502407d929db218eb1e85afc1f5..abd91bea7cc9ebc70e62622f8edc6e86524baee4 100644
--- a/media/midi/midi_manager.cc
+++ b/media/midi/midi_manager.cc
@@ -43,14 +43,14 @@ void ReportUsage(Usage usage) {
} // namespace
MidiManager::MidiManager()
- : initialized_(false), result_(Result::NOT_INITIALIZED) {
+ : initialized_(false), finalized_(false), result_(Result::NOT_INITIALIZED) {
ReportUsage(Usage::CREATED);
}
MidiManager::~MidiManager() {
- UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown",
- static_cast<Sample>(result_),
- static_cast<Sample>(Result::MAX) + 1);
+ // Make sure that Finalize() is called to clean up resources allocated on
+ // the Chrome_IOThread.
+ DCHECK(finalized_);
}
#if !defined(OS_MACOSX) && !defined(OS_WIN) && \
@@ -61,6 +61,20 @@ MidiManager* MidiManager::Create() {
}
#endif
+void MidiManager::Shutdown() {
+ UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown",
+ static_cast<int>(result_),
+ static_cast<int>(Result::MAX) + 1);
+ if (session_thread_runner_) {
yhirano 2015/09/10 07:37:29 We need to protect more code with lock in order to
Takashi Toyoshima 2015/09/10 08:19:15 You are right. I change code to protect session_th
+ session_thread_runner_->PostTask(
+ FROM_HERE, base::Bind(&MidiManager::ShutdownOnSessionThread,
+ base::Unretained(this)));
+ } else {
+ base::AutoLock auto_lock(lock_);
+ finalized_ = true;
+ }
+}
+
void MidiManager::StartSession(MidiManagerClient* client) {
ReportUsage(Usage::SESSION_STARTED);
@@ -242,5 +256,11 @@ void MidiManager::AddInitialPorts(MidiManagerClient* client) {
client->AddOutputPort(info);
}
+void MidiManager::ShutdownOnSessionThread() {
+ Finalize();
+ base::AutoLock auto_lock(lock_);
+ finalized_ = true;
+}
+
} // namespace midi
} // namespace media
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698