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

Side by Side Diff: ipc/ipc_message.cc

Issue 583473002: IPC: Get rid of FileDescriptor usage from FileDescriptorSet and Message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « ipc/ipc_message.h ('k') | ipc/ipc_message_utils.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 (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_message.h" 5 #include "ipc/ipc_message.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 #if defined(OS_POSIX) 11 #if defined(OS_POSIX)
12 #include "base/file_descriptor_posix.h"
12 #include "ipc/file_descriptor_set_posix.h" 13 #include "ipc/file_descriptor_set_posix.h"
13 #endif 14 #endif
14 15
15 namespace { 16 namespace {
16 17
17 base::StaticAtomicSequenceNumber g_ref_num; 18 base::StaticAtomicSequenceNumber g_ref_num;
18 19
19 // Create a reference number for identifying IPC messages in traces. The return 20 // Create a reference number for identifying IPC messages in traces. The return
20 // values has the reference number stored in the upper 24 bits, leaving the low 21 // values has the reference number stored in the upper 24 bits, leaving the low
21 // 8 bits set to 0 for use as flags. 22 // 8 bits set to 0 for use as flags.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 data -= sizeof(int64); 116 data -= sizeof(int64);
116 return *(reinterpret_cast<const int64*>(data)); 117 return *(reinterpret_cast<const int64*>(data));
117 } 118 }
118 119
119 void Message::set_received_time(int64 time) const { 120 void Message::set_received_time(int64 time) const {
120 received_time_ = time; 121 received_time_ = time;
121 } 122 }
122 #endif 123 #endif
123 124
124 #if defined(OS_POSIX) 125 #if defined(OS_POSIX)
125 bool Message::WriteFileDescriptor(const base::FileDescriptor& descriptor) { 126 bool Message::WriteFile(base::ScopedFD descriptor) {
126 // We write the index of the descriptor so that we don't have to 127 // We write the index of the descriptor so that we don't have to
127 // keep the current descriptor as extra decoding state when deserialising. 128 // keep the current descriptor as extra decoding state when deserialising.
128 WriteInt(file_descriptor_set()->size()); 129 WriteInt(file_descriptor_set()->size());
129 if (descriptor.auto_close) { 130 return file_descriptor_set()->AddToOwn(descriptor.Pass());
130 return file_descriptor_set()->AddAndAutoClose(descriptor.fd);
131 } else {
132 return file_descriptor_set()->Add(descriptor.fd);
133 }
134 } 131 }
135 132
136 bool Message::ReadFileDescriptor(PickleIterator* iter, 133 bool Message::WriteBorrowingFile(const base::PlatformFile& descriptor) {
137 base::FileDescriptor* descriptor) const { 134 // We write the index of the descriptor so that we don't have to
135 // keep the current descriptor as extra decoding state when deserialising.
136 WriteInt(file_descriptor_set()->size());
137 return file_descriptor_set()->AddToBorrow(descriptor);
138 }
139
140 bool Message::ReadFile(PickleIterator* iter, base::ScopedFD* descriptor) const {
138 int descriptor_index; 141 int descriptor_index;
139 if (!ReadInt(iter, &descriptor_index)) 142 if (!ReadInt(iter, &descriptor_index))
140 return false; 143 return false;
141 144
142 FileDescriptorSet* file_descriptor_set = file_descriptor_set_.get(); 145 FileDescriptorSet* file_descriptor_set = file_descriptor_set_.get();
143 if (!file_descriptor_set) 146 if (!file_descriptor_set)
144 return false; 147 return false;
145 148
146 descriptor->fd = file_descriptor_set->GetDescriptorAt(descriptor_index); 149 base::PlatformFile file =
147 descriptor->auto_close = true; 150 file_descriptor_set->TakeDescriptorAt(descriptor_index);
151 if (file < 0)
152 return false;
148 153
149 return descriptor->fd >= 0; 154 descriptor->reset(file);
155 return true;
150 } 156 }
151 157
152 bool Message::HasFileDescriptors() const { 158 bool Message::HasFileDescriptors() const {
153 return file_descriptor_set_.get() && !file_descriptor_set_->empty(); 159 return file_descriptor_set_.get() && !file_descriptor_set_->empty();
154 } 160 }
155 161
156 void Message::EnsureFileDescriptorSet() { 162 void Message::EnsureFileDescriptorSet() {
157 if (file_descriptor_set_.get() == NULL) 163 if (file_descriptor_set_.get() == NULL)
158 file_descriptor_set_ = new FileDescriptorSet; 164 file_descriptor_set_ = new FileDescriptorSet;
159 } 165 }
160 166
161 #endif 167 #endif
162 168
163 } // namespace IPC 169 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message.h ('k') | ipc/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698