| 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 "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/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool IsSystemRealTimeMessage(uint8_t data) { | 39 bool IsSystemRealTimeMessage(uint8_t data) { |
| 40 return 0xf8 <= data && data <= 0xff; | 40 return 0xf8 <= data && data <= 0xff; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 using midi::kSysExByte; | 45 using midi::kSysExByte; |
| 46 using midi::kEndOfSysExByte; | 46 using midi::kEndOfSysExByte; |
| 47 using midi::mojom::Result; |
| 47 | 48 |
| 48 MidiHost::MidiHost(int renderer_process_id, | 49 MidiHost::MidiHost(int renderer_process_id, |
| 49 midi::MidiManager* midi_manager) | 50 midi::MidiManager* midi_manager) |
| 50 : BrowserMessageFilter(MidiMsgStart), | 51 : BrowserMessageFilter(MidiMsgStart), |
| 51 renderer_process_id_(renderer_process_id), | 52 renderer_process_id_(renderer_process_id), |
| 52 has_sys_ex_permission_(false), | 53 has_sys_ex_permission_(false), |
| 53 is_session_requested_(false), | 54 is_session_requested_(false), |
| 54 midi_manager_(midi_manager), | 55 midi_manager_(midi_manager), |
| 55 sent_bytes_in_flight_(0), | 56 sent_bytes_in_flight_(0), |
| 56 bytes_sent_since_last_acknowledgement_(0), | 57 bytes_sent_since_last_acknowledgement_(0), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (midi_manager_) | 135 if (midi_manager_) |
| 135 midi_manager_->DispatchSendMidiData(this, port, data, timestamp); | 136 midi_manager_->DispatchSendMidiData(this, port, data, timestamp); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void MidiHost::OnEndSession() { | 139 void MidiHost::OnEndSession() { |
| 139 is_session_requested_ = false; | 140 is_session_requested_ = false; |
| 140 if (midi_manager_) | 141 if (midi_manager_) |
| 141 midi_manager_->EndSession(this); | 142 midi_manager_->EndSession(this); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void MidiHost::CompleteStartSession(midi::Result result) { | 145 void MidiHost::CompleteStartSession(Result result) { |
| 145 DCHECK(is_session_requested_); | 146 DCHECK(is_session_requested_); |
| 146 if (result == midi::Result::OK) { | 147 if (result == Result::OK) { |
| 147 // ChildSecurityPolicy is set just before OnStartSession by | 148 // ChildSecurityPolicy is set just before OnStartSession by |
| 148 // MidiDispatcherHost. So we can safely cache the policy. | 149 // MidiDispatcherHost. So we can safely cache the policy. |
| 149 has_sys_ex_permission_ = ChildProcessSecurityPolicyImpl::GetInstance()-> | 150 has_sys_ex_permission_ = ChildProcessSecurityPolicyImpl::GetInstance()-> |
| 150 CanSendMidiSysExMessage(renderer_process_id_); | 151 CanSendMidiSysExMessage(renderer_process_id_); |
| 151 } | 152 } |
| 152 Send(new MidiMsg_SessionStarted(result)); | 153 Send(new MidiMsg_SessionStarted(result)); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void MidiHost::AddInputPort(const midi::MidiPortInfo& info) { | 156 void MidiHost::AddInputPort(const midi::MidiPortInfo& info) { |
| 156 base::AutoLock auto_lock(messages_queues_lock_); | 157 base::AutoLock auto_lock(messages_queues_lock_); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 263 } |
| 263 waiting_data_length = midi::GetMidiMessageLength(current); | 264 waiting_data_length = midi::GetMidiMessageLength(current); |
| 264 if (waiting_data_length == 0) | 265 if (waiting_data_length == 0) |
| 265 return false; // Error: |current| should have been a valid status byte. | 266 return false; // Error: |current| should have been a valid status byte. |
| 266 --waiting_data_length; // Found status byte | 267 --waiting_data_length; // Found status byte |
| 267 } | 268 } |
| 268 return waiting_data_length == 0 && !in_sysex; | 269 return waiting_data_length == 0 && !in_sysex; |
| 269 } | 270 } |
| 270 | 271 |
| 271 } // namespace content | 272 } // namespace content |
| OLD | NEW |