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

Side by Side Diff: content/browser/media/midi_host.cc

Issue 1576323002: Prevent a race condition with MidiHost IPC sending. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style Created 4 years, 11 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 | « content/browser/media/midi_host.h ('k') | media/midi/midi_manager.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 "content/browser/media/midi_host.h" 5 #include "content/browser/media/midi_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 renderer_process_id_(renderer_process_id), 52 renderer_process_id_(renderer_process_id),
53 has_sys_ex_permission_(false), 53 has_sys_ex_permission_(false),
54 is_session_requested_(false), 54 is_session_requested_(false),
55 midi_manager_(midi_manager), 55 midi_manager_(midi_manager),
56 sent_bytes_in_flight_(0), 56 sent_bytes_in_flight_(0),
57 bytes_sent_since_last_acknowledgement_(0), 57 bytes_sent_since_last_acknowledgement_(0),
58 output_port_count_(0) { 58 output_port_count_(0) {
59 DCHECK(midi_manager_); 59 DCHECK(midi_manager_);
60 } 60 }
61 61
62 MidiHost::~MidiHost() { 62 MidiHost::~MidiHost() = default;
63 // Close an open session, or abort opening a session. 63
64 if (is_session_requested_ && midi_manager_) 64 void MidiHost::OnChannelClosing() {
65 // If we get here the MidiHost is going to be destroyed soon. Prevent any
66 // subsequent calls from MidiManager by closing our session.
67 // If Send() is called from a different thread (e.g. a separate thread owned
68 // by the MidiManager implementation), it will get posted to the IO thread.
69 // There is a race condition here if our refcount is 0 and we're about to or
70 // have already entered OnDestruct().
71 if (is_session_requested_ && midi_manager_) {
65 midi_manager_->EndSession(this); 72 midi_manager_->EndSession(this);
73 is_session_requested_ = false;
74 }
66 } 75 }
67 76
68 void MidiHost::OnDestruct() const { 77 void MidiHost::OnDestruct() const {
69 BrowserThread::DeleteOnIOThread::Destruct(this); 78 BrowserThread::DeleteOnIOThread::Destruct(this);
70 } 79 }
71 80
72 // IPC Messages handler 81 // IPC Messages handler
73 bool MidiHost::OnMessageReceived(const IPC::Message& message) { 82 bool MidiHost::OnMessageReceived(const IPC::Message& message) {
74 bool handled = true; 83 bool handled = true;
75 IPC_BEGIN_MESSAGE_MAP(MidiHost, message) 84 IPC_BEGIN_MESSAGE_MAP(MidiHost, message)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 258 }
250 waiting_data_length = media::midi::GetMidiMessageLength(current); 259 waiting_data_length = media::midi::GetMidiMessageLength(current);
251 if (waiting_data_length == 0) 260 if (waiting_data_length == 0)
252 return false; // Error: |current| should have been a valid status byte. 261 return false; // Error: |current| should have been a valid status byte.
253 --waiting_data_length; // Found status byte 262 --waiting_data_length; // Found status byte
254 } 263 }
255 return waiting_data_length == 0 && !in_sysex; 264 return waiting_data_length == 0 && !in_sysex;
256 } 265 }
257 266
258 } // namespace content 267 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/midi_host.h ('k') | media/midi/midi_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698