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

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

Issue 1234683002: Convert some more |base::Lock|s to |mojo::system::Mutex|s. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 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
11 namespace mojo { 11 namespace mojo {
12 namespace system { 12 namespace system {
13 namespace test { 13 namespace test {
14 14
15 TestChannelEndpointClient::TestChannelEndpointClient() 15 TestChannelEndpointClient::TestChannelEndpointClient()
16 : port_(0), read_event_(nullptr) { 16 : port_(0), read_event_(nullptr) {
17 } 17 }
18 18
19 void TestChannelEndpointClient::Init(unsigned port, ChannelEndpoint* endpoint) { 19 void TestChannelEndpointClient::Init(unsigned port, ChannelEndpoint* endpoint) {
20 base::AutoLock locker(lock_); 20 MutexLocker locker(&mutex_);
21 ASSERT_EQ(0u, port_); 21 ASSERT_EQ(0u, port_);
22 ASSERT_FALSE(endpoint_); 22 ASSERT_FALSE(endpoint_);
23 port_ = port; 23 port_ = port;
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 MutexLocker locker(&mutex_);
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 MutexLocker locker(&mutex_);
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 MutexLocker locker(&mutex_);
39 if (messages_.IsEmpty()) 39 if (messages_.IsEmpty())
40 return nullptr; 40 return nullptr;
41 return messages_.GetMessage(); 41 return messages_.GetMessage();
42 } 42 }
43 43
44 void TestChannelEndpointClient::SetReadEvent(base::WaitableEvent* read_event) { 44 void TestChannelEndpointClient::SetReadEvent(base::WaitableEvent* read_event) {
45 base::AutoLock locker(lock_); 45 MutexLocker locker(&mutex_);
46 read_event_ = read_event; 46 read_event_ = read_event;
47 } 47 }
48 48
49 bool TestChannelEndpointClient::OnReadMessage(unsigned port, 49 bool TestChannelEndpointClient::OnReadMessage(unsigned port,
50 MessageInTransit* message) { 50 MessageInTransit* message) {
51 base::AutoLock locker(lock_); 51 MutexLocker locker(&mutex_);
52 52
53 EXPECT_EQ(port_, port); 53 EXPECT_EQ(port_, port);
54 EXPECT_TRUE(endpoint_); 54 EXPECT_TRUE(endpoint_);
55 messages_.AddMessage(make_scoped_ptr(message)); 55 messages_.AddMessage(make_scoped_ptr(message));
56 56
57 if (read_event_) 57 if (read_event_)
58 read_event_->Signal(); 58 read_event_->Signal();
59 59
60 return true; 60 return true;
61 } 61 }
62 62
63 void TestChannelEndpointClient::OnDetachFromChannel(unsigned port) { 63 void TestChannelEndpointClient::OnDetachFromChannel(unsigned port) {
64 MutexLocker locker(&mutex_);
65
64 EXPECT_EQ(port_, port); 66 EXPECT_EQ(port_, port);
65
66 base::AutoLock locker(lock_);
67 ASSERT_TRUE(endpoint_); 67 ASSERT_TRUE(endpoint_);
68 endpoint_->DetachFromClient(); 68 endpoint_->DetachFromClient();
69 endpoint_ = nullptr; 69 endpoint_ = nullptr;
70 } 70 }
71 71
72 TestChannelEndpointClient::~TestChannelEndpointClient() { 72 TestChannelEndpointClient::~TestChannelEndpointClient() {
73 EXPECT_FALSE(endpoint_); 73 EXPECT_FALSE(endpoint_);
74 } 74 }
75 75
76 } // namespace test 76 } // namespace test
77 } // namespace system 77 } // namespace system
78 } // namespace mojo 78 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698