OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/posix/global_descriptors.h" | 5 #include "base/posix/global_descriptors.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 int GlobalDescriptors::MaybeGet(Key key) const { | 40 int GlobalDescriptors::MaybeGet(Key key) const { |
41 for (Mapping::const_iterator | 41 for (Mapping::const_iterator |
42 i = descriptors_.begin(); i != descriptors_.end(); ++i) { | 42 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
43 if (i->key == key) | 43 if (i->key == key) |
44 return i->fd; | 44 return i->fd; |
45 } | 45 } |
46 | 46 |
47 return -1; | 47 return -1; |
48 } | 48 } |
49 | 49 |
| 50 base::ScopedFD GlobalDescriptors::TakeFD( |
| 51 Key key, |
| 52 base::MemoryMappedFile::Region* region) { |
| 53 base::ScopedFD fd; |
| 54 for (Mapping::iterator i = descriptors_.begin(); i != descriptors_.end(); |
| 55 ++i) { |
| 56 if (i->key == key) { |
| 57 if (region) |
| 58 *region = i->region; |
| 59 fd.reset(i->fd); |
| 60 descriptors_.erase(i); |
| 61 break; |
| 62 } |
| 63 } |
| 64 return fd; |
| 65 } |
| 66 |
50 void GlobalDescriptors::Set(Key key, int fd) { | 67 void GlobalDescriptors::Set(Key key, int fd) { |
51 Set(key, fd, base::MemoryMappedFile::Region::kWholeFile); | 68 Set(key, fd, base::MemoryMappedFile::Region::kWholeFile); |
52 } | 69 } |
53 | 70 |
54 void GlobalDescriptors::Set(Key key, | 71 void GlobalDescriptors::Set(Key key, |
55 int fd, | 72 int fd, |
56 base::MemoryMappedFile::Region region) { | 73 base::MemoryMappedFile::Region region) { |
57 for (auto& i : descriptors_) { | 74 for (auto& i : descriptors_) { |
58 if (i.key == key) { | 75 if (i.key == key) { |
59 i.fd = fd; | 76 i.fd = fd; |
(...skipping 16 matching lines...) Expand all Loading... |
76 | 93 |
77 void GlobalDescriptors::Reset(const Mapping& mapping) { | 94 void GlobalDescriptors::Reset(const Mapping& mapping) { |
78 descriptors_ = mapping; | 95 descriptors_ = mapping; |
79 } | 96 } |
80 | 97 |
81 GlobalDescriptors::GlobalDescriptors() {} | 98 GlobalDescriptors::GlobalDescriptors() {} |
82 | 99 |
83 GlobalDescriptors::~GlobalDescriptors() {} | 100 GlobalDescriptors::~GlobalDescriptors() {} |
84 | 101 |
85 } // namespace base | 102 } // namespace base |
OLD | NEW |