| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_android.h" | 5 #include "media/midi/midi_manager_android.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/android/context_utils.h" | 8 #include "base/android/context_utils.h" |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 void MidiManagerAndroid::OnAttached(JNIEnv* env, | 149 void MidiManagerAndroid::OnAttached(JNIEnv* env, |
| 150 const JavaParamRef<jobject>& caller, | 150 const JavaParamRef<jobject>& caller, |
| 151 const JavaParamRef<jobject>& raw_device) { | 151 const JavaParamRef<jobject>& raw_device) { |
| 152 AddDevice(base::MakeUnique<MidiDeviceAndroid>(env, raw_device, this)); | 152 AddDevice(base::MakeUnique<MidiDeviceAndroid>(env, raw_device, this)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void MidiManagerAndroid::OnDetached(JNIEnv* env, | 155 void MidiManagerAndroid::OnDetached(JNIEnv* env, |
| 156 const JavaParamRef<jobject>& caller, | 156 const JavaParamRef<jobject>& caller, |
| 157 const JavaParamRef<jobject>& raw_device) { | 157 const JavaParamRef<jobject>& raw_device) { |
| 158 for (auto& device : devices_) { | 158 for (auto* device : devices_) { |
| 159 if (device->HasRawDevice(env, raw_device)) { | 159 if (device->HasRawDevice(env, raw_device)) { |
| 160 for (auto& port : device->input_ports()) { | 160 for (auto* port : device->input_ports()) { |
| 161 DCHECK(input_port_to_index_.end() != | 161 DCHECK(input_port_to_index_.end() != input_port_to_index_.find(port)); |
| 162 input_port_to_index_.find(port.get())); | 162 size_t index = input_port_to_index_[port]; |
| 163 size_t index = input_port_to_index_[port.get()]; | |
| 164 SetInputPortState(index, PortState::DISCONNECTED); | 163 SetInputPortState(index, PortState::DISCONNECTED); |
| 165 } | 164 } |
| 166 for (auto& port : device->output_ports()) { | 165 for (auto* port : device->output_ports()) { |
| 167 DCHECK(output_port_to_index_.end() != | 166 DCHECK(output_port_to_index_.end() != output_port_to_index_.find(port)); |
| 168 output_port_to_index_.find(port.get())); | 167 size_t index = output_port_to_index_[port]; |
| 169 size_t index = output_port_to_index_[port.get()]; | |
| 170 SetOutputPortState(index, PortState::DISCONNECTED); | 168 SetOutputPortState(index, PortState::DISCONNECTED); |
| 171 } | 169 } |
| 172 } | 170 } |
| 173 } | 171 } |
| 174 } | 172 } |
| 175 | 173 |
| 176 void MidiManagerAndroid::AddDevice(std::unique_ptr<MidiDeviceAndroid> device) { | 174 void MidiManagerAndroid::AddDevice(std::unique_ptr<MidiDeviceAndroid> device) { |
| 177 for (auto& port : device->input_ports()) { | 175 for (auto* port : device->input_ports()) { |
| 178 // We implicitly open input ports here, because there are no signal | 176 // We implicitly open input ports here, because there are no signal |
| 179 // from the renderer when to open. | 177 // from the renderer when to open. |
| 180 // TODO(yhirano): Implement open operation in Blink. | 178 // TODO(yhirano): Implement open operation in Blink. |
| 181 PortState state = port->Open() ? PortState::OPENED : PortState::CONNECTED; | 179 PortState state = port->Open() ? PortState::OPENED : PortState::CONNECTED; |
| 182 | 180 |
| 183 const size_t index = all_input_ports_.size(); | 181 const size_t index = all_input_ports_.size(); |
| 184 all_input_ports_.push_back(port.get()); | 182 all_input_ports_.push_back(port); |
| 185 // Port ID must be unique in a MIDI manager. This ID setting is | 183 // Port ID must be unique in a MIDI manager. This ID setting is |
| 186 // sufficiently unique although there is no user-friendly meaning. | 184 // sufficiently unique although there is no user-friendly meaning. |
| 187 // TODO(yhirano): Use a hashed string as ID. | 185 // TODO(yhirano): Use a hashed string as ID. |
| 188 const std::string id( | 186 const std::string id( |
| 189 base::StringPrintf("native:port-in-%ld", static_cast<long>(index))); | 187 base::StringPrintf("native:port-in-%ld", static_cast<long>(index))); |
| 190 | 188 |
| 191 input_port_to_index_.insert(std::make_pair(port.get(), index)); | 189 input_port_to_index_.insert(std::make_pair(port, index)); |
| 192 AddInputPort(MidiPortInfo(id, device->GetManufacturer(), | 190 AddInputPort(MidiPortInfo(id, device->GetManufacturer(), |
| 193 device->GetProductName(), | 191 device->GetProductName(), |
| 194 device->GetDeviceVersion(), state)); | 192 device->GetDeviceVersion(), state)); |
| 195 } | 193 } |
| 196 for (auto& port : device->output_ports()) { | 194 for (auto* port : device->output_ports()) { |
| 197 const size_t index = all_output_ports_.size(); | 195 const size_t index = all_output_ports_.size(); |
| 198 all_output_ports_.push_back(port.get()); | 196 all_output_ports_.push_back(port); |
| 199 | 197 |
| 200 // Port ID must be unique in a MIDI manager. This ID setting is | 198 // Port ID must be unique in a MIDI manager. This ID setting is |
| 201 // sufficiently unique although there is no user-friendly meaning. | 199 // sufficiently unique although there is no user-friendly meaning. |
| 202 // TODO(yhirano): Use a hashed string as ID. | 200 // TODO(yhirano): Use a hashed string as ID. |
| 203 const std::string id( | 201 const std::string id( |
| 204 base::StringPrintf("native:port-out-%ld", static_cast<long>(index))); | 202 base::StringPrintf("native:port-out-%ld", static_cast<long>(index))); |
| 205 | 203 |
| 206 output_port_to_index_.insert(std::make_pair(port.get(), index)); | 204 output_port_to_index_.insert(std::make_pair(port, index)); |
| 207 AddOutputPort( | 205 AddOutputPort( |
| 208 MidiPortInfo(id, device->GetManufacturer(), device->GetProductName(), | 206 MidiPortInfo(id, device->GetManufacturer(), device->GetProductName(), |
| 209 device->GetDeviceVersion(), PortState::CONNECTED)); | 207 device->GetDeviceVersion(), PortState::CONNECTED)); |
| 210 } | 208 } |
| 211 devices_.push_back(std::move(device)); | 209 devices_.push_back(device.release()); |
| 212 } | 210 } |
| 213 | 211 |
| 214 bool MidiManagerAndroid::Register(JNIEnv* env) { | 212 bool MidiManagerAndroid::Register(JNIEnv* env) { |
| 215 return RegisterNativesImpl(env); | 213 return RegisterNativesImpl(env); |
| 216 } | 214 } |
| 217 | 215 |
| 218 } // namespace midi | 216 } // namespace midi |
| OLD | NEW |