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 26 matching lines...) Expand all Loading... |
37 // Creates a channel that lives on a given I/O thread (determined by the given | 37 // Creates a channel that lives on a given I/O thread (determined by the given |
38 // |TaskRunner|) attached to the given |platform_handle|. After construction, | 38 // |TaskRunner|) attached to the given |platform_handle|. After construction, |
39 // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message | 39 // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message |
40 // pipe on this channel; it is up to the caller to close this handle. | 40 // pipe on this channel; it is up to the caller to close this handle. |
41 // Note: The I/O thread must outlive this object (and its message loop must | 41 // Note: The I/O thread must outlive this object (and its message loop must |
42 // continue pumping messages while this object is alive). | 42 // continue pumping messages while this object is alive). |
43 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner, | 43 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner, |
44 ScopedPlatformHandle platform_handle) | 44 ScopedPlatformHandle platform_handle) |
45 : io_thread_task_runner_(io_thread_task_runner), | 45 : io_thread_task_runner_(io_thread_task_runner), |
46 bootstrap_message_pipe_(MOJO_HANDLE_INVALID), | 46 bootstrap_message_pipe_(MOJO_HANDLE_INVALID), |
47 did_create_channel_event_(true, false), // Manual reset. | 47 did_create_channel_event_(true, false), |
48 channel_info_(nullptr) { | 48 channel_info_(nullptr) { |
49 bootstrap_message_pipe_ = | 49 bootstrap_message_pipe_ = |
50 CreateChannel(platform_handle.Pass(), io_thread_task_runner_, | 50 CreateChannel(platform_handle.Pass(), io_thread_task_runner_, |
51 base::Bind(&ScopedTestChannel::DidCreateChannel, | 51 base::Bind(&ScopedTestChannel::DidCreateChannel, |
52 base::Unretained(this)), | 52 base::Unretained(this)), |
53 nullptr) | 53 nullptr) |
54 .release() | 54 .release() |
55 .value(); | 55 .value(); |
56 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); | 56 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); |
57 } | 57 } |
58 | 58 |
59 // Destructor: Shuts down the channel. (As noted above, for this to happen, | 59 // Destructor: Shuts down the channel. (As noted above, for this to happen, |
60 // the I/O thread must be alive and pumping messages.) | 60 // the I/O thread must be alive and pumping messages.) |
61 ~ScopedTestChannel() { | 61 ~ScopedTestChannel() { DestroyChannel(channel_info_); } |
62 // |WaitForChannelCreationCompletion()| must be called before destruction. | |
63 CHECK(did_create_channel_event_.IsSignaled()); | |
64 DestroyChannel(channel_info_); | |
65 } | |
66 | 62 |
67 // Waits for channel creation to be completed. | 63 // Waits for channel creation to be completed. |
68 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } | 64 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } |
69 | 65 |
70 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } | 66 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } |
71 | 67 |
72 // Call only after |WaitForChannelCreationCompletion()|. Use only to check | 68 // Call only after |WaitForChannelCreationCompletion()|. Use only to check |
73 // that it's not null. | 69 // that it's not null. |
74 const ChannelInfo* channel_info() const { return channel_info_; } | 70 const ChannelInfo* channel_info() const { return channel_info_; } |
75 | 71 |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 630 |
635 EXPECT_TRUE(test::Shutdown()); | 631 EXPECT_TRUE(test::Shutdown()); |
636 } | 632 } |
637 | 633 |
638 // TODO(vtl): Test immediate write & close. | 634 // TODO(vtl): Test immediate write & close. |
639 // TODO(vtl): Test broken-connection cases. | 635 // TODO(vtl): Test broken-connection cases. |
640 | 636 |
641 } // namespace | 637 } // namespace |
642 } // namespace embedder | 638 } // namespace embedder |
643 } // namespace mojo | 639 } // namespace mojo |
OLD | NEW |