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

Side by Side Diff: mojo/edk/system/incoming_endpoint.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 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/system/incoming_endpoint.h" 5 #include "mojo/edk/system/incoming_endpoint.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/edk/system/channel_endpoint.h" 8 #include "mojo/edk/system/channel_endpoint.h"
9 #include "mojo/edk/system/data_pipe.h" 9 #include "mojo/edk/system/data_pipe.h"
10 #include "mojo/edk/system/message_in_transit.h" 10 #include "mojo/edk/system/message_in_transit.h"
11 #include "mojo/edk/system/message_pipe.h" 11 #include "mojo/edk/system/message_pipe.h"
12 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" 12 #include "mojo/edk/system/remote_producer_data_pipe_impl.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace system { 15 namespace system {
16 16
17 IncomingEndpoint::IncomingEndpoint() { 17 IncomingEndpoint::IncomingEndpoint() {
18 } 18 }
19 19
20 scoped_refptr<ChannelEndpoint> IncomingEndpoint::Init() { 20 scoped_refptr<ChannelEndpoint> IncomingEndpoint::Init()
21 MOJO_NO_THREAD_SAFETY_ANALYSIS {
21 endpoint_ = new ChannelEndpoint(this, 0); 22 endpoint_ = new ChannelEndpoint(this, 0);
22 return endpoint_; 23 return endpoint_;
23 } 24 }
24 25
25 scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() { 26 scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() {
26 base::AutoLock locker(lock_); 27 MutexLocker locker(&mutex_);
27 scoped_refptr<MessagePipe> message_pipe( 28 scoped_refptr<MessagePipe> message_pipe(
28 MessagePipe::CreateLocalProxyFromExisting(&message_queue_, 29 MessagePipe::CreateLocalProxyFromExisting(&message_queue_,
29 endpoint_.get())); 30 endpoint_.get()));
30 DCHECK(message_queue_.IsEmpty()); 31 DCHECK(message_queue_.IsEmpty());
31 endpoint_ = nullptr; 32 endpoint_ = nullptr;
32 return message_pipe; 33 return message_pipe;
33 } 34 }
34 35
35 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeProducer( 36 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeProducer(
36 const MojoCreateDataPipeOptions& validated_options, 37 const MojoCreateDataPipeOptions& validated_options,
37 size_t consumer_num_bytes) { 38 size_t consumer_num_bytes) {
38 base::AutoLock locker(lock_); 39 MutexLocker locker(&mutex_);
39 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteConsumerFromExisting( 40 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteConsumerFromExisting(
40 validated_options, consumer_num_bytes, &message_queue_, endpoint_.get())); 41 validated_options, consumer_num_bytes, &message_queue_, endpoint_.get()));
41 DCHECK(message_queue_.IsEmpty()); 42 DCHECK(message_queue_.IsEmpty());
42 endpoint_ = nullptr; 43 endpoint_ = nullptr;
43 return data_pipe; 44 return data_pipe;
44 } 45 }
45 46
46 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeConsumer( 47 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeConsumer(
47 const MojoCreateDataPipeOptions& validated_options) { 48 const MojoCreateDataPipeOptions& validated_options) {
48 base::AutoLock locker(lock_); 49 MutexLocker locker(&mutex_);
49 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteProducerFromExisting( 50 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteProducerFromExisting(
50 validated_options, &message_queue_, endpoint_.get())); 51 validated_options, &message_queue_, endpoint_.get()));
51 DCHECK(message_queue_.IsEmpty()); 52 DCHECK(message_queue_.IsEmpty());
52 endpoint_ = nullptr; 53 endpoint_ = nullptr;
53 return data_pipe; 54 return data_pipe;
54 } 55 }
55 56
56 void IncomingEndpoint::Close() { 57 void IncomingEndpoint::Close() {
57 base::AutoLock locker(lock_); 58 MutexLocker locker(&mutex_);
58 if (endpoint_) { 59 if (endpoint_) {
59 endpoint_->DetachFromClient(); 60 endpoint_->DetachFromClient();
60 endpoint_ = nullptr; 61 endpoint_ = nullptr;
61 } 62 }
62 } 63 }
63 64
64 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/, 65 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/,
65 MessageInTransit* message) { 66 MessageInTransit* message) {
66 base::AutoLock locker(lock_); 67 MutexLocker locker(&mutex_);
67 if (!endpoint_) 68 if (!endpoint_)
68 return false; 69 return false;
69 70
70 message_queue_.AddMessage(make_scoped_ptr(message)); 71 message_queue_.AddMessage(make_scoped_ptr(message));
71 return true; 72 return true;
72 } 73 }
73 74
74 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) { 75 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) {
75 Close(); 76 Close();
76 } 77 }
77 78
78 IncomingEndpoint::~IncomingEndpoint() { 79 IncomingEndpoint::~IncomingEndpoint() {
79 } 80 }
80 81
81 } // namespace system 82 } // namespace system
82 } // namespace mojo 83 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698