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 #ifndef BASE_GLOBAL_DESCRIPTORS_POSIX_H_ | 5 #ifndef BASE_GLOBAL_DESCRIPTORS_POSIX_H_ |
6 #define BASE_GLOBAL_DESCRIPTORS_POSIX_H_ | 6 #define BASE_GLOBAL_DESCRIPTORS_POSIX_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 // It maps from an abstract key to a descriptor. If independent modules each | 34 // It maps from an abstract key to a descriptor. If independent modules each |
35 // need to define keys, then values should be chosen randomly so as not to | 35 // need to define keys, then values should be chosen randomly so as not to |
36 // collide. | 36 // collide. |
37 class GlobalDescriptors { | 37 class GlobalDescriptors { |
38 public: | 38 public: |
39 typedef uint32_t Key; | 39 typedef uint32_t Key; |
40 // Often we want a canonical descriptor for a given Key. In this case, we add | 40 // Often we want a canonical descriptor for a given Key. In this case, we add |
41 // the following constant to the key value: | 41 // the following constant to the key value: |
42 static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken. | 42 static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken. |
43 | 43 |
44 // Returns a pointer to the singleton object constructed with default traits. | |
45 static GlobalDescriptors* GetInstance(); | |
M-A Ruel
2010/12/07 17:32:21
You realize that you're creating two objects here?
Satish
2010/12/07 17:45:27
The leaky instance is created in src/chrome/app/ch
M-A Ruel
2010/12/07 17:49:17
Ok, adding Evan to know if it was intentional.
Evan Martin
2010/12/07 17:55:16
Ugh, no, this was definitely not intentional. :(
| |
46 | |
47 // Returns a pointer to the singleton object constructed with leaky traits, | |
48 // i.e. one which won't be freed on shutdown. | |
49 static GlobalDescriptors* GetLeakyInstance(); | |
50 | |
44 // Get a descriptor given a key. It is a fatal error if the key is not known. | 51 // Get a descriptor given a key. It is a fatal error if the key is not known. |
45 int Get(Key key) const; | 52 int Get(Key key) const; |
46 // Get a descriptor give a key. Returns -1 on error. | 53 // Get a descriptor give a key. Returns -1 on error. |
47 int MaybeGet(Key key) const; | 54 int MaybeGet(Key key) const; |
48 | 55 |
49 typedef std::vector<std::pair<Key, int> > Mapping; | 56 typedef std::vector<std::pair<Key, int> > Mapping; |
50 | 57 |
51 // Set the descriptor for the given key. | 58 // Set the descriptor for the given key. |
52 void Set(Key key, int fd); | 59 void Set(Key key, int fd); |
53 | 60 |
54 void Reset(const Mapping& mapping) { | 61 void Reset(const Mapping& mapping) { |
55 descriptors_ = mapping; | 62 descriptors_ = mapping; |
56 } | 63 } |
57 | 64 |
58 private: | 65 private: |
59 GlobalDescriptors(); | 66 GlobalDescriptors(); |
60 ~GlobalDescriptors(); | 67 ~GlobalDescriptors(); |
61 friend struct DefaultSingletonTraits<GlobalDescriptors>; | 68 friend struct DefaultSingletonTraits<GlobalDescriptors>; |
62 | 69 |
63 Mapping descriptors_; | 70 Mapping descriptors_; |
64 }; | 71 }; |
65 | 72 |
66 } // namespace base | 73 } // namespace base |
67 | 74 |
68 #endif // BASE_GLOBAL_DESCRIPTORS_POSIX_H_ | 75 #endif // BASE_GLOBAL_DESCRIPTORS_POSIX_H_ |
OLD | NEW |