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

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

Issue 1775693002: [mojo-edk] Keep old wire format and semantics on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « no previous file | mojo/edk/system/channel.cc » ('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 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 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_
6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 27 matching lines...) Expand all
38 // A control message containing handles to echo back. 38 // A control message containing handles to echo back.
39 HANDLES_SENT, 39 HANDLES_SENT,
40 // A control message containing handles that can now be closed. 40 // A control message containing handles that can now be closed.
41 HANDLES_SENT_ACK, 41 HANDLES_SENT_ACK,
42 #endif 42 #endif
43 }; 43 };
44 44
45 // Message size in bytes, including the header. 45 // Message size in bytes, including the header.
46 uint32_t num_bytes; 46 uint32_t num_bytes;
47 47
48 #if defined(OS_CHROMEOS) 48 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
49 // Old message wire format for ChromeOS. 49 // Old message wire format for ChromeOS and Android.
50 // Number of attached handles. 50 // Number of attached handles.
51 uint16_t num_handles; 51 uint16_t num_handles;
52 52
53 MessageType message_type; 53 MessageType message_type;
54 #else 54 #else
55 // Total size of header, including extra header data (i.e. HANDLEs on 55 // Total size of header, including extra header data (i.e. HANDLEs on
56 // windows). 56 // windows).
57 uint16_t num_header_bytes; 57 uint16_t num_header_bytes;
58 58
59 // Number of attached handles. May be less than the reserved handle 59 // Number of attached handles. May be less than the reserved handle
60 // storage size in this message on platforms that serialise handles as 60 // storage size in this message on platforms that serialise handles as
61 // data (i.e. HANDLEs on Windows, Mach ports on OSX). 61 // data (i.e. HANDLEs on Windows, Mach ports on OSX).
62 uint16_t num_handles; 62 uint16_t num_handles;
63 63
64 MessageType message_type; 64 MessageType message_type;
65 65
66 char padding[6]; 66 char padding[6];
67 #endif // defined(OS_CHROMEOS) 67 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
68 }; 68 };
69 #pragma pack(pop) 69 #pragma pack(pop)
70 70
71 // Allocates and owns a buffer for message data with enough capacity for 71 // Allocates and owns a buffer for message data with enough capacity for
72 // |payload_size| bytes plus a header, plus |max_handles| platform handles. 72 // |payload_size| bytes plus a header, plus |max_handles| platform handles.
73 Message(size_t payload_size, 73 Message(size_t payload_size,
74 size_t max_handles, 74 size_t max_handles,
75 Header::MessageType message_type = Header::MessageType::NORMAL); 75 Header::MessageType message_type = Header::MessageType::NORMAL);
76 76
77 ~Message(); 77 ~Message();
78 78
79 // Constructs a Message from serialized message data. 79 // Constructs a Message from serialized message data.
80 static MessagePtr Deserialize(const void* data, size_t data_num_bytes); 80 static MessagePtr Deserialize(const void* data, size_t data_num_bytes);
81 81
82 const void* data() const { return data_; } 82 const void* data() const { return data_; }
83 size_t data_num_bytes() const { return size_; } 83 size_t data_num_bytes() const { return size_; }
84 84
85 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
86 void* mutable_payload() { return static_cast<void*>(header_ + 1); } 86 void* mutable_payload() { return static_cast<void*>(header_ + 1); }
87 const void* payload() const { 87 const void* payload() const {
88 return static_cast<const void*>(header_ + 1); 88 return static_cast<const void*>(header_ + 1);
89 } 89 }
90 size_t payload_size() const; 90 size_t payload_size() const;
91 #else 91 #else
92 const void* extra_header() const { return data_ + sizeof(Header); } 92 const void* extra_header() const { return data_ + sizeof(Header); }
93 void* mutable_extra_header() { return data_ + sizeof(Header); } 93 void* mutable_extra_header() { return data_ + sizeof(Header); }
94 size_t extra_header_size() const { 94 size_t extra_header_size() const {
95 return header_->num_header_bytes - sizeof(Header); 95 return header_->num_header_bytes - sizeof(Header);
96 } 96 }
97 97
98 void* mutable_payload() { return data_ + header_->num_header_bytes; } 98 void* mutable_payload() { return data_ + header_->num_header_bytes; }
99 const void* payload() const { return data_ + header_->num_header_bytes; } 99 const void* payload() const { return data_ + header_->num_header_bytes; }
100 size_t payload_size() const; 100 size_t payload_size() const;
101 #endif // defined(OS_CHROMEOS) 101 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
102 102
103 size_t num_handles() const { return header_->num_handles; } 103 size_t num_handles() const { return header_->num_handles; }
104 bool has_handles() const { return header_->num_handles > 0; } 104 bool has_handles() const { return header_->num_handles > 0; }
105 PlatformHandle* handles(); 105 PlatformHandle* handles();
106 #if defined(OS_MACOSX) && !defined(OS_IOS) 106 #if defined(OS_MACOSX) && !defined(OS_IOS)
107 bool has_mach_ports() const; 107 bool has_mach_ports() const;
108 #endif 108 #endif
109 109
110 // Note: SetHandles() and TakeHandles() invalidate any previous value of 110 // Note: SetHandles() and TakeHandles() invalidate any previous value of
111 // handles(). 111 // handles().
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 Delegate* delegate_; 232 Delegate* delegate_;
233 const scoped_ptr<ReadBuffer> read_buffer_; 233 const scoped_ptr<ReadBuffer> read_buffer_;
234 234
235 DISALLOW_COPY_AND_ASSIGN(Channel); 235 DISALLOW_COPY_AND_ASSIGN(Channel);
236 }; 236 };
237 237
238 } // namespace edk 238 } // namespace edk
239 } // namespace mojo 239 } // namespace mojo
240 240
241 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ 241 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698