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 *region = i->region; |
| 58 fd.reset(i->fd); |
| 59 descriptors_.erase(i); |
| 60 break; |
| 61 } |
| 62 } |
| 63 return fd; |
| 64 } |
| 65 |
50 void GlobalDescriptors::Set(Key key, int fd) { | 66 void GlobalDescriptors::Set(Key key, int fd) { |
51 Set(key, fd, base::MemoryMappedFile::Region::kWholeFile); | 67 Set(key, fd, base::MemoryMappedFile::Region::kWholeFile); |
52 } | 68 } |
53 | 69 |
54 void GlobalDescriptors::Set(Key key, | 70 void GlobalDescriptors::Set(Key key, |
55 int fd, | 71 int fd, |
56 base::MemoryMappedFile::Region region) { | 72 base::MemoryMappedFile::Region region) { |
57 for (auto& i : descriptors_) { | 73 for (auto& i : descriptors_) { |
58 if (i.key == key) { | 74 if (i.key == key) { |
59 i.fd = fd; | 75 i.fd = fd; |
(...skipping 16 matching lines...) Expand all Loading... |
76 | 92 |
77 void GlobalDescriptors::Reset(const Mapping& mapping) { | 93 void GlobalDescriptors::Reset(const Mapping& mapping) { |
78 descriptors_ = mapping; | 94 descriptors_ = mapping; |
79 } | 95 } |
80 | 96 |
81 GlobalDescriptors::GlobalDescriptors() {} | 97 GlobalDescriptors::GlobalDescriptors() {} |
82 | 98 |
83 GlobalDescriptors::~GlobalDescriptors() {} | 99 GlobalDescriptors::~GlobalDescriptors() {} |
84 | 100 |
85 } // namespace base | 101 } // namespace base |
OLD | NEW |