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

Unified Diff: ipc/file_descriptor_set_posix.h

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ipc/file_descriptor_set_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/file_descriptor_set_posix.h
diff --git a/ipc/file_descriptor_set_posix.h b/ipc/file_descriptor_set_posix.h
index b413b4a2212abc214e5b09f4557ac7652ad54c9d..d454962e84fcf14e62f689551f1cbc0125992c3c 100644
--- a/ipc/file_descriptor_set_posix.h
+++ b/ipc/file_descriptor_set_posix.h
@@ -8,8 +8,9 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/file_descriptor_posix.h"
+#include "base/files/file.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_vector.h"
#include "ipc/ipc_export.h"
// -----------------------------------------------------------------------------
@@ -36,10 +37,10 @@ class IPC_EXPORT FileDescriptorSet
// Interfaces for building during message serialisation...
// Add a descriptor to the end of the set. Returns false iff the set is full.
- bool Add(int fd);
+ bool AddToBorrow(base::PlatformFile fd);
// Add a descriptor to the end of the set and automatically close it after
// transmission. Returns false iff the set is full.
- bool AddAndAutoClose(int fd);
+ bool AddToOwn(base::ScopedFD fd);
// ---------------------------------------------------------------------------
@@ -50,15 +51,15 @@ class IPC_EXPORT FileDescriptorSet
// Return the number of descriptors
unsigned size() const { return descriptors_.size(); }
// Return true if no unconsumed descriptors remain
- bool empty() const { return descriptors_.empty(); }
- // Fetch the nth descriptor from the beginning of the set. Code using this
- // /must/ access the descriptors in order, except that it may wrap from the
- // end to index 0 again.
+ bool empty() const { return 0 == size(); }
+ // Take the nth descriptor from the beginning of the set,
+ // transferring the ownership of the descriptor taken. Code using this
+ // /must/ access the descriptors in order, and must do it at most once.
//
// This interface is designed for the deserialising code as it doesn't
// support close flags.
// returns: file descriptor, or -1 on error
- int GetDescriptorAt(unsigned n) const;
+ base::PlatformFile TakeDescriptorAt(unsigned n);
// ---------------------------------------------------------------------------
@@ -69,9 +70,9 @@ class IPC_EXPORT FileDescriptorSet
// Fill an array with file descriptors without 'consuming' them. CommitAll
// must be called after these descriptors have been transmitted.
// buffer: (output) a buffer of, at least, size() integers.
- void GetDescriptors(int* buffer) const;
+ void PeekDescriptors(base::PlatformFile* buffer) const;
// This must be called after transmitting the descriptors returned by
- // GetDescriptors. It marks all the descriptors as consumed and closes those
+ // PeekDescriptors. It marks all the descriptors as consumed and closes those
// which are auto-close.
void CommitAll();
// Returns true if any contained file descriptors appear to be handles to a
@@ -79,7 +80,7 @@ class IPC_EXPORT FileDescriptorSet
bool ContainsDirectoryDescriptor() const;
// Fetch all filedescriptors with the "auto close" property.
// Used instead of CommitAll() when closing must be handled manually.
- void ReleaseFDsToClose(std::vector<int>* fds);
+ void ReleaseFDsToClose(std::vector<base::PlatformFile>* fds);
// ---------------------------------------------------------------------------
@@ -90,7 +91,7 @@ class IPC_EXPORT FileDescriptorSet
// Set the contents of the set from the given buffer. This set must be empty
// before calling. The auto-close flag is set on all the descriptors so that
// unconsumed descriptors are closed on destruction.
- void SetDescriptors(const int* buffer, unsigned count);
+ void AddDescriptorsToOwn(const base::PlatformFile* buffer, unsigned count);
// ---------------------------------------------------------------------------
@@ -103,7 +104,8 @@ class IPC_EXPORT FileDescriptorSet
// these descriptors are sent as control data. After sending, any descriptors
// with a true flag are closed. If this message has been received, then these
// are the descriptors which were received and all close flags are true.
- std::vector<base::FileDescriptor> descriptors_;
+ std::vector<base::PlatformFile> descriptors_;
+ ScopedVector<base::ScopedFD> owned_descriptors_;
// This contains the index of the next descriptor which should be consumed.
// It's used in a couple of ways. Firstly, at destruction we can check that
« no previous file with comments | « no previous file | ipc/file_descriptor_set_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698