OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 bool PathProvider(int key, FilePath* result); | 21 bool PathProvider(int key, FilePath* result); |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 bool PathProviderWin(int key, FilePath* result); | 23 bool PathProviderWin(int key, FilePath* result); |
24 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
25 bool PathProviderMac(int key, FilePath* result); | 25 bool PathProviderMac(int key, FilePath* result); |
26 #elif defined(OS_ANDROID) | 26 #elif defined(OS_ANDROID) |
27 bool PathProviderAndroid(int key, FilePath* result); | 27 bool PathProviderAndroid(int key, FilePath* result); |
28 #elif defined(OS_POSIX) | 28 #elif defined(OS_POSIX) |
29 // PathProviderPosix is the default path provider on POSIX OSes other than | |
30 // Mac and Android. | |
31 bool PathProviderPosix(int key, FilePath* result); | 29 bool PathProviderPosix(int key, FilePath* result); |
32 #endif | 30 #endif |
33 } | 31 } |
34 | 32 |
35 namespace { | 33 namespace { |
36 | 34 |
37 typedef base::hash_map<int, FilePath> PathMap; | 35 typedef base::hash_map<int, FilePath> PathMap; |
38 | 36 |
39 // 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 |
40 // providers claim overlapping keys. | 38 // providers claim overlapping keys. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #endif | 78 #endif |
81 true | 79 true |
82 }; | 80 }; |
83 #endif | 81 #endif |
84 | 82 |
85 #if defined(OS_ANDROID) | 83 #if defined(OS_ANDROID) |
86 Provider base_provider_android = { | 84 Provider base_provider_android = { |
87 base::PathProviderAndroid, | 85 base::PathProviderAndroid, |
88 &base_provider, | 86 &base_provider, |
89 #ifndef NDEBUG | 87 #ifndef NDEBUG |
90 base::PATH_ANDROID_START, | 88 0, |
91 base::PATH_ANDROID_END, | 89 0, |
92 #endif | 90 #endif |
93 true | 91 true |
94 }; | 92 }; |
95 #endif | 93 #endif |
96 | 94 |
97 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 95 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
98 Provider base_provider_posix = { | 96 Provider base_provider_posix = { |
99 base::PathProviderPosix, | 97 base::PathProviderPosix, |
100 &base_provider, | 98 &base_provider, |
101 #ifndef NDEBUG | 99 #ifndef NDEBUG |
102 base::PATH_POSIX_START, | 100 0, |
103 base::PATH_POSIX_END, | 101 0, |
104 #endif | 102 #endif |
105 true | 103 true |
106 }; | 104 }; |
107 #endif | 105 #endif |
108 | 106 |
109 | 107 |
110 struct PathData { | 108 struct PathData { |
111 base::Lock lock; | 109 base::Lock lock; |
112 PathMap cache; // Cache mappings from path key to path value. | 110 PathMap cache; // Cache mappings from path key to path value. |
113 PathMap overrides; // Track path overrides. | 111 PathMap overrides; // Track path overrides. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 p = new Provider; | 286 p = new Provider; |
289 p->is_static = false; | 287 p->is_static = false; |
290 p->func = func; | 288 p->func = func; |
291 p->next = path_data->providers; | 289 p->next = path_data->providers; |
292 #ifndef NDEBUG | 290 #ifndef NDEBUG |
293 p->key_start = key_start; | 291 p->key_start = key_start; |
294 p->key_end = key_end; | 292 p->key_end = key_end; |
295 #endif | 293 #endif |
296 path_data->providers = p; | 294 path_data->providers = p; |
297 } | 295 } |
OLD | NEW |