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

Side by Side Diff: mojo/public/cpp/bindings/lib/connector.cc

Issue 1932083002: Mojo: Use new message APIs to reduce copying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 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/public/cpp/bindings/lib/buffer.h ('k') | mojo/public/cpp/bindings/lib/fixed_buffer.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/public/cpp/bindings/lib/connector.h" 5 #include "mojo/public/cpp/bindings/lib/connector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // encountering an error, which should be fine. 143 // encountering an error, which should be fine.
144 if (error_) 144 if (error_)
145 return false; 145 return false;
146 146
147 MayAutoLock locker(lock_.get()); 147 MayAutoLock locker(lock_.get());
148 148
149 if (!message_pipe_.is_valid() || drop_writes_) 149 if (!message_pipe_.is_valid() || drop_writes_)
150 return true; 150 return true;
151 151
152 MojoResult rv = 152 MojoResult rv =
153 WriteMessageRaw(message_pipe_.get(), 153 WriteMessageNew(message_pipe_.get(), message->TakeMojoMessage(),
154 message->data(),
155 message->data_num_bytes(),
156 message->mutable_handles()->empty()
157 ? nullptr
158 : reinterpret_cast<const MojoHandle*>(
159 &message->mutable_handles()->front()),
160 static_cast<uint32_t>(message->mutable_handles()->size()),
161 MOJO_WRITE_MESSAGE_FLAG_NONE); 154 MOJO_WRITE_MESSAGE_FLAG_NONE);
162 155
163 // The handles are always either transferred or closed, so we don't need the
164 // message to track their lifetime any longer.
165 message->mutable_handles()->clear();
166
167 switch (rv) { 156 switch (rv) {
168 case MOJO_RESULT_OK: 157 case MOJO_RESULT_OK:
169 break; 158 break;
170 case MOJO_RESULT_FAILED_PRECONDITION: 159 case MOJO_RESULT_FAILED_PRECONDITION:
171 // There's no point in continuing to write to this pipe since the other 160 // There's no point in continuing to write to this pipe since the other
172 // end is gone. Avoid writing any future messages. Hide write failures 161 // end is gone. Avoid writing any future messages. Hide write failures
173 // from the caller since we'd like them to continue consuming any backlog 162 // from the caller since we'd like them to continue consuming any backlog
174 // of incoming messages before regarding the message pipe as closed. 163 // of incoming messages before regarding the message pipe as closed.
175 drop_writes_ = true; 164 drop_writes_ = true;
176 break; 165 break;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (sync_watcher_) 347 if (sync_watcher_)
359 return; 348 return;
360 sync_watcher_.reset(new SyncHandleWatcher( 349 sync_watcher_.reset(new SyncHandleWatcher(
361 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, 350 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
362 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, 351 base::Bind(&Connector::OnSyncHandleWatcherHandleReady,
363 base::Unretained(this)))); 352 base::Unretained(this))));
364 } 353 }
365 354
366 } // namespace internal 355 } // namespace internal
367 } // namespace mojo 356 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/buffer.h ('k') | mojo/public/cpp/bindings/lib/fixed_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698