| 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.h" | 5 #include "media/midi/midi_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 wait_for_result_ = false; | 68 wait_for_result_ = false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual void ReceiveMidiData(uint32 port_index, const uint8* data, | 71 virtual void ReceiveMidiData(uint32 port_index, const uint8* data, |
| 72 size_t size, double timestamp) override {} | 72 size_t size, double timestamp) override {} |
| 73 virtual void AccumulateMidiBytesSent(size_t size) override {} | 73 virtual void AccumulateMidiBytesSent(size_t size) override {} |
| 74 | 74 |
| 75 int client_id() const { return client_id_; } | 75 int client_id() const { return client_id_; } |
| 76 MidiResult result() const { return result_; } | 76 MidiResult result() const { return result_; } |
| 77 | 77 |
| 78 void HandleContinuationMessage() { | |
| 79 // Stop posting a dummy message once CompleteStartSession() is invoked. | |
| 80 if (!wait_for_result_) | |
| 81 return; | |
| 82 base::MessageLoop::current()->PostTask( | |
| 83 FROM_HERE, | |
| 84 base::Bind(&FakeMidiManagerClient::HandleContinuationMessage, | |
| 85 base::Unretained(this))); | |
| 86 } | |
| 87 | |
| 88 | |
| 89 MidiResult WaitForResult() { | 78 MidiResult WaitForResult() { |
| 90 base::RunLoop run_loop; | 79 while (wait_for_result_) { |
| 91 // Post a dummy task not to stop the following event loop. | 80 base::RunLoop run_loop; |
| 92 HandleContinuationMessage(); | 81 run_loop.RunUntilIdle(); |
| 93 // CompleteStartSession() is called inside the message loop on the same | 82 } |
| 94 // thread. Protection for |wait_for_result_| is not needed. | |
| 95 run_loop.RunUntilIdle(); | |
| 96 return result(); | 83 return result(); |
| 97 } | 84 } |
| 98 | 85 |
| 99 private: | 86 private: |
| 100 int client_id_; | 87 int client_id_; |
| 101 MidiResult result_; | 88 MidiResult result_; |
| 102 bool wait_for_result_; | 89 bool wait_for_result_; |
| 103 | 90 |
| 104 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); | 91 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); |
| 105 }; | 92 }; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // Temporary until http://crbug.com/371230 is resolved. | 259 // Temporary until http://crbug.com/371230 is resolved. |
| 273 EXPECT_TRUE((result == MIDI_OK) || (result == MIDI_INITIALIZATION_ERROR)); | 260 EXPECT_TRUE((result == MIDI_OK) || (result == MIDI_INITIALIZATION_ERROR)); |
| 274 #else | 261 #else |
| 275 EXPECT_EQ(MIDI_OK, result); | 262 EXPECT_EQ(MIDI_OK, result); |
| 276 #endif | 263 #endif |
| 277 } | 264 } |
| 278 | 265 |
| 279 } // namespace | 266 } // namespace |
| 280 | 267 |
| 281 } // namespace media | 268 } // namespace media |
| OLD | NEW |