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

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

Issue 2765673002: Revert of Making the Mojo Channel Messages legacy mode dynamic. (Closed)
Patch Set: 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"
18 #include "mojo/edk/embedder/platform_handle.h" 17 #include "mojo/edk/embedder/platform_handle.h"
19 18
20 #if defined(OS_MACOSX) && !defined(OS_IOS) 19 #if defined(OS_MACOSX) && !defined(OS_IOS)
21 #include "base/mac/mach_logging.h" 20 #include "base/mac/mach_logging.h"
22 #elif defined(OS_WIN) 21 #elif defined(OS_WIN)
23 #include "base/win/win_util.h" 22 #include "base/win/win_util.h"
24 #endif 23 #endif
25 24
26 namespace mojo { 25 namespace mojo {
27 namespace edk { 26 namespace edk {
(...skipping 11 matching lines...) Expand all
39 "LegacyHeader must be 8 bytes on ChromeOS and Android"); 38 "LegacyHeader must be 8 bytes on ChromeOS and Android");
40 39
41 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) == 40 static_assert(offsetof(Channel::Message::LegacyHeader, num_bytes) ==
42 offsetof(Channel::Message::Header, num_bytes), 41 offsetof(Channel::Message::Header, num_bytes),
43 "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.");
44 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) == 43 static_assert(offsetof(Channel::Message::LegacyHeader, message_type) ==
45 offsetof(Channel::Message::Header, message_type), 44 offsetof(Channel::Message::Header, message_type),
46 "message_type should be at the same offset in both Header " 45 "message_type should be at the same offset in both Header "
47 "structs."); 46 "structs.");
48 47
49 bool g_use_legacy_protocol = false;
50
51 } // namespace 48 } // namespace
52 49
53 const size_t kReadBufferSize = 4096; 50 const size_t kReadBufferSize = 4096;
54 const size_t kMaxUnusedReadBufferCapacity = 4096; 51 const size_t kMaxUnusedReadBufferCapacity = 4096;
55 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024; 52 const size_t kMaxChannelMessageSize = 256 * 1024 * 1024;
56 const size_t kMaxAttachedHandles = 128; 53 const size_t kMaxAttachedHandles = 128;
57 54
58 Channel::Message::Message(size_t payload_size, size_t max_handles) 55 Channel::Message::Message(size_t payload_size, size_t max_handles)
59 : Message(payload_size, 56 #if defined(MOJO_EDK_LEGACY_PROTOCOL)
60 max_handles, 57 : Message(payload_size, max_handles, MessageType::NORMAL_LEGACY) {
61 g_use_legacy_protocol ? MessageType::NORMAL_LEGACY 58 }
62 : MessageType::NORMAL) {} 59 #else
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
405 #if defined(OS_WIN) 398 #if defined(OS_WIN)
406 // static 399 // static
407 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, 400 bool Channel::Message::RewriteHandles(base::ProcessHandle from_process,
408 base::ProcessHandle to_process, 401 base::ProcessHandle to_process,
409 PlatformHandleVector* handles) { 402 PlatformHandleVector* handles) {
410 bool success = true; 403 bool success = true;
411 for (size_t i = 0; i < handles->size(); ++i) { 404 for (size_t i = 0; i < handles->size(); ++i) {
412 if (!(*handles)[i].is_valid()) { 405 if (!(*handles)[i].is_valid()) {
413 DLOG(ERROR) << "Refusing to duplicate invalid handle."; 406 DLOG(ERROR) << "Refusing to duplicate invalid handle.";
414 continue; 407 continue;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 674
682 bool Channel::OnControlMessage(Message::MessageType message_type, 675 bool Channel::OnControlMessage(Message::MessageType message_type,
683 const void* payload, 676 const void* payload,
684 size_t payload_size, 677 size_t payload_size,
685 ScopedPlatformHandleVectorPtr handles) { 678 ScopedPlatformHandleVectorPtr handles) {
686 return false; 679 return false;
687 } 680 }
688 681
689 } // namespace edk 682 } // namespace edk
690 } // namespace mojo 683 } // 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