summaryrefslogtreecommitdiffstats
path: root/content/browser/file_descriptor_info_impl.cc
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2015-02-09 10:53:21 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-09 18:54:01 +0000
commitf7302eb74f6e79d5b4e26ea5e9aa4e4eb81a52f1 (patch)
treef43636f85827ceea972aeb6ecd607f351a68943a /content/browser/file_descriptor_info_impl.cc
parentaba6a96e10ca6593a7f97caf9f8f8bcf2894e0ee (diff)
downloadchromium_src-f7302eb74f6e79d5b4e26ea5e9aa4e4eb81a52f1.zip
chromium_src-f7302eb74f6e79d5b4e26ea5e9aa4e4eb81a52f1.tar.gz
chromium_src-f7302eb74f6e79d5b4e26ea5e9aa4e4eb81a52f1.tar.bz2
Android: Get rid of extra dup()s on launching child processes
This is a regression from [1] which added a dup() call on the renderer launching process. This CL removes these calls by reveiling the subtle ownership of the file descriptors. The original intention here was to completely hide and simplify the notion of the ownership, at the cost of a few dup() calls. However, the crash report on the reported bug indicates that the dup() can fail and it lets the renderer initialization fail, probably due to some per-process limit of the number of opened files. [1] https://codereview.chromium.org/585203002 R=mdempsky@chromium.org, jam@chromium.org BUG=455364 Review URL: https://codereview.chromium.org/909553003 Cr-Commit-Position: refs/heads/master@{#315353}
Diffstat (limited to 'content/browser/file_descriptor_info_impl.cc')
-rw-r--r--content/browser/file_descriptor_info_impl.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/content/browser/file_descriptor_info_impl.cc b/content/browser/file_descriptor_info_impl.cc
index c1f055b..45ce542 100644
--- a/content/browser/file_descriptor_info_impl.cc
+++ b/content/browser/file_descriptor_info_impl.cc
@@ -47,6 +47,27 @@ bool FileDescriptorInfoImpl::HasID(int id) const {
return false;
}
+bool FileDescriptorInfoImpl::OwnsFD(base::PlatformFile file) const {
+ return owned_descriptors_.end() !=
+ std::find_if(
+ owned_descriptors_.begin(), owned_descriptors_.end(),
+ [file](const base::ScopedFD* fd) { return fd->get() == file; });
+}
+
+base::ScopedFD FileDescriptorInfoImpl::ReleaseFD(base::PlatformFile file) {
+ DCHECK(OwnsFD(file));
+
+ base::ScopedFD fd;
+ auto found = std::find_if(
+ owned_descriptors_.begin(), owned_descriptors_.end(),
+ [file](const base::ScopedFD* fd) { return fd->get() == file; });
+
+ (*found)->swap(fd);
+ owned_descriptors_.erase(found);
+
+ return fd.Pass();
+}
+
void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) {
DCHECK(!HasID(id));
mapping_.push_back(std::make_pair(fd, id));