OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/path_service.h" | 5 #include "base/path_service.h" |
6 | 6 |
7 #ifdef OS_WIN | 7 #ifdef OS_WIN |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
11 #endif | 11 #endif |
12 | 12 |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/hash_tables.h" | 15 #include "base/hash_tables.h" |
16 #include "base/lock.h" | 16 #include "base/lock.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/singleton.h" | 18 #include "base/singleton.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 bool PathProvider(int key, FilePath* result); | 22 bool PathProvider(int key, FilePath* result); |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 bool PathProviderWin(int key, FilePath* result); | 24 bool PathProviderWin(int key, FilePath* result); |
25 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
26 bool PathProviderMac(int key, FilePath* result); | 26 bool PathProviderMac(int key, FilePath* result); |
27 #elif defined(OS_LINUX) | 27 #elif defined(OS_POSIX) |
28 bool PathProviderLinux(int key, FilePath* result); | 28 bool PathProviderLinux(int key, FilePath* result); |
29 #endif | 29 #endif |
30 } | 30 } |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 typedef base::hash_map<int, FilePath> PathMap; | 34 typedef base::hash_map<int, FilePath> PathMap; |
35 typedef base::hash_set<int> PathSet; | 35 typedef base::hash_set<int> PathSet; |
36 | 36 |
37 // We keep a linked list of providers. In a debug build we ensure that no two | 37 // We keep a linked list of providers. In a debug build we ensure that no two |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 base::PathProviderMac, | 73 base::PathProviderMac, |
74 &base_provider, | 74 &base_provider, |
75 #ifndef NDEBUG | 75 #ifndef NDEBUG |
76 base::PATH_MAC_START, | 76 base::PATH_MAC_START, |
77 base::PATH_MAC_END, | 77 base::PATH_MAC_END, |
78 #endif | 78 #endif |
79 true | 79 true |
80 }; | 80 }; |
81 #endif | 81 #endif |
82 | 82 |
83 #if defined(OS_LINUX) | 83 #if defined(OS_POSIX) |
84 static Provider base_provider_linux = { | 84 static Provider base_provider_linux = { |
85 base::PathProviderLinux, | 85 base::PathProviderLinux, |
86 &base_provider, | 86 &base_provider, |
87 #ifndef NDEBUG | 87 #ifndef NDEBUG |
88 base::PATH_LINUX_START, | 88 base::PATH_LINUX_START, |
89 base::PATH_LINUX_END, | 89 base::PATH_LINUX_END, |
90 #endif | 90 #endif |
91 true | 91 true |
92 }; | 92 }; |
93 #endif | 93 #endif |
94 | 94 |
95 | 95 |
96 struct PathData { | 96 struct PathData { |
97 Lock lock; | 97 Lock lock; |
98 PathMap cache; // Track mappings from path key to path value. | 98 PathMap cache; // Track mappings from path key to path value. |
99 PathSet overrides; // Track whether a path has been overridden. | 99 PathSet overrides; // Track whether a path has been overridden. |
100 Provider* providers; // Linked list of path service providers. | 100 Provider* providers; // Linked list of path service providers. |
101 | 101 |
102 PathData() { | 102 PathData() { |
103 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
104 providers = &base_provider_win; | 104 providers = &base_provider_win; |
105 #elif defined(OS_MACOSX) | 105 #elif defined(OS_MACOSX) |
106 providers = &base_provider_mac; | 106 providers = &base_provider_mac; |
107 #elif defined(OS_LINUX) | 107 #elif defined(OS_POSIX) |
108 providers = &base_provider_linux; | 108 providers = &base_provider_linux; |
109 #endif | 109 #endif |
110 } | 110 } |
111 | 111 |
112 ~PathData() { | 112 ~PathData() { |
113 Provider* p = providers; | 113 Provider* p = providers; |
114 while (p) { | 114 while (p) { |
115 Provider* next = p->next; | 115 Provider* next = p->next; |
116 if (!p->is_static) | 116 if (!p->is_static) |
117 delete p; | 117 delete p; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 p = new Provider; | 257 p = new Provider; |
258 p->is_static = false; | 258 p->is_static = false; |
259 p->func = func; | 259 p->func = func; |
260 p->next = path_data->providers; | 260 p->next = path_data->providers; |
261 #ifndef NDEBUG | 261 #ifndef NDEBUG |
262 p->key_start = key_start; | 262 p->key_start = key_start; |
263 p->key_end = key_end; | 263 p->key_end = key_end; |
264 #endif | 264 #endif |
265 path_data->providers = p; | 265 path_data->providers = p; |
266 } | 266 } |
OLD | NEW |