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

Side by Side Diff: mojo/edk/system/test_channel_endpoint_client.cc

Issue 1153283004: Make TestChannelEndpointClient use MessageInTransitQueue. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « mojo/edk/system/test_channel_endpoint_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/system/test_channel_endpoint_client.h" 5 #include "mojo/edk/system/test_channel_endpoint_client.h"
6 6
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "mojo/edk/system/message_in_transit.h" 8 #include "mojo/edk/system/message_in_transit.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 13 matching lines...) Expand all
24 endpoint_ = endpoint; 24 endpoint_ = endpoint;
25 } 25 }
26 26
27 bool TestChannelEndpointClient::IsDetached() const { 27 bool TestChannelEndpointClient::IsDetached() const {
28 base::AutoLock locker(lock_); 28 base::AutoLock locker(lock_);
29 return !endpoint_; 29 return !endpoint_;
30 } 30 }
31 31
32 size_t TestChannelEndpointClient::NumMessages() const { 32 size_t TestChannelEndpointClient::NumMessages() const {
33 base::AutoLock locker(lock_); 33 base::AutoLock locker(lock_);
34 return messages_.size(); 34 return messages_.Size();
35 } 35 }
36 36
37 scoped_ptr<MessageInTransit> TestChannelEndpointClient::PopMessage() { 37 scoped_ptr<MessageInTransit> TestChannelEndpointClient::PopMessage() {
38 base::AutoLock locker(lock_); 38 base::AutoLock locker(lock_);
39 if (!messages_.size()) 39 if (messages_.IsEmpty())
40 return nullptr; 40 return nullptr;
41 scoped_ptr<MessageInTransit> rv(messages_.front()); 41 return messages_.GetMessage();
42 messages_.pop_front();
43 return rv;
44 } 42 }
45 43
46 void TestChannelEndpointClient::SetReadEvent(base::WaitableEvent* read_event) { 44 void TestChannelEndpointClient::SetReadEvent(base::WaitableEvent* read_event) {
47 base::AutoLock locker(lock_); 45 base::AutoLock locker(lock_);
48 read_event_ = read_event; 46 read_event_ = read_event;
49 } 47 }
50 48
51 bool TestChannelEndpointClient::OnReadMessage(unsigned port, 49 bool TestChannelEndpointClient::OnReadMessage(unsigned port,
52 MessageInTransit* message) { 50 MessageInTransit* message) {
53 base::AutoLock locker(lock_); 51 base::AutoLock locker(lock_);
54 52
55 EXPECT_EQ(port_, port); 53 EXPECT_EQ(port_, port);
56 EXPECT_TRUE(endpoint_); 54 EXPECT_TRUE(endpoint_);
57 messages_.push_back(message); 55 messages_.AddMessage(make_scoped_ptr(message));
58 56
59 if (read_event_) 57 if (read_event_)
60 read_event_->Signal(); 58 read_event_->Signal();
61 59
62 return true; 60 return true;
63 } 61 }
64 62
65 void TestChannelEndpointClient::OnDetachFromChannel(unsigned port) { 63 void TestChannelEndpointClient::OnDetachFromChannel(unsigned port) {
66 EXPECT_EQ(port_, port); 64 EXPECT_EQ(port_, port);
67 65
68 base::AutoLock locker(lock_); 66 base::AutoLock locker(lock_);
69 ASSERT_TRUE(endpoint_); 67 ASSERT_TRUE(endpoint_);
70 endpoint_->DetachFromClient(); 68 endpoint_->DetachFromClient();
71 endpoint_ = nullptr; 69 endpoint_ = nullptr;
72 } 70 }
73 71
74 TestChannelEndpointClient::~TestChannelEndpointClient() { 72 TestChannelEndpointClient::~TestChannelEndpointClient() {
75 EXPECT_FALSE(endpoint_); 73 EXPECT_FALSE(endpoint_);
76 for (auto message : messages_)
77 delete message;
78 } 74 }
79 75
80 } // namespace test 76 } // namespace test
81 } // namespace system 77 } // namespace system
82 } // namespace mojo 78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/test_channel_endpoint_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698