| 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 "mojo/edk/embedder/embedder.h" | 5 #include "mojo/edk/embedder/embedder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 base::Bind(&ScopedTestChannel::DidCreateChannel, | 43 base::Bind(&ScopedTestChannel::DidCreateChannel, |
| 44 base::Unretained(this)), | 44 base::Unretained(this)), |
| 45 nullptr) | 45 nullptr) |
| 46 .release() | 46 .release() |
| 47 .value(); | 47 .value(); |
| 48 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); | 48 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Destructor: Shuts down the channel. (As noted above, for this to happen, | 51 // Destructor: Shuts down the channel. (As noted above, for this to happen, |
| 52 // the I/O thread must be alive and pumping messages.) | 52 // the I/O thread must be alive and pumping messages.) |
| 53 ~ScopedTestChannel() { | 53 ~ScopedTestChannel() { DestroyChannel(channel_info_); } |
| 54 system::test::PostTaskAndWait( | |
| 55 io_thread_task_runner_, FROM_HERE, | |
| 56 base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this))); | |
| 57 } | |
| 58 | 54 |
| 59 // Waits for channel creation to be completed. | 55 // Waits for channel creation to be completed. |
| 60 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } | 56 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } |
| 61 | 57 |
| 62 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } | 58 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } |
| 63 | 59 |
| 64 // Call only after |WaitForChannelCreationCompletion()|. Use only to check | 60 // Call only after |WaitForChannelCreationCompletion()|. Use only to check |
| 65 // that it's not null. | 61 // that it's not null. |
| 66 const ChannelInfo* channel_info() const { return channel_info_; } | 62 const ChannelInfo* channel_info() const { return channel_info_; } |
| 67 | 63 |
| 68 private: | 64 private: |
| 69 void DidCreateChannel(ChannelInfo* channel_info) { | 65 void DidCreateChannel(ChannelInfo* channel_info) { |
| 70 CHECK(channel_info); | 66 CHECK(channel_info); |
| 71 CHECK(!channel_info_); | 67 CHECK(!channel_info_); |
| 72 channel_info_ = channel_info; | 68 channel_info_ = channel_info; |
| 73 did_create_channel_event_.Signal(); | 69 did_create_channel_event_.Signal(); |
| 74 } | 70 } |
| 75 | 71 |
| 76 void DestroyChannel() { | |
| 77 CHECK(channel_info_); | |
| 78 DestroyChannelOnIOThread(channel_info_); | |
| 79 channel_info_ = nullptr; | |
| 80 } | |
| 81 | |
| 82 scoped_refptr<base::TaskRunner> io_thread_task_runner_; | 72 scoped_refptr<base::TaskRunner> io_thread_task_runner_; |
| 83 | 73 |
| 84 // Valid from creation until whenever it gets closed (by the "owner" of this | 74 // Valid from creation until whenever it gets closed (by the "owner" of this |
| 85 // object). | 75 // object). |
| 86 // Note: We don't want use the C++ wrappers here, since we want to test the | 76 // Note: We don't want use the C++ wrappers here, since we want to test the |
| 87 // API at the lowest level. | 77 // API at the lowest level. |
| 88 MojoHandle bootstrap_message_pipe_; | 78 MojoHandle bootstrap_message_pipe_; |
| 89 | 79 |
| 90 // Set after channel creation has been completed (i.e., the callback to | 80 // Set after channel creation has been completed (i.e., the callback to |
| 91 // |CreateChannel()| has been called). | 81 // |CreateChannel()| has been called). |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 484 |
| 495 EXPECT_TRUE(test::Shutdown()); | 485 EXPECT_TRUE(test::Shutdown()); |
| 496 } | 486 } |
| 497 | 487 |
| 498 // TODO(vtl): Test immediate write & close. | 488 // TODO(vtl): Test immediate write & close. |
| 499 // TODO(vtl): Test broken-connection cases. | 489 // TODO(vtl): Test broken-connection cases. |
| 500 | 490 |
| 501 } // namespace | 491 } // namespace |
| 502 } // namespace embedder | 492 } // namespace embedder |
| 503 } // namespace mojo | 493 } // namespace mojo |
| OLD | NEW |