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

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

Issue 2749853003: Making the Mojo Channel Messages legacy mode dynamic. (Closed)
Patch Set: Making the Mojo Channel Messages legacy mode dynamic. Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 27 matching lines...) Expand all
38 "LegacyHeader must be 8 bytes on ChromeOS and Android"); 38 "LegacyHeader must be 8 bytes on ChromeOS and Android");
39 39
40 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) == 40 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) ==
41 offsetof(Channel::Message::Header, num_bytes), 41 offsetof(Channel::Message::Header, num_bytes),
42 "num_bytes should be at the same offset in both Header structs."); 42 "num_bytes should be at the same offset in both Header structs.");
43 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) == 43 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) ==
44 offsetof(Channel::Message::Header, message_type), 44 offsetof(Channel::Message::Header, message_type),
45 "message_type should be at the same offset in both Header " 45 "message_type should be at the same offset in both Header "
46 "structs."); 46 "structs.");
47 47
48 bool g_use_legacy_protocol = false;
49
48 } // namespace 50 } // namespace
49 51
50 const size_t kReadBufferSize = 4096; 52 const size_t kReadBufferSize = 4096;
51 const size_t kMaxUnusedReadBufferCapacity = 4096; 53 const size_t kMaxUnusedReadBufferCapacity = 4096;
52 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024; 54 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024;
53 const size_t kMaxAttachedHandles = 128; 55 const size_t kMaxAttachedHandles = 128;
54 56
55 Channel::Message::Message(size_t payload_size, size_t max_handles) 57 Channel::Message::Message(size_t payload_size, size_t max_handles)
56 #if defined(MOJO_EDK_LEGACY_PROTOCOL) 58 : Message(payload_size, max_handles,
57 : Message(payload_size, max_handles, MessageType::NORMAL_LEGACY) { 59 g_use_legacy_protocol ? MessageType::NORMAL_LEGACY
60 : MessageType::NORMAL) {
58 } 61 }
59 #else
60 : Message(payload_size, max_handles, MessageType::NORMAL) {
61 }
62 #endif
63 62
64 Channel::Message::Message(size_t payload_size, 63 Channel::Message::Message(size_t payload_size,
65 size_t max_handles, 64 size_t max_handles,
66 MessageType message_type) 65 MessageType message_type)
67 : max_handles_(max_handles) { 66 : max_handles_(max_handles) {
68 DCHECK_LE(max_handles_, kMaxAttachedHandles); 67 DCHECK_LE(max_handles_, kMaxAttachedHandles);
69 68
70 const bool is_legacy_message = (message_type == MessageType::NORMAL_LEGACY); 69 const bool is_legacy_message = (message_type == MessageType::NORMAL_LEGACY);
71 size_t extra_header_size = 0; 70 size_t extra_header_size = 0;
72 #if defined(OS_WIN) 71 #if defined(OS_WIN)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 ++it; 387 ++it;
389 } 388 }
390 } 389 }
391 } 390 }
392 return std::move(handle_vector_); 391 return std::move(handle_vector_);
393 #else 392 #else
394 return std::move(handle_vector_); 393 return std::move(handle_vector_);
395 #endif 394 #endif
396 } 395 }
397 396
397 // static
398 void Channel::Message::SetUseLegacyTransportProtocol(bool use_legacy_protocol) {
399 g_use_legacy_protocol = use_legacy_protocol;
Ken Rockot(use gerrit already) 2017/03/15 17:59:31 nit: Let's add a DCHECK(!internal::g_core) to ensu
Jay Civelli 2017/03/15 18:14:09 Good idea, done.
400 }
401
398 #if defined(OS_WIN) 402 #if defined(OS_WIN)
399 // static 403 // static
400 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, 404 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process,
401 base::ProcessHandle to_process, 405 base::ProcessHandle to_process,
402 PlatformHandleVector* handles) { 406 PlatformHandleVector* handles) {
403 bool success = true; 407 bool success = true;
404 for (size_t i = 0; i < handles->size(); ++i) { 408 for (size_t i = 0; i < handles->size(); ++i) {
405 if (!(*handles)[i].is_valid()) { 409 if (!(*handles)[i].is_valid()) {
406 DLOG(ERROR) << "Refusing to duplicate invalid handle."; 410 DLOG(ERROR) << "Refusing to duplicate invalid handle.";
407 continue; 411 continue;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 678
675 bool Channel::OnControlMessage(Message::MessageType message_type, 679 bool Channel::OnControlMessage(Message::MessageType message_type,
676 const void* payload, 680 const void* payload,
677 size_t payload_size, 681 size_t payload_size,
678 ScopedPlatformHandleVectorPtr handles) { 682 ScopedPlatformHandleVectorPtr handles) {
679 return false; 683 return false;
680 } 684 }
681 685
682 } // namespace edk 686 } // namespace edk
683 } // namespace mojo 687 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698