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

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

Issue 1396783004: Convert mojo::system::ChannelEndpointClient to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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/incoming_endpoint.h ('k') | mojo/edk/system/ipc_support_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "mojo/edk/system/channel_endpoint.h" 10 #include "mojo/edk/system/channel_endpoint.h"
11 #include "mojo/edk/system/data_pipe.h" 11 #include "mojo/edk/system/data_pipe.h"
12 #include "mojo/edk/system/message_in_transit.h" 12 #include "mojo/edk/system/message_in_transit.h"
13 #include "mojo/edk/system/message_pipe.h" 13 #include "mojo/edk/system/message_pipe.h"
14 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" 14 #include "mojo/edk/system/remote_producer_data_pipe_impl.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace system { 17 namespace system {
18 18
19 IncomingEndpoint::IncomingEndpoint() {
20 }
21
22 RefPtr<ChannelEndpoint> IncomingEndpoint::Init() { 19 RefPtr<ChannelEndpoint> IncomingEndpoint::Init() {
23 endpoint_ = MakeRefCounted<ChannelEndpoint>(this, 0); 20 endpoint_ =
21 MakeRefCounted<ChannelEndpoint>(RefPtr<IncomingEndpoint>(this), 0);
24 return endpoint_; 22 return endpoint_;
25 } 23 }
26 24
27 scoped_refptr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() { 25 RefPtr<MessagePipe> IncomingEndpoint::ConvertToMessagePipe() {
28 MutexLocker locker(&mutex_); 26 MutexLocker locker(&mutex_);
29 scoped_refptr<MessagePipe> message_pipe( 27 RefPtr<MessagePipe> message_pipe = MessagePipe::CreateLocalProxyFromExisting(
30 MessagePipe::CreateLocalProxyFromExisting(&message_queue_, 28 &message_queue_, std::move(endpoint_));
31 std::move(endpoint_)));
32 DCHECK(message_queue_.IsEmpty()); 29 DCHECK(message_queue_.IsEmpty());
33 return message_pipe; 30 return message_pipe;
34 } 31 }
35 32
36 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeProducer( 33 RefPtr<DataPipe> IncomingEndpoint::ConvertToDataPipeProducer(
37 const MojoCreateDataPipeOptions& validated_options, 34 const MojoCreateDataPipeOptions& validated_options,
38 size_t consumer_num_bytes) { 35 size_t consumer_num_bytes) {
39 MutexLocker locker(&mutex_); 36 MutexLocker locker(&mutex_);
40 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteConsumerFromExisting( 37 auto data_pipe = DataPipe::CreateRemoteConsumerFromExisting(
41 validated_options, consumer_num_bytes, &message_queue_, 38 validated_options, consumer_num_bytes, &message_queue_,
42 std::move(endpoint_))); 39 std::move(endpoint_));
43 DCHECK(message_queue_.IsEmpty()); 40 DCHECK(message_queue_.IsEmpty());
44 return data_pipe; 41 return data_pipe;
45 } 42 }
46 43
47 scoped_refptr<DataPipe> IncomingEndpoint::ConvertToDataPipeConsumer( 44 RefPtr<DataPipe> IncomingEndpoint::ConvertToDataPipeConsumer(
48 const MojoCreateDataPipeOptions& validated_options) { 45 const MojoCreateDataPipeOptions& validated_options) {
49 MutexLocker locker(&mutex_); 46 MutexLocker locker(&mutex_);
50 scoped_refptr<DataPipe> data_pipe(DataPipe::CreateRemoteProducerFromExisting( 47 auto data_pipe = DataPipe::CreateRemoteProducerFromExisting(
51 validated_options, &message_queue_, std::move(endpoint_))); 48 validated_options, &message_queue_, std::move(endpoint_));
52 DCHECK(message_queue_.IsEmpty()); 49 DCHECK(message_queue_.IsEmpty());
53 return data_pipe; 50 return data_pipe;
54 } 51 }
55 52
56 void IncomingEndpoint::Close() { 53 void IncomingEndpoint::Close() {
57 MutexLocker locker(&mutex_); 54 MutexLocker locker(&mutex_);
58 if (endpoint_) { 55 if (endpoint_) {
59 endpoint_->DetachFromClient(); 56 endpoint_->DetachFromClient();
60 endpoint_ = nullptr; 57 endpoint_ = nullptr;
61 } 58 }
62 } 59 }
63 60
64 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/, 61 bool IncomingEndpoint::OnReadMessage(unsigned /*port*/,
65 MessageInTransit* message) { 62 MessageInTransit* message) {
66 MutexLocker locker(&mutex_); 63 MutexLocker locker(&mutex_);
67 if (!endpoint_) 64 if (!endpoint_)
68 return false; 65 return false;
69 66
70 message_queue_.AddMessage(std::unique_ptr<MessageInTransit>(message)); 67 message_queue_.AddMessage(std::unique_ptr<MessageInTransit>(message));
71 return true; 68 return true;
72 } 69 }
73 70
74 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) { 71 void IncomingEndpoint::OnDetachFromChannel(unsigned /*port*/) {
75 Close(); 72 Close();
76 } 73 }
77 74
78 IncomingEndpoint::~IncomingEndpoint() { 75 IncomingEndpoint::IncomingEndpoint() {}
79 } 76
77 IncomingEndpoint::~IncomingEndpoint() {}
80 78
81 } // namespace system 79 } // namespace system
82 } // namespace mojo 80 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/incoming_endpoint.h ('k') | mojo/edk/system/ipc_support_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698