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

Side by Side Diff: media/midi/midi_manager.cc

Issue 1217853007: Web MIDI: add a new UMA entry for the final result code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #16 Created 5 years, 5 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_alsa.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/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
10 11
11 namespace media { 12 namespace media {
12 namespace midi { 13 namespace midi {
13 14
14 MidiManager::MidiManager() 15 MidiManager::MidiManager()
15 : initialized_(false), 16 : initialized_(false), result_(Result::NOT_INITIALIZED) {
16 result_(MIDI_NOT_SUPPORTED) {
17 } 17 }
18 18
19 MidiManager::~MidiManager() { 19 MidiManager::~MidiManager() {
20 UMA_HISTOGRAM_ENUMERATION("Media.Midi.ResultOnShutdown",
21 static_cast<int>(result_),
22 static_cast<int>(Result::MAX) + 1);
Takashi Toyoshima 2015/07/09 17:43:30 Hum... presubmit check has a special rule for UMA_
Alexei Svitkine (slow) 2015/07/09 18:05:27 Yeah, the media convention is to do it this way, w
20 } 23 }
21 24
22 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ 25 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \
23 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) 26 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID)
24 MidiManager* MidiManager::Create() { 27 MidiManager* MidiManager::Create() {
25 return new MidiManager; 28 return new MidiManager;
26 } 29 }
27 #endif 30 #endif
28 31
29 void MidiManager::StartSession(MidiManagerClient* client) { 32 void MidiManager::StartSession(MidiManagerClient* client) {
(...skipping 27 matching lines...) Expand all
57 // Lazily initialize the MIDI back-end. 60 // Lazily initialize the MIDI back-end.
58 if (!session_is_ready) { 61 if (!session_is_ready) {
59 if (session_needs_initialization) { 62 if (session_needs_initialization) {
60 TRACE_EVENT0("midi", "MidiManager::StartInitialization"); 63 TRACE_EVENT0("midi", "MidiManager::StartInitialization");
61 session_thread_runner_ = 64 session_thread_runner_ =
62 base::MessageLoop::current()->task_runner(); 65 base::MessageLoop::current()->task_runner();
63 StartInitialization(); 66 StartInitialization();
64 } 67 }
65 if (too_many_pending_clients_exist) { 68 if (too_many_pending_clients_exist) {
66 // Return an error immediately if there are too many requests. 69 // Return an error immediately if there are too many requests.
67 client->CompleteStartSession(MIDI_INITIALIZATION_ERROR); 70 client->CompleteStartSession(Result::INITIALIZATION_ERROR);
68 return; 71 return;
69 } 72 }
70 // CompleteInitialization() will be called asynchronously when platform 73 // CompleteInitialization() will be called asynchronously when platform
71 // dependent initialization is finished. 74 // dependent initialization is finished.
72 return; 75 return;
73 } 76 }
74 77
75 // Platform dependent initialization was already finished for previously 78 // Platform dependent initialization was already finished for previously
76 // initialized clients. 79 // initialized clients.
77 MidiResult result; 80 Result result;
78 { 81 {
79 base::AutoLock auto_lock(lock_); 82 base::AutoLock auto_lock(lock_);
80 if (result_ == MIDI_OK) { 83 if (result_ == Result::OK) {
81 AddInitialPorts(client); 84 AddInitialPorts(client);
82 clients_.insert(client); 85 clients_.insert(client);
83 } 86 }
84 result = result_; 87 result = result_;
85 } 88 }
86 client->CompleteStartSession(result); 89 client->CompleteStartSession(result);
87 } 90 }
88 91
89 void MidiManager::EndSession(MidiManagerClient* client) { 92 void MidiManager::EndSession(MidiManagerClient* client) {
90 // At this point, |client| can be in the destruction process, and calling 93 // At this point, |client| can be in the destruction process, and calling
(...skipping 13 matching lines...) Expand all
104 } 107 }
105 108
106 void MidiManager::DispatchSendMidiData(MidiManagerClient* client, 109 void MidiManager::DispatchSendMidiData(MidiManagerClient* client,
107 uint32 port_index, 110 uint32 port_index,
108 const std::vector<uint8>& data, 111 const std::vector<uint8>& data,
109 double timestamp) { 112 double timestamp) {
110 NOTREACHED(); 113 NOTREACHED();
111 } 114 }
112 115
113 void MidiManager::StartInitialization() { 116 void MidiManager::StartInitialization() {
114 CompleteInitialization(MIDI_NOT_SUPPORTED); 117 CompleteInitialization(Result::NOT_SUPPORTED);
115 } 118 }
116 119
117 void MidiManager::CompleteInitialization(MidiResult result) { 120 void MidiManager::CompleteInitialization(Result result) {
118 DCHECK(session_thread_runner_.get()); 121 DCHECK(session_thread_runner_.get());
119 // It is safe to post a task to the IO thread from here because the IO thread 122 // It is safe to post a task to the IO thread from here because the IO thread
120 // should have stopped if the MidiManager is going to be destructed. 123 // should have stopped if the MidiManager is going to be destructed.
121 session_thread_runner_->PostTask( 124 session_thread_runner_->PostTask(
122 FROM_HERE, 125 FROM_HERE,
123 base::Bind(&MidiManager::CompleteInitializationInternal, 126 base::Bind(&MidiManager::CompleteInitializationInternal,
124 base::Unretained(this), 127 base::Unretained(this),
125 result)); 128 result));
126 } 129 }
127 130
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 uint32 port_index, 162 uint32 port_index,
160 const uint8* data, 163 const uint8* data,
161 size_t length, 164 size_t length,
162 double timestamp) { 165 double timestamp) {
163 base::AutoLock auto_lock(lock_); 166 base::AutoLock auto_lock(lock_);
164 167
165 for (auto client : clients_) 168 for (auto client : clients_)
166 client->ReceiveMidiData(port_index, data, length, timestamp); 169 client->ReceiveMidiData(port_index, data, length, timestamp);
167 } 170 }
168 171
169 void MidiManager::CompleteInitializationInternal(MidiResult result) { 172 void MidiManager::CompleteInitializationInternal(Result result) {
170 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); 173 TRACE_EVENT0("midi", "MidiManager::CompleteInitialization");
171 174
172 base::AutoLock auto_lock(lock_); 175 base::AutoLock auto_lock(lock_);
173 DCHECK(clients_.empty()); 176 DCHECK(clients_.empty());
174 DCHECK(!initialized_); 177 DCHECK(!initialized_);
175 initialized_ = true; 178 initialized_ = true;
176 result_ = result; 179 result_ = result;
177 180
178 for (auto client : pending_clients_) { 181 for (auto client : pending_clients_) {
179 if (result_ == MIDI_OK) { 182 if (result_ == Result::OK) {
180 AddInitialPorts(client); 183 AddInitialPorts(client);
181 clients_.insert(client); 184 clients_.insert(client);
182 } 185 }
183 client->CompleteStartSession(result_); 186 client->CompleteStartSession(result_);
184 } 187 }
185 pending_clients_.clear(); 188 pending_clients_.clear();
186 } 189 }
187 190
188 void MidiManager::AddInitialPorts(MidiManagerClient* client) { 191 void MidiManager::AddInitialPorts(MidiManagerClient* client) {
189 lock_.AssertAcquired(); 192 lock_.AssertAcquired();
190 193
191 for (const auto& info : input_ports_) 194 for (const auto& info : input_ports_)
192 client->AddInputPort(info); 195 client->AddInputPort(info);
193 for (const auto& info : output_ports_) 196 for (const auto& info : output_ports_)
194 client->AddOutputPort(info); 197 client->AddOutputPort(info);
195 } 198 }
196 199
197 } // namespace midi 200 } // namespace midi
198 } // namespace media 201 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_alsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698