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

Unified Diff: content/browser/file_descriptor_info_impl.cc

Issue 585203002: Turn FileDescriptorInfo a collection class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing 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 | « content/browser/file_descriptor_info_impl.h ('k') | content/browser/file_descriptor_info_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/file_descriptor_info_impl.cc
diff --git a/content/browser/file_descriptor_info_impl.cc b/content/browser/file_descriptor_info_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c1f055bc76db322c496ad01cca6f87989d275a74
--- /dev/null
+++ b/content/browser/file_descriptor_info_impl.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/file_descriptor_info_impl.h"
+
+namespace content {
+
+// static
+scoped_ptr<FileDescriptorInfo> FileDescriptorInfoImpl::Create() {
+ return scoped_ptr<FileDescriptorInfo>(new FileDescriptorInfoImpl());
+}
+
+FileDescriptorInfoImpl::FileDescriptorInfoImpl() {
+}
+
+FileDescriptorInfoImpl::~FileDescriptorInfoImpl() {
+}
+
+void FileDescriptorInfoImpl::Share(int id, base::PlatformFile fd) {
+ AddToMapping(id, fd);
+}
+
+void FileDescriptorInfoImpl::Transfer(int id, base::ScopedFD fd) {
+ AddToMapping(id, fd.get());
+ owned_descriptors_.push_back(new base::ScopedFD(fd.Pass()));
+}
+
+base::PlatformFile FileDescriptorInfoImpl::GetFDAt(size_t i) const {
+ return mapping_[i].first;
+}
+
+int FileDescriptorInfoImpl::GetIDAt(size_t i) const {
+ return mapping_[i].second;
+}
+
+size_t FileDescriptorInfoImpl::GetMappingSize() const {
+ return mapping_.size();
+}
+
+bool FileDescriptorInfoImpl::HasID(int id) const {
+ for (unsigned i = 0; i < mapping_.size(); ++i) {
+ if (mapping_[i].second == id)
+ return true;
+ }
+
+ return false;
+}
+
+void FileDescriptorInfoImpl::AddToMapping(int id, base::PlatformFile fd) {
+ DCHECK(!HasID(id));
+ mapping_.push_back(std::make_pair(fd, id));
+}
+
+const base::FileHandleMappingVector& FileDescriptorInfoImpl::GetMapping()
+ const {
+ return mapping_;
+}
+
+base::FileHandleMappingVector
+FileDescriptorInfoImpl::GetMappingWithIDAdjustment(int delta) const {
+ base::FileHandleMappingVector result = mapping_;
+ // Adding delta to each ID.
+ for (unsigned i = 0; i < mapping_.size(); ++i)
+ result[i].second += delta;
+ return result;
+}
+
+} // namespace content
« no previous file with comments | « content/browser/file_descriptor_info_impl.h ('k') | content/browser/file_descriptor_info_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698