OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/public/cpp/bindings/message.h" | 5 #include "mojo/public/cpp/bindings/message.h" |
6 | 6 |
7 #include <assert.h> | |
8 #include <stdlib.h> | 7 #include <stdlib.h> |
9 | 8 |
10 #include <algorithm> | 9 #include <algorithm> |
11 | 10 |
| 11 #include "mojo/public/cpp/environment/logging.h" |
| 12 |
12 namespace mojo { | 13 namespace mojo { |
13 | 14 |
14 Message::Message() | 15 Message::Message() |
15 : data_num_bytes_(0), | 16 : data_num_bytes_(0), |
16 data_(NULL) { | 17 data_(NULL) { |
17 } | 18 } |
18 | 19 |
19 Message::~Message() { | 20 Message::~Message() { |
20 free(data_); | 21 free(data_); |
21 | 22 |
22 for (std::vector<Handle>::iterator it = handles_.begin(); | 23 for (std::vector<Handle>::iterator it = handles_.begin(); |
23 it != handles_.end(); ++it) { | 24 it != handles_.end(); ++it) { |
24 if (it->is_valid()) | 25 if (it->is_valid()) |
25 CloseRaw(*it); | 26 CloseRaw(*it); |
26 } | 27 } |
27 } | 28 } |
28 | 29 |
29 void Message::AllocUninitializedData(uint32_t num_bytes) { | 30 void Message::AllocUninitializedData(uint32_t num_bytes) { |
30 assert(!data_); | 31 MOJO_DCHECK(!data_); |
31 data_num_bytes_ = num_bytes; | 32 data_num_bytes_ = num_bytes; |
32 data_ = static_cast<internal::MessageData*>(malloc(num_bytes)); | 33 data_ = static_cast<internal::MessageData*>(malloc(num_bytes)); |
33 } | 34 } |
34 | 35 |
35 void Message::AdoptData(uint32_t num_bytes, internal::MessageData* data) { | 36 void Message::AdoptData(uint32_t num_bytes, internal::MessageData* data) { |
36 assert(!data_); | 37 MOJO_DCHECK(!data_); |
37 data_num_bytes_ = num_bytes; | 38 data_num_bytes_ = num_bytes; |
38 data_ = data; | 39 data_ = data; |
39 } | 40 } |
40 | 41 |
41 void Message::Swap(Message* other) { | 42 void Message::Swap(Message* other) { |
42 std::swap(data_num_bytes_, other->data_num_bytes_); | 43 std::swap(data_num_bytes_, other->data_num_bytes_); |
43 std::swap(data_, other->data_); | 44 std::swap(data_, other->data_); |
44 std::swap(handles_, other->handles_); | 45 std::swap(handles_, other->handles_); |
45 } | 46 } |
46 | 47 |
(...skipping 25 matching lines...) Expand all Loading... |
72 &message.mutable_handles()->front()), | 73 &message.mutable_handles()->front()), |
73 &num_handles, | 74 &num_handles, |
74 MOJO_READ_MESSAGE_FLAG_NONE); | 75 MOJO_READ_MESSAGE_FLAG_NONE); |
75 if (receiver && rv == MOJO_RESULT_OK) | 76 if (receiver && rv == MOJO_RESULT_OK) |
76 *receiver_result = receiver->Accept(&message); | 77 *receiver_result = receiver->Accept(&message); |
77 | 78 |
78 return rv; | 79 return rv; |
79 } | 80 } |
80 | 81 |
81 } // namespace mojo | 82 } // namespace mojo |
OLD | NEW |