| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/global_descriptors_posix.h" | 5 #include "base/global_descriptors_posix.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 16 matching lines...) Expand all Loading... |
| 27 return ret; | 27 return ret; |
| 28 } | 28 } |
| 29 | 29 |
| 30 int GlobalDescriptors::MaybeGet(Key key) const { | 30 int GlobalDescriptors::MaybeGet(Key key) const { |
| 31 for (Mapping::const_iterator | 31 for (Mapping::const_iterator |
| 32 i = descriptors_.begin(); i != descriptors_.end(); ++i) { | 32 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
| 33 if (i->first == key) | 33 if (i->first == key) |
| 34 return i->second; | 34 return i->second; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // In order to make unittests pass, we define a default mapping from keys to | 37 return -1; |
| 38 // descriptors by adding a fixed offset: | |
| 39 return kBaseDescriptor + key; | |
| 40 } | 38 } |
| 41 | 39 |
| 42 void GlobalDescriptors::Set(Key key, int fd) { | 40 void GlobalDescriptors::Set(Key key, int fd) { |
| 43 for (Mapping::iterator | 41 for (Mapping::iterator |
| 44 i = descriptors_.begin(); i != descriptors_.end(); ++i) { | 42 i = descriptors_.begin(); i != descriptors_.end(); ++i) { |
| 45 if (i->first == key) { | 43 if (i->first == key) { |
| 46 i->second = fd; | 44 i->second = fd; |
| 47 return; | 45 return; |
| 48 } | 46 } |
| 49 } | 47 } |
| 50 | 48 |
| 51 descriptors_.push_back(std::make_pair(key, fd)); | 49 descriptors_.push_back(std::make_pair(key, fd)); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void GlobalDescriptors::Reset(const Mapping& mapping) { | 52 void GlobalDescriptors::Reset(const Mapping& mapping) { |
| 55 descriptors_ = mapping; | 53 descriptors_ = mapping; |
| 56 } | 54 } |
| 57 | 55 |
| 58 GlobalDescriptors::GlobalDescriptors() {} | 56 GlobalDescriptors::GlobalDescriptors() {} |
| 59 | 57 |
| 60 GlobalDescriptors::~GlobalDescriptors() {} | 58 GlobalDescriptors::~GlobalDescriptors() {} |
| 61 | 59 |
| 62 } // namespace base | 60 } // namespace base |
| OLD | NEW |