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

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

Issue 2443113002: Fix possible multiple calls to MidiManager::StartInitialization() in StartSession() (Closed)
Patch Set: styles Created 4 years, 1 month 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 | « no previous file | 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 #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
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 size_t clients_size_for_testing() const { return clients_.size(); } 169 size_t clients_size_for_testing() const { return clients_.size(); }
170 size_t pending_clients_size_for_testing() const { 170 size_t pending_clients_size_for_testing() const {
171 return pending_clients_.size(); 171 return pending_clients_.size();
172 } 172 }
173 173
174 const MidiPortInfoList& input_ports() const { return input_ports_; } 174 const MidiPortInfoList& input_ports() const { return input_ports_; }
175 const MidiPortInfoList& output_ports() const { return output_ports_; } 175 const MidiPortInfoList& output_ports() const { return output_ports_; }
176 176
177 private: 177 private:
178 enum class InitializationState {
179 NOT_STARTED,
180 STARTED,
181 COMPLETED,
182 };
183
178 void CompleteInitializationInternal(mojom::Result result); 184 void CompleteInitializationInternal(mojom::Result result);
179 void AddInitialPorts(MidiManagerClient* client); 185 void AddInitialPorts(MidiManagerClient* client);
180 void ShutdownOnSessionThread(); 186 void ShutdownOnSessionThread();
181 187
182 // Keeps track of all clients who wish to receive MIDI data. 188 // Keeps track of all clients who wish to receive MIDI data.
183 typedef std::set<MidiManagerClient*> ClientSet; 189 typedef std::set<MidiManagerClient*> ClientSet;
184 ClientSet clients_; 190 ClientSet clients_;
185 191
186 // Keeps track of all clients who are waiting for CompleteStartSession(). 192 // Keeps track of all clients who are waiting for CompleteStartSession().
187 ClientSet pending_clients_; 193 ClientSet pending_clients_;
188 194
189 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in 195 // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in
190 // order to invoke CompleteStartSession() on the thread. 196 // order to invoke CompleteStartSession() on the thread.
191 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; 197 scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_;
192 198
193 // Keeps true if platform dependent initialization is already completed. 199 // Tracks platform dependent initialization state.
194 bool initialized_; 200 InitializationState initialization_state_;
195 201
196 // Keeps false until Finalize() is called. 202 // Keeps false until Finalize() is called.
197 bool finalized_; 203 bool finalized_;
198 204
199 // Keeps the platform dependent initialization result if initialization is 205 // Keeps the platform dependent initialization result if initialization is
200 // completed. Otherwise keeps mojom::Result::NOT_INITIALIZED. 206 // completed. Otherwise keeps mojom::Result::NOT_INITIALIZED.
201 mojom::Result result_; 207 mojom::Result result_;
202 208
203 // Keeps all MidiPortInfo. 209 // Keeps all MidiPortInfo.
204 MidiPortInfoList input_ports_; 210 MidiPortInfoList input_ports_;
205 MidiPortInfoList output_ports_; 211 MidiPortInfoList output_ports_;
206 212
207 // Protects access to |clients_|, |pending_clients_|, 213 // Protects access to |clients_|, |pending_clients_|,
208 // |session_thread_runner_|, |initialized_|, |finalize_|, |result_|, 214 // |session_thread_runner_|, |initialization_state_|, |finalize_|, |result_|,
209 // |input_ports_| and |output_ports_|. 215 // |input_ports_| and |output_ports_|.
210 base::Lock lock_; 216 base::Lock lock_;
211 217
212 DISALLOW_COPY_AND_ASSIGN(MidiManager); 218 DISALLOW_COPY_AND_ASSIGN(MidiManager);
213 }; 219 };
214 220
215 } // namespace midi 221 } // namespace midi
216 222
217 #endif // MEDIA_MIDI_MIDI_MANAGER_H_ 223 #endif // MEDIA_MIDI_MIDI_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | media/midi/midi_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698