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

Side by Side Diff: base/file_descriptor_posix.h

Issue 621613002: Refactoring: Make IPC::Channel::TakeClientFileDescriptor() a ScopedFD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing Mac build Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 BASE_FILE_DESCRIPTOR_POSIX_H_ 5 #ifndef BASE_FILE_DESCRIPTOR_POSIX_H_
6 #define BASE_FILE_DESCRIPTOR_POSIX_H_ 6 #define BASE_FILE_DESCRIPTOR_POSIX_H_
7 7
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/scoped_file.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 // ----------------------------------------------------------------------------- 13 // -----------------------------------------------------------------------------
13 // We introduct a special structure for file descriptors in order that we are 14 // We introduct a special structure for file descriptors in order that we are
14 // able to use template specialisation to special-case their handling. 15 // able to use template specialisation to special-case their handling.
15 // 16 //
16 // WARNING: (Chromium only) There are subtleties to consider if serialising 17 // WARNING: (Chromium only) There are subtleties to consider if serialising
17 // these objects over IPC. See comments in ipc/ipc_message_utils.h 18 // these objects over IPC. See comments in ipc/ipc_message_utils.h
18 // above the template specialisation for this structure. 19 // above the template specialisation for this structure.
19 // ----------------------------------------------------------------------------- 20 // -----------------------------------------------------------------------------
20 struct FileDescriptor { 21 struct FileDescriptor {
21 FileDescriptor() : fd(-1), auto_close(false) {} 22 FileDescriptor() : fd(-1), auto_close(false) {}
22 23
23 FileDescriptor(int ifd, bool iauto_close) : fd(ifd), auto_close(iauto_close) { 24 FileDescriptor(int ifd, bool iauto_close) : fd(ifd), auto_close(iauto_close) {
24 } 25 }
25 26
26 FileDescriptor(File file) : fd(file.TakePlatformFile()), auto_close(true) {} 27 FileDescriptor(File file) : fd(file.TakePlatformFile()), auto_close(true) {}
28 explicit FileDescriptor(ScopedFD fd) : fd(fd.release()), auto_close(true) {}
27 29
28 bool operator==(const FileDescriptor& other) const { 30 bool operator==(const FileDescriptor& other) const {
29 return (fd == other.fd && auto_close == other.auto_close); 31 return (fd == other.fd && auto_close == other.auto_close);
30 } 32 }
31 33
32 bool operator!=(const FileDescriptor& other) const { 34 bool operator!=(const FileDescriptor& other) const {
33 return !operator==(other); 35 return !operator==(other);
34 } 36 }
35 37
36 // A comparison operator so that we can use these as keys in a std::map. 38 // A comparison operator so that we can use these as keys in a std::map.
37 bool operator<(const FileDescriptor& other) const { 39 bool operator<(const FileDescriptor& other) const {
38 return other.fd < fd; 40 return other.fd < fd;
39 } 41 }
40 42
41 int fd; 43 int fd;
42 // If true, this file descriptor should be closed after it has been used. For 44 // If true, this file descriptor should be closed after it has been used. For
43 // example an IPC system might interpret this flag as indicating that the 45 // example an IPC system might interpret this flag as indicating that the
44 // file descriptor it has been given should be closed after use. 46 // file descriptor it has been given should be closed after use.
45 bool auto_close; 47 bool auto_close;
46 }; 48 };
47 49
48 } // namespace base 50 } // namespace base
49 51
50 #endif // BASE_FILE_DESCRIPTOR_POSIX_H_ 52 #endif // BASE_FILE_DESCRIPTOR_POSIX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698