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.
5 #include "base/posix/global_descriptors.h"
10 #include "base/logging.h"
15 GlobalDescriptors* GlobalDescriptors::GetInstance() {
16 typedef Singleton<base::GlobalDescriptors,
17 LeakySingletonTraits<base::GlobalDescriptors> >
18 GlobalDescriptorsSingleton;
19 return GlobalDescriptorsSingleton::get();
22 int GlobalDescriptors::Get(Key key) const {
23 const int ret = MaybeGet(key);
26 DLOG(FATAL) << "Unknown global descriptor: " << key;
30 int GlobalDescriptors::MaybeGet(Key key) const {
31 for (Mapping::const_iterator
32 i = descriptors_.begin(); i != descriptors_.end(); ++i) {
40 void GlobalDescriptors::Set(Key key, int fd) {
41 for (Mapping::iterator
42 i = descriptors_.begin(); i != descriptors_.end(); ++i) {
43 if (i->first == key) {
49 descriptors_.push_back(std::make_pair(key, fd));
52 void GlobalDescriptors::Reset(const Mapping& mapping) {
53 descriptors_ = mapping;
56 GlobalDescriptors::GlobalDescriptors() {}
58 GlobalDescriptors::~GlobalDescriptors() {}