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

Side by Side Diff: chrome/common/ipc_message.h

Issue 20275: POSIX: Clean up DescriptorSet (Closed)
Patch Set: ... Created 11 years, 10 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 | « chrome/common/ipc_channel_posix.cc ('k') | chrome/common/ipc_message.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_IPC_MESSAGE_H__ 5 #ifndef CHROME_COMMON_IPC_MESSAGE_H__
6 #define CHROME_COMMON_IPC_MESSAGE_H__ 6 #define CHROME_COMMON_IPC_MESSAGE_H__
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/pickle.h" 11 #include "base/pickle.h"
12 #include "testing/gtest/include/gtest/gtest_prod.h" 12 #include "testing/gtest/include/gtest/gtest_prod.h"
13 13
14 #if defined(OS_WIN) 14 #if defined(OS_WIN)
15 // TODO(port): IPC message logging hasn't been ported to other platforms yet. 15 // TODO(port): IPC message logging hasn't been ported to other platforms yet.
16 #ifndef NDEBUG 16 #ifndef NDEBUG
17 #define IPC_MESSAGE_LOG_ENABLED 17 #define IPC_MESSAGE_LOG_ENABLED
18 #endif 18 #endif
19 #elif defined(OS_POSIX) 19 #elif defined(OS_POSIX)
20 #include "chrome/common/descriptor_set_posix.h" 20 #include "base/ref_counted.h"
21 #endif 21 #endif
22 22
23 namespace base {
24 class FileDescriptor;
25 }
26
27 class DescriptorSet;
28
23 namespace IPC { 29 namespace IPC {
24 30
25 //------------------------------------------------------------------------------ 31 //------------------------------------------------------------------------------
26 32
27 class Channel; 33 class Channel;
28 class Message; 34 class Message;
29 struct LogData; 35 struct LogData;
30 36
31 class Message : public Pickle { 37 class Message : public Pickle {
32 public: 38 public:
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 static void Log(const Message* msg, std::wstring* l) { 161 static void Log(const Message* msg, std::wstring* l) {
156 } 162 }
157 163
158 // Find the end of the message data that starts at range_start. Returns NULL 164 // Find the end of the message data that starts at range_start. Returns NULL
159 // if the entire message is not found in the given data range. 165 // if the entire message is not found in the given data range.
160 static const char* FindNext(const char* range_start, const char* range_end) { 166 static const char* FindNext(const char* range_start, const char* range_end) {
161 return Pickle::FindNext(sizeof(Header), range_start, range_end); 167 return Pickle::FindNext(sizeof(Header), range_start, range_end);
162 } 168 }
163 169
164 #if defined(OS_POSIX) 170 #if defined(OS_POSIX)
165 DescriptorSet* descriptor_set() const { return &descriptor_set_; } 171 // On POSIX, a message supports reading / writing FileDescriptor objects.
172 // This is used to pass a file descriptor to the peer of an IPC channel.
173
174 // Add a descriptor to the end of the set. Returns false iff the set is full.
175 bool WriteFileDescriptor(const base::FileDescriptor& descriptor);
176 // Get a file descriptor from the message. Returns false on error.
177 // iter: a Pickle iterator to the current location in the message.
178 bool ReadFileDescriptor(void** iter, base::FileDescriptor* descriptor) const;
166 #endif 179 #endif
167 180
168 #ifdef IPC_MESSAGE_LOG_ENABLED 181 #ifdef IPC_MESSAGE_LOG_ENABLED
169 // Adds the outgoing time from Time::Now() at the end of the message and sets 182 // Adds the outgoing time from Time::Now() at the end of the message and sets
170 // a bit to indicate that it's been added. 183 // a bit to indicate that it's been added.
171 void set_sent_time(int64 time); 184 void set_sent_time(int64 time);
172 int64 sent_time() const; 185 int64 sent_time() const;
173 186
174 void set_received_time(int64 time) const; 187 void set_received_time(int64 time) const;
175 int64 received_time() const { return received_time_; } 188 int64 received_time() const { return received_time_; }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return headerT<Header>(); 233 return headerT<Header>();
221 } 234 }
222 const Header* header() const { 235 const Header* header() const {
223 return headerT<Header>(); 236 return headerT<Header>();
224 } 237 }
225 238
226 void InitLoggingVariables(); 239 void InitLoggingVariables();
227 240
228 #if defined(OS_POSIX) 241 #if defined(OS_POSIX)
229 // The set of file descriptors associated with this message. 242 // The set of file descriptors associated with this message.
230 mutable DescriptorSet descriptor_set_; 243 scoped_refptr<DescriptorSet> descriptor_set_;
244
245 // Ensure that a DescriptorSet is allocated
246 void EnsureDescriptorSet();
247
248 DescriptorSet* descriptor_set() {
249 EnsureDescriptorSet();
250 return descriptor_set_.get();
251 }
252 const DescriptorSet* descriptor_set() const {
253 return descriptor_set_.get();
254 }
231 #endif 255 #endif
232 256
233 #ifdef IPC_MESSAGE_LOG_ENABLED 257 #ifdef IPC_MESSAGE_LOG_ENABLED
234 // Used for logging. 258 // Used for logging.
235 mutable int64 received_time_; 259 mutable int64 received_time_;
236 mutable std::wstring output_params_; 260 mutable std::wstring output_params_;
237 mutable LogData* log_data_; 261 mutable LogData* log_data_;
238 mutable bool dont_log_; 262 mutable bool dont_log_;
239 #endif 263 #endif
240 }; 264 };
241 265
242 //------------------------------------------------------------------------------ 266 //------------------------------------------------------------------------------
243 267
244 } // namespace IPC 268 } // namespace IPC
245 269
246 enum SpecialRoutingIDs { 270 enum SpecialRoutingIDs {
247 // indicates that we don't have a routing ID yet. 271 // indicates that we don't have a routing ID yet.
248 MSG_ROUTING_NONE = -2, 272 MSG_ROUTING_NONE = -2,
249 273
250 // indicates a general message not sent to a particular tab. 274 // indicates a general message not sent to a particular tab.
251 MSG_ROUTING_CONTROL = kint32max, 275 MSG_ROUTING_CONTROL = kint32max,
252 }; 276 };
253 277
254 #define IPC_REPLY_ID 0xFFF0 // Special message id for replies 278 #define IPC_REPLY_ID 0xFFF0 // Special message id for replies
255 #define IPC_LOGGING_ID 0xFFF1 // Special message id for logging 279 #define IPC_LOGGING_ID 0xFFF1 // Special message id for logging
256 280
257 #endif // CHROME_COMMON_IPC_MESSAGE_H__ 281 #endif // CHROME_COMMON_IPC_MESSAGE_H__
258 282
OLDNEW
« no previous file with comments | « chrome/common/ipc_channel_posix.cc ('k') | chrome/common/ipc_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698