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

Side by Side Diff: mojo/edk/embedder/embedder_unittest.cc

Issue 899993002: Add a thread-safe CreateChannel method to ChannelManager. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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
OLDNEW
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
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), 47 did_create_channel_event_(true, false), // Manual reset.
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() { DestroyChannel(channel_info_); } 61 ~ScopedTestChannel() {
62 // |WaitForChannelCreationCompletion()| must be called before destruction.
63 CHECK(did_create_channel_event_.IsSignaled());
64 DestroyChannel(channel_info_);
65 }
62 66
63 // Waits for channel creation to be completed. 67 // Waits for channel creation to be completed.
64 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } 68 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); }
65 69
66 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } 70 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; }
67 71
68 // Call only after |WaitForChannelCreationCompletion()|. Use only to check 72 // Call only after |WaitForChannelCreationCompletion()|. Use only to check
69 // that it's not null. 73 // that it's not null.
70 const ChannelInfo* channel_info() const { return channel_info_; } 74 const ChannelInfo* channel_info() const { return channel_info_; }
71 75
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 634
631 EXPECT_TRUE(test::Shutdown()); 635 EXPECT_TRUE(test::Shutdown());
632 } 636 }
633 637
634 // TODO(vtl): Test immediate write & close. 638 // TODO(vtl): Test immediate write & close.
635 // TODO(vtl): Test broken-connection cases. 639 // TODO(vtl): Test broken-connection cases.
636 640
637 } // namespace 641 } // namespace
638 } // namespace embedder 642 } // namespace embedder
639 } // namespace mojo 643 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698