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

Side by Side Diff: base/global_descriptors_posix.cc

Issue 5581008: Add a new GetInstance() method for singleton classes, take 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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 | Annotate | Revision Log
OLDNEW
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"
11 11
12 namespace base { 12 namespace base {
13 13
14 GlobalDescriptors::GlobalDescriptors() {} 14 GlobalDescriptors::GlobalDescriptors() {}
15 15
16 GlobalDescriptors::~GlobalDescriptors() {} 16 GlobalDescriptors::~GlobalDescriptors() {}
17 17
18 // static
19 GlobalDescriptors* GlobalDescriptors::GetInstance() {
20 return Singleton<GlobalDescriptors>::get();
21 }
22
23 // static
24 GlobalDescriptors* GlobalDescriptors::GetLeakyInstance() {
25 return Singleton<GlobalDescriptors,
26 LeakySingletonTraits<GlobalDescriptors> >::get();
27 }
28
18 int GlobalDescriptors::MaybeGet(Key key) const { 29 int GlobalDescriptors::MaybeGet(Key key) const {
19 for (Mapping::const_iterator 30 for (Mapping::const_iterator
20 i = descriptors_.begin(); i != descriptors_.end(); ++i) { 31 i = descriptors_.begin(); i != descriptors_.end(); ++i) {
21 if (i->first == key) 32 if (i->first == key)
22 return i->second; 33 return i->second;
23 } 34 }
24 35
25 // In order to make unittests pass, we define a default mapping from keys to 36 // In order to make unittests pass, we define a default mapping from keys to
26 // descriptors by adding a fixed offset: 37 // descriptors by adding a fixed offset:
27 return kBaseDescriptor + key; 38 return kBaseDescriptor + key;
(...skipping 13 matching lines...) Expand all
41 if (i->first == key) { 52 if (i->first == key) {
42 i->second = fd; 53 i->second = fd;
43 return; 54 return;
44 } 55 }
45 } 56 }
46 57
47 descriptors_.push_back(std::make_pair(key, fd)); 58 descriptors_.push_back(std::make_pair(key, fd));
48 } 59 }
49 60
50 } // namespace base 61 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698