OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_channel.h" | 5 #include "ipc/ipc_channel.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 int process_id = -1; | 34 int process_id = -1; |
35 #else | 35 #else |
36 int process_id = base::GetCurrentProcId(); | 36 int process_id = base::GetCurrentProcId(); |
37 #endif | 37 #endif |
38 return base::StringPrintf("%d.%u.%d", | 38 return base::StringPrintf("%d.%u.%d", |
39 process_id, | 39 process_id, |
40 g_last_id.GetNext(), | 40 g_last_id.GetNext(), |
41 base::RandInt(0, std::numeric_limits<int32>::max())); | 41 base::RandInt(0, std::numeric_limits<int32>::max())); |
42 } | 42 } |
43 | 43 |
44 Channel::OutputElement::OutputElement(Message* message) | |
45 : message_(message), buffer_(nullptr), length_(0) {} | |
46 | |
47 Channel::OutputElement::OutputElement(const char* buffer, size_t length) | |
48 : message_(nullptr), buffer_(buffer), length_(length) {} | |
49 | |
50 Channel::OutputElement::~OutputElement() { | |
51 if (message_) | |
Tom Sepez
2015/08/17 18:29:39
no need to test before delete. just delete them.
erikchen
2015/08/18 05:59:46
Done on both counts.
| |
52 delete message_; | |
53 if (buffer_) | |
54 delete buffer_; | |
55 } | |
56 | |
57 size_t Channel::OutputElement::size() { | |
58 if (message_) | |
59 return message_->size(); | |
60 return length_; | |
61 } | |
62 | |
63 const void* Channel::OutputElement::data() { | |
64 if (message_) | |
65 return message_->data(); | |
66 return buffer_; | |
67 } | |
68 | |
44 } // namespace IPC | 69 } // namespace IPC |
OLD | NEW |