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

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

Issue 2749853003: Making the Mojo Channel Messages legacy mode dynamic. (Closed)
Patch Set: Fixed NaCl browser test failures. 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
« no previous file with comments | « mojo/edk/system/channel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 #include <limits> 11 #include <limits>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/aligned_memory.h" 15 #include "base/memory/aligned_memory.h"
16 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
17 #include "mojo/edk/embedder/embedder_internal.h"
17 #include "mojo/edk/embedder/platform_handle.h" 18 #include "mojo/edk/embedder/platform_handle.h"
18 19
19 #if defined(OS_MACOSX) && !defined(OS_IOS) 20 #if defined(OS_MACOSX) && !defined(OS_IOS)
20 #include "base/mac/mach_logging.h" 21 #include "base/mac/mach_logging.h"
21 #elif defined(OS_WIN) 22 #elif defined(OS_WIN)
22 #include "base/win/win_util.h" 23 #include "base/win/win_util.h"
23 #endif 24 #endif
24 25
25 namespace mojo { 26 namespace mojo {
26 namespace edk { 27 namespace edk {
(...skipping 11 matching lines...) Expand all
38 "LegacyHeader must be 8 bytes on ChromeOS and Android"); 39 "LegacyHeader must be 8 bytes on ChromeOS and Android");
39 40
40 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) == 41 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) ==
41 offsetof(Channel::Message::Header, num_bytes), 42 offsetof(Channel::Message::Header, num_bytes),
42 "num_bytes should be at the same offset in both Header structs."); 43 "num_bytes should be at the same offset in both Header structs.");
43 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) == 44 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) ==
44 offsetof(Channel::Message::Header, message_type), 45 offsetof(Channel::Message::Header, message_type),
45 "message_type should be at the same offset in both Header " 46 "message_type should be at the same offset in both Header "
46 "structs."); 47 "structs.");
47 48
49 bool g_use_legacy_protocol = false;
50
48 } // namespace 51 } // namespace
49 52
50 const size_t kReadBufferSize = 4096; 53 const size_t kReadBufferSize = 4096;
51 const size_t kMaxUnusedReadBufferCapacity = 4096; 54 const size_t kMaxUnusedReadBufferCapacity = 4096;
52 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024; 55 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024;
53 const size_t kMaxAttachedHandles = 128; 56 const size_t kMaxAttachedHandles = 128;
54 57
55 Channel::Message::Message(size_t payload_size, size_t max_handles) 58 Channel::Message::Message(size_t payload_size, size_t max_handles)
56 #if defined(MOJO_EDK_LEGACY_PROTOCOL) 59 : Message(payload_size,
57 : Message(payload_size, max_handles, MessageType::NORMAL_LEGACY) { 60 max_handles,
58 } 61 g_use_legacy_protocol ? MessageType::NORMAL_LEGACY
59 #else 62 : MessageType::NORMAL) {}
60 : Message(payload_size, max_handles, MessageType::NORMAL) {
61 }
62 #endif
63 63
64 Channel::Message::Message(size_t payload_size, 64 Channel::Message::Message(size_t payload_size,
65 size_t max_handles, 65 size_t max_handles,
66 MessageType message_type) 66 MessageType message_type)
67 : max_handles_(max_handles) { 67 : max_handles_(max_handles) {
68 DCHECK_LE(max_handles_, kMaxAttachedHandles); 68 DCHECK_LE(max_handles_, kMaxAttachedHandles);
69 69
70 const bool is_legacy_message = (message_type == MessageType::NORMAL_LEGACY); 70 const bool is_legacy_message = (message_type == MessageType::NORMAL_LEGACY);
71 size_t extra_header_size = 0; 71 size_t extra_header_size = 0;
72 #if defined(OS_WIN) 72 #if defined(OS_WIN)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 ++it; 388 ++it;
389 } 389 }
390 } 390 }
391 } 391 }
392 return std::move(handle_vector_); 392 return std::move(handle_vector_);
393 #else 393 #else
394 return std::move(handle_vector_); 394 return std::move(handle_vector_);
395 #endif 395 #endif
396 } 396 }
397 397
398 // static
399 void Channel::Message::SetUseLegacyTransportProtocol(bool use_legacy_protocol) {
400 // Make sure this is called before mojo::edk::Init() is called.
401 DCHECK(!internal::g_core);
402 g_use_legacy_protocol = use_legacy_protocol;
403 }
404
398 #if defined(OS_WIN) 405 #if defined(OS_WIN)
399 // static 406 // static
400 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, 407 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process,
401 base::ProcessHandle to_process, 408 base::ProcessHandle to_process,
402 PlatformHandleVector* handles) { 409 PlatformHandleVector* handles) {
403 bool success = true; 410 bool success = true;
404 for (size_t i = 0; i < handles->size(); ++i) { 411 for (size_t i = 0; i < handles->size(); ++i) {
405 if (!(*handles)[i].is_valid()) { 412 if (!(*handles)[i].is_valid()) {
406 DLOG(ERROR) << "Refusing to duplicate invalid handle."; 413 DLOG(ERROR) << "Refusing to duplicate invalid handle.";
407 continue; 414 continue;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 681
675 bool Channel::OnControlMessage(Message::MessageType message_type, 682 bool Channel::OnControlMessage(Message::MessageType message_type,
676 const void* payload, 683 const void* payload,
677 size_t payload_size, 684 size_t payload_size,
678 ScopedPlatformHandleVectorPtr handles) { 685 ScopedPlatformHandleVectorPtr handles) {
679 return false; 686 return false;
680 } 687 }
681 688
682 } // namespace edk 689 } // namespace edk
683 } // namespace mojo 690 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698