Chromium Code Reviews| 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 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MANAGER_H_ |
| 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ | 6 #define MEDIA_MIDI_MIDI_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "media/midi/midi_export.h" | 18 #include "media/midi/midi_export.h" |
| 19 #include "media/midi/midi_port_info.h" | 19 #include "media/midi/midi_port_info.h" |
| 20 #include "media/midi/midi_service.mojom.h" | 20 #include "media/midi/midi_service.mojom.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 24 } // namespace base | 24 } // namespace base |
| 25 | 25 |
| 26 namespace midi { | 26 namespace midi { |
| 27 | 27 |
| 28 class MidiService; | |
| 29 | |
| 28 // A MidiManagerClient registers with the MidiManager to receive MIDI data. | 30 // A MidiManagerClient registers with the MidiManager to receive MIDI data. |
| 29 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() | 31 // See MidiManager::RequestAccess() and MidiManager::ReleaseAccess() |
| 30 // for details. | 32 // for details. |
| 31 // TODO(toyoshim): Consider to have a MidiServiceClient interface. | 33 // TODO(toyoshim): Consider to have a MidiServiceClient interface. |
| 32 class MIDI_EXPORT MidiManagerClient { | 34 class MIDI_EXPORT MidiManagerClient { |
| 33 public: | 35 public: |
| 34 virtual ~MidiManagerClient() {} | 36 virtual ~MidiManagerClient() {} |
| 35 | 37 |
| 36 // AddInputPort() and AddOutputPort() are called before CompleteStartSession() | 38 // AddInputPort() and AddOutputPort() are called before CompleteStartSession() |
| 37 // is called to notify existing MIDI ports, and also called after that to | 39 // is called to notify existing MIDI ports, and also called after that to |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 66 // This happens as a result of the client having previously called | 68 // This happens as a result of the client having previously called |
| 67 // MidiManager::DispatchSendMidiData(). | 69 // MidiManager::DispatchSendMidiData(). |
| 68 virtual void AccumulateMidiBytesSent(size_t n) = 0; | 70 virtual void AccumulateMidiBytesSent(size_t n) = 0; |
| 69 | 71 |
| 70 // Detach() is called when MidiManager is going to shutdown immediately. | 72 // Detach() is called when MidiManager is going to shutdown immediately. |
| 71 // Client should not touch MidiManager instance after Detach() is called. | 73 // Client should not touch MidiManager instance after Detach() is called. |
| 72 virtual void Detach() = 0; | 74 virtual void Detach() = 0; |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 // Manages access to all MIDI hardware. | 77 // Manages access to all MIDI hardware. |
| 78 // *** Note ***: If dynamic instantiation feature is enabled, all MidiManager | |
| 79 // methods will be called on Chrome_IOThread. See comments on Shutdown() too. | |
| 76 class MIDI_EXPORT MidiManager { | 80 class MIDI_EXPORT MidiManager { |
| 77 public: | 81 public: |
| 78 static const size_t kMaxPendingClientCount = 128; | 82 static const size_t kMaxPendingClientCount = 128; |
| 79 | 83 |
| 80 MidiManager(); | 84 MidiManager(MidiService* service); |
|
yhirano
2017/02/08 10:04:36
+explicit
Takashi Toyoshima
2017/02/08 11:08:55
Done.
| |
| 81 virtual ~MidiManager(); | 85 virtual ~MidiManager(); |
| 82 | 86 |
| 83 // The constructor and the destructor will be called on the CrBrowserMain | 87 // The constructor and the destructor will be called on the CrBrowserMain |
| 84 // thread. | 88 // thread. |
| 85 static MidiManager* Create(); | 89 static MidiManager* Create(MidiService* service); |
| 86 | 90 |
| 87 // Called on the CrBrowserMain thread to notify the Chrome_IOThread will stop | 91 // Called on the CrBrowserMain thread to notify the Chrome_IOThread will stop |
| 88 // and the instance will be destructed on the CrBrowserMain thread soon. | 92 // and the instance will be destructed on the CrBrowserMain thread soon. |
| 93 // *** Note ***: If dynamic instantiation feature is enabled, MidiService call | |
|
yhirano
2017/02/08 10:04:36
call"s"
Takashi Toyoshima
2017/02/08 11:08:55
Done.
| |
| 94 // this on Chrome_IOThread and ShutdownOnSessionThread() will be called | |
| 95 // synchronously so that MidiService can destruct MidiManager synchronously. | |
| 89 void Shutdown(); | 96 void Shutdown(); |
| 90 | 97 |
| 91 // A client calls StartSession() to receive and send MIDI data. | 98 // A client calls StartSession() to receive and send MIDI data. |
| 92 // If the session is ready to start, the MIDI system is lazily initialized | 99 // If the session is ready to start, the MIDI system is lazily initialized |
| 93 // and the client is registered to receive MIDI data. | 100 // and the client is registered to receive MIDI data. |
| 94 // CompleteStartSession() is called with mojom::Result::OK if the session is | 101 // CompleteStartSession() is called with mojom::Result::OK if the session is |
| 95 // started. Otherwise CompleteStartSession() is called with a proper | 102 // started. Otherwise CompleteStartSession() is called with a proper |
| 96 // mojom::Result code. | 103 // mojom::Result code. |
| 97 // StartSession() and EndSession() can be called on the Chrome_IOThread. | 104 // StartSession() and EndSession() can be called on the Chrome_IOThread. |
| 98 // CompleteStartSession() will be invoked on the same Chrome_IOThread. | 105 // CompleteStartSession() will be invoked on the same Chrome_IOThread. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 (time - base::TimeTicks()).InSecondsF()); | 174 (time - base::TimeTicks()).InSecondsF()); |
| 168 } | 175 } |
| 169 | 176 |
| 170 size_t clients_size_for_testing() const { return clients_.size(); } | 177 size_t clients_size_for_testing() const { return clients_.size(); } |
| 171 size_t pending_clients_size_for_testing() const { | 178 size_t pending_clients_size_for_testing() const { |
| 172 return pending_clients_.size(); | 179 return pending_clients_.size(); |
| 173 } | 180 } |
| 174 | 181 |
| 175 const MidiPortInfoList& input_ports() const { return input_ports_; } | 182 const MidiPortInfoList& input_ports() const { return input_ports_; } |
| 176 const MidiPortInfoList& output_ports() const { return output_ports_; } | 183 const MidiPortInfoList& output_ports() const { return output_ports_; } |
| 184 MidiService* service() { return service_; } | |
| 177 | 185 |
| 178 private: | 186 private: |
| 179 enum class InitializationState { | 187 enum class InitializationState { |
| 180 NOT_STARTED, | 188 NOT_STARTED, |
| 181 STARTED, | 189 STARTED, |
| 182 COMPLETED, | 190 COMPLETED, |
| 183 }; | 191 }; |
| 184 | 192 |
| 185 void CompleteInitializationInternal(mojom::Result result); | 193 void CompleteInitializationInternal(mojom::Result result); |
| 186 void AddInitialPorts(MidiManagerClient* client); | 194 void AddInitialPorts(MidiManagerClient* client); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 209 | 217 |
| 210 // Keeps all MidiPortInfo. | 218 // Keeps all MidiPortInfo. |
| 211 MidiPortInfoList input_ports_; | 219 MidiPortInfoList input_ports_; |
| 212 MidiPortInfoList output_ports_; | 220 MidiPortInfoList output_ports_; |
| 213 | 221 |
| 214 // Protects access to |clients_|, |pending_clients_|, | 222 // Protects access to |clients_|, |pending_clients_|, |
| 215 // |session_thread_runner_|, |initialization_state_|, |finalize_|, |result_|, | 223 // |session_thread_runner_|, |initialization_state_|, |finalize_|, |result_|, |
| 216 // |input_ports_| and |output_ports_|. | 224 // |input_ports_| and |output_ports_|. |
| 217 base::Lock lock_; | 225 base::Lock lock_; |
| 218 | 226 |
| 227 // MidiService outlives MidiManager. | |
| 228 MidiService* const service_; | |
| 229 | |
| 219 DISALLOW_COPY_AND_ASSIGN(MidiManager); | 230 DISALLOW_COPY_AND_ASSIGN(MidiManager); |
| 220 }; | 231 }; |
| 221 | 232 |
| 222 } // namespace midi | 233 } // namespace midi |
| 223 | 234 |
| 224 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ | 235 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ |
| OLD | NEW |