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

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

Issue 1478503003: EDK: Convert most uses of PlatformHandleVector to std::vector<ScopedPlatformHandle>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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/channel.h ('k') | mojo/edk/system/data_pipe.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/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "mojo/edk/embedder/platform_handle_vector.h" 13 #include "mojo/edk/embedder/platform_handle_vector.h"
14 #include "mojo/edk/system/endpoint_relayer.h" 14 #include "mojo/edk/system/endpoint_relayer.h"
15 #include "mojo/edk/system/transport_data.h" 15 #include "mojo/edk/system/transport_data.h"
16 16
17 using mojo::embedder::ScopedPlatformHandle;
17 using mojo::util::MakeRefCounted; 18 using mojo::util::MakeRefCounted;
18 using mojo::util::MutexLocker; 19 using mojo::util::MutexLocker;
19 using mojo::util::RefPtr; 20 using mojo::util::RefPtr;
20 21
21 namespace mojo { 22 namespace mojo {
22 namespace system { 23 namespace system {
23 24
24 namespace { 25 namespace {
25 26
26 struct SerializedEndpoint { 27 struct SerializedEndpoint {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (it == local_id_to_endpoint_map_.end() || it->second.get() != endpoint) 289 if (it == local_id_to_endpoint_map_.end() || it->second.get() != endpoint)
289 return false; 290 return false;
290 291
291 DCHECK(it->second); 292 DCHECK(it->second);
292 it->second = nullptr; 293 it->second = nullptr;
293 return true; 294 return true;
294 } 295 }
295 296
296 void Channel::OnReadMessage( 297 void Channel::OnReadMessage(
297 const MessageInTransit::View& message_view, 298 const MessageInTransit::View& message_view,
298 embedder::ScopedPlatformHandleVectorPtr platform_handles) { 299 std::unique_ptr<std::vector<ScopedPlatformHandle>> platform_handles) {
299 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 300 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
300 DCHECK(thread_checker_.IsCreationThreadCurrent()); 301 DCHECK(thread_checker_.IsCreationThreadCurrent());
301 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 302 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
302 303
303 switch (message_view.type()) { 304 switch (message_view.type()) {
304 case MessageInTransit::Type::ENDPOINT_CLIENT: 305 case MessageInTransit::Type::ENDPOINT_CLIENT:
305 case MessageInTransit::Type::ENDPOINT: 306 case MessageInTransit::Type::ENDPOINT:
306 OnReadMessageForEndpoint(message_view, std::move(platform_handles)); 307 OnReadMessageForEndpoint(message_view, std::move(platform_handles));
307 break; 308 break;
308 case MessageInTransit::Type::CHANNEL: 309 case MessageInTransit::Type::CHANNEL:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // Write errors are slightly notable: they probably shouldn't happen under 346 // Write errors are slightly notable: they probably shouldn't happen under
346 // normal operation (but maybe the other side crashed). 347 // normal operation (but maybe the other side crashed).
347 LOG(WARNING) << "RawChannel write error"; 348 LOG(WARNING) << "RawChannel write error";
348 break; 349 break;
349 } 350 }
350 Shutdown(); 351 Shutdown();
351 } 352 }
352 353
353 void Channel::OnReadMessageForEndpoint( 354 void Channel::OnReadMessageForEndpoint(
354 const MessageInTransit::View& message_view, 355 const MessageInTransit::View& message_view,
355 embedder::ScopedPlatformHandleVectorPtr platform_handles) { 356 std::unique_ptr<std::vector<ScopedPlatformHandle>> platform_handles) {
356 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 357 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
357 DCHECK(thread_checker_.IsCreationThreadCurrent()); 358 DCHECK(thread_checker_.IsCreationThreadCurrent());
358 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 359 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
359 DCHECK(message_view.type() == MessageInTransit::Type::ENDPOINT_CLIENT || 360 DCHECK(message_view.type() == MessageInTransit::Type::ENDPOINT_CLIENT ||
360 message_view.type() == MessageInTransit::Type::ENDPOINT); 361 message_view.type() == MessageInTransit::Type::ENDPOINT);
361 362
362 ChannelEndpointId local_id = message_view.destination_id(); 363 ChannelEndpointId local_id = message_view.destination_id();
363 if (!local_id.is_valid()) { 364 if (!local_id.is_valid()) {
364 HandleRemoteError("Received message with no destination ID"); 365 HandleRemoteError("Received message with no destination ID");
365 return; 366 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 message_view.transport_data_buffer(), 409 message_view.transport_data_buffer(),
409 message_view.transport_data_buffer_size(), std::move(platform_handles), 410 message_view.transport_data_buffer_size(), std::move(platform_handles),
410 this)); 411 this));
411 } 412 }
412 413
413 endpoint->OnReadMessage(std::move(message)); 414 endpoint->OnReadMessage(std::move(message));
414 } 415 }
415 416
416 void Channel::OnReadMessageForChannel( 417 void Channel::OnReadMessageForChannel(
417 const MessageInTransit::View& message_view, 418 const MessageInTransit::View& message_view,
418 embedder::ScopedPlatformHandleVectorPtr platform_handles) { 419 std::unique_ptr<std::vector<ScopedPlatformHandle>> platform_handles) {
419 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 420 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
420 DCHECK(thread_checker_.IsCreationThreadCurrent()); 421 DCHECK(thread_checker_.IsCreationThreadCurrent());
421 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 422 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
422 DCHECK_EQ(message_view.type(), MessageInTransit::Type::CHANNEL); 423 DCHECK_EQ(message_view.type(), MessageInTransit::Type::CHANNEL);
423 424
424 // Currently, no channel messages take platform handles. 425 // Currently, no channel messages take platform handles.
425 if (platform_handles) { 426 if (platform_handles) {
426 HandleRemoteError( 427 HandleRemoteError(
427 "Received invalid channel message (has platform handles)"); 428 "Received invalid channel message (has platform handles)");
428 NOTREACHED(); 429 NOTREACHED();
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 << ", local ID " << local_id << ", remote ID " << remote_id; 641 << ", local ID " << local_id << ", remote ID " << remote_id;
641 std::unique_ptr<MessageInTransit> message(new MessageInTransit( 642 std::unique_ptr<MessageInTransit> message(new MessageInTransit(
642 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes)); 643 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes));
643 message->set_source_id(local_id); 644 message->set_source_id(local_id);
644 message->set_destination_id(remote_id); 645 message->set_destination_id(remote_id);
645 return WriteMessage(std::move(message)); 646 return WriteMessage(std::move(message));
646 } 647 }
647 648
648 } // namespace system 649 } // namespace system
649 } // namespace mojo 650 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/data_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698