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

Side by Side Diff: mojo/public/cpp/bindings/message.h

Issue 399313007: Mojo: Convert assert()s under mojo/public/cpp/bindings/... to MOJO_DCHECK()s. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
7 7
8 #include <assert.h>
9
10 #include <vector> 8 #include <vector>
11 9
12 #include "mojo/public/cpp/bindings/lib/message_internal.h" 10 #include "mojo/public/cpp/bindings/lib/message_internal.h"
11 #include "mojo/public/cpp/environment/logging.h"
13 12
14 namespace mojo { 13 namespace mojo {
15 14
16 // Message is a holder for the data and handles to be sent over a MessagePipe. 15 // Message is a holder for the data and handles to be sent over a MessagePipe.
17 // Message owns its data and handles, but a consumer of Message is free to 16 // Message owns its data and handles, but a consumer of Message is free to
18 // mutate the data and handles. The message's data is comprised of a header 17 // mutate the data and handles. The message's data is comprised of a header
19 // followed by payload. 18 // followed by payload.
20 class Message { 19 class Message {
21 public: 20 public:
22 Message(); 21 Message();
(...skipping 16 matching lines...) Expand all
39 38
40 // Access the header. 39 // Access the header.
41 const internal::MessageHeader* header() const { return &data_->header; } 40 const internal::MessageHeader* header() const { return &data_->header; }
42 41
43 uint32_t name() const { return data_->header.name; } 42 uint32_t name() const { return data_->header.name; }
44 bool has_flag(uint32_t flag) const { return !!(data_->header.flags & flag); } 43 bool has_flag(uint32_t flag) const { return !!(data_->header.flags & flag); }
45 44
46 // Access the request_id field (if present). 45 // Access the request_id field (if present).
47 bool has_request_id() const { return data_->header.num_fields >= 3; } 46 bool has_request_id() const { return data_->header.num_fields >= 3; }
48 uint64_t request_id() const { 47 uint64_t request_id() const {
49 assert(has_request_id()); 48 MOJO_DCHECK(has_request_id());
50 return static_cast<const internal::MessageHeaderWithRequestID*>( 49 return static_cast<const internal::MessageHeaderWithRequestID*>(
51 &data_->header)->request_id; 50 &data_->header)->request_id;
52 } 51 }
53 void set_request_id(uint64_t request_id) { 52 void set_request_id(uint64_t request_id) {
54 assert(has_request_id()); 53 MOJO_DCHECK(has_request_id());
55 static_cast<internal::MessageHeaderWithRequestID*>(&data_->header)-> 54 static_cast<internal::MessageHeaderWithRequestID*>(&data_->header)->
56 request_id = request_id; 55 request_id = request_id;
57 } 56 }
58 57
59 // Access the payload. 58 // Access the payload.
60 const uint8_t* payload() const { 59 const uint8_t* payload() const {
61 return reinterpret_cast<const uint8_t*>(data_) + data_->header.num_bytes; 60 return reinterpret_cast<const uint8_t*>(data_) + data_->header.num_bytes;
62 } 61 }
63 uint8_t* mutable_payload() { 62 uint8_t* mutable_payload() {
64 return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes; 63 return reinterpret_cast<uint8_t*>(data_) + data_->header.num_bytes;
65 } 64 }
66 uint32_t payload_num_bytes() const { 65 uint32_t payload_num_bytes() const {
67 assert(data_num_bytes_ >= data_->header.num_bytes); 66 MOJO_DCHECK(data_num_bytes_ >= data_->header.num_bytes);
68 return data_num_bytes_ - data_->header.num_bytes; 67 return data_num_bytes_ - data_->header.num_bytes;
69 } 68 }
70 69
71 // Access the handles. 70 // Access the handles.
72 const std::vector<Handle>* handles() const { return &handles_; } 71 const std::vector<Handle>* handles() const { return &handles_; }
73 std::vector<Handle>* mutable_handles() { return &handles_; } 72 std::vector<Handle>* mutable_handles() { return &handles_; }
74 73
75 private: 74 private:
76 uint32_t data_num_bytes_; 75 uint32_t data_num_bytes_;
77 internal::MessageData* data_; // Heap-allocated using malloc. 76 internal::MessageData* data_; // Heap-allocated using malloc.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // otherwise returns an error code if something went wrong. 113 // otherwise returns an error code if something went wrong.
115 // 114 //
116 // NOTE: The message hasn't been validated and may be malformed! 115 // NOTE: The message hasn't been validated and may be malformed!
117 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle, 116 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle,
118 MessageReceiver* receiver, 117 MessageReceiver* receiver,
119 bool* receiver_result); 118 bool* receiver_result);
120 119
121 } // namespace mojo 120 } // namespace mojo
122 121
123 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ 122 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698