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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 25 matching lines...) Expand all
36 36
37 void ReportUsage(Usage usage) { 37 void ReportUsage(Usage usage) {
38 UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage", 38 UMA_HISTOGRAM_ENUMERATION("Media.Midi.Usage",
39 static_cast<Sample>(usage), 39 static_cast<Sample>(usage),
40 static_cast<Sample>(Usage::MAX) + 1); 40 static_cast<Sample>(Usage::MAX) + 1);
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 MidiManager::MidiManager() 45 MidiManager::MidiManager()
46 : initialized_(false), result_(Result::NOT_INITIALIZED) { 46 : initialized_(false), finalized_(false), result_(Result::NOT_INITIALIZED) {
47 ReportUsage(Usage::CREATED); 47 ReportUsage(Usage::CREATED);
48 } 48 }
49 49
50 MidiManager::~MidiManager() { 50 MidiManager::~MidiManager() {
51 UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown", 51 // Make sure that Finalize() is called to clean up resources allocated on
52 static_cast<Sample>(result_), 52 // the Chrome_IOThread.
53 static_cast<Sample>(Result::MAX) + 1); 53 DCHECK(finalized_);
54 } 54 }
55 55
56 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ 56 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \
57 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) 57 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID)
58 MidiManager* MidiManager::Create() { 58 MidiManager* MidiManager::Create() {
59 ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS); 59 ReportUsage(Usage::CREATED_ON_UNSUPPORTED_PLATFORMS);
60 return new MidiManager; 60 return new MidiManager;
61 } 61 }
62 #endif 62 #endif
63 63
64 void MidiManager::Shutdown() {
65 UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown",
66 static_cast<int>(result_),
67 static_cast<int>(Result::MAX) + 1);
68 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
69 session_thread_runner_->PostTask(
70 FROM_HERE, base::Bind(&MidiManager::ShutdownOnSessionThread,
71 base::Unretained(this)));
72 } else {
73 base::AutoLock auto_lock(lock_);
74 finalized_ = true;
75 }
76 }
77
64 void MidiManager::StartSession(MidiManagerClient* client) { 78 void MidiManager::StartSession(MidiManagerClient* client) {
65 ReportUsage(Usage::SESSION_STARTED); 79 ReportUsage(Usage::SESSION_STARTED);
66 80
67 bool session_is_ready; 81 bool session_is_ready;
68 bool session_needs_initialization = false; 82 bool session_needs_initialization = false;
69 bool too_many_pending_clients_exist = false; 83 bool too_many_pending_clients_exist = false;
70 84
71 { 85 {
72 base::AutoLock auto_lock(lock_); 86 base::AutoLock auto_lock(lock_);
73 session_is_ready = initialized_; 87 session_is_ready = initialized_;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 249
236 void MidiManager::AddInitialPorts(MidiManagerClient* client) { 250 void MidiManager::AddInitialPorts(MidiManagerClient* client) {
237 lock_.AssertAcquired(); 251 lock_.AssertAcquired();
238 252
239 for (const auto& info : input_ports_) 253 for (const auto& info : input_ports_)
240 client->AddInputPort(info); 254 client->AddInputPort(info);
241 for (const auto& info : output_ports_) 255 for (const auto& info : output_ports_)
242 client->AddOutputPort(info); 256 client->AddOutputPort(info);
243 } 257 }
244 258
259 void MidiManager::ShutdownOnSessionThread() {
260 Finalize();
261 base::AutoLock auto_lock(lock_);
262 finalized_ = true;
263 }
264
245 } // namespace midi 265 } // namespace midi
246 } // namespace media 266 } // namespace media
OLDNEW
« 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