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

Side by Side Diff: content/public/browser/file_descriptor_info.cc

Issue 585203002: Turn FileDescriptorInfo a collection class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing windows build failure 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/browser/file_descriptor_info.h"
6
7 namespace content {
8
9 FileDescriptorInfo::FileDescriptorInfo() {
10 }
11
12 FileDescriptorInfo::~FileDescriptorInfo() {
13 }
14
15 void FileDescriptorInfo::Share(int id, base::PlatformFile fd) {
16 AddToMapping(id, fd);
17 }
18
19 void FileDescriptorInfo::Transfer(int id, base::ScopedFD fd) {
20 AddToMapping(id, fd.get());
21 owned_descriptors_.push_back(new base::ScopedFD(fd.Pass()));
22 }
23
24 void FileDescriptorInfo::TransferWithoutMapping(base::ScopedFD fd) {
25 owned_descriptors_.push_back(new base::ScopedFD(fd.Pass()));
26 }
27
28 base::PlatformFile FileDescriptorInfo::GetFDAt(size_t i) const {
29 return mapping_[i].first;
30 }
31
32 int FileDescriptorInfo::GetIDAt(size_t i) const {
33 return mapping_[i].second;
34 }
35
36 void FileDescriptorInfo::AddToMapping(int id, base::PlatformFile fd) {
37 DCHECK(mapping_.end() ==
38 std::find(mapping_.begin(), mapping_.end(), std::make_pair(fd, id)));
39 mapping_.push_back(std::make_pair(fd, id));
40 }
41
42 const base::FileHandleMappingVector& FileDescriptorInfo::GetMapping() const {
43 return mapping_;
44 }
45
46 base::FileHandleMappingVector FileDescriptorInfo::GetMappingWithIDAdjustment(
47 int delta) const {
48 base::FileHandleMappingVector result = mapping_;
49 // Adding delta to each ID.
50 for (unsigned i = 0; i < mapping_.size(); ++i)
51 result[i].second += delta;
52 return result;
53 }
54
55 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698