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 #if defined(OS_WIN) | |
8 #include <windows.h> | |
9 #include <shellapi.h> | |
10 #include <shlobj.h> | |
11 #endif | |
12 | |
13 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
14 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
16 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 11 #include "base/logging.h" |
18 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
19 | 13 |
20 using base::FilePath; | 14 using base::FilePath; |
21 using base::MakeAbsoluteFilePath; | 15 using base::MakeAbsoluteFilePath; |
22 | 16 |
23 namespace base { | 17 namespace base { |
24 bool PathProvider(int key, FilePath* result); | 18 bool PathProvider(int key, FilePath* result); |
25 #if defined(OS_WIN) | 19 #if defined(OS_MACOSX) |
26 bool PathProviderWin(int key, FilePath* result); | |
27 #elif defined(OS_MACOSX) | |
28 bool PathProviderMac(int key, FilePath* result); | 20 bool PathProviderMac(int key, FilePath* result); |
29 #elif defined(OS_ANDROID) | 21 #elif defined(OS_ANDROID) |
30 bool PathProviderAndroid(int key, FilePath* result); | 22 bool PathProviderAndroid(int key, FilePath* result); |
31 #elif defined(OS_POSIX) | 23 #elif defined(OS_POSIX) |
32 // PathProviderPosix is the default path provider on POSIX OSes other than | 24 // PathProviderPosix is the default path provider on POSIX OSes other than |
33 // Mac and Android. | 25 // Mac and Android. |
34 bool PathProviderPosix(int key, FilePath* result); | 26 bool PathProviderPosix(int key, FilePath* result); |
35 #endif | 27 #endif |
36 } // namespace base | 28 } // namespace base |
37 | 29 |
(...skipping 16 matching lines...) Expand all Loading... |
54 Provider base_provider = { | 46 Provider base_provider = { |
55 base::PathProvider, | 47 base::PathProvider, |
56 NULL, | 48 NULL, |
57 #ifndef NDEBUG | 49 #ifndef NDEBUG |
58 base::PATH_START, | 50 base::PATH_START, |
59 base::PATH_END, | 51 base::PATH_END, |
60 #endif | 52 #endif |
61 true | 53 true |
62 }; | 54 }; |
63 | 55 |
64 #if defined(OS_WIN) | |
65 Provider base_provider_win = { | |
66 base::PathProviderWin, | |
67 &base_provider, | |
68 #ifndef NDEBUG | |
69 base::PATH_WIN_START, | |
70 base::PATH_WIN_END, | |
71 #endif | |
72 true | |
73 }; | |
74 #endif | |
75 | |
76 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
77 Provider base_provider_mac = { | 57 Provider base_provider_mac = { |
78 base::PathProviderMac, | 58 base::PathProviderMac, |
79 &base_provider, | 59 &base_provider, |
80 #ifndef NDEBUG | 60 #ifndef NDEBUG |
81 base::PATH_MAC_START, | 61 base::PATH_MAC_START, |
82 base::PATH_MAC_END, | 62 base::PATH_MAC_END, |
83 #endif | 63 #endif |
84 true | 64 true |
85 }; | 65 }; |
(...skipping 25 matching lines...) Expand all Loading... |
111 | 91 |
112 | 92 |
113 struct PathData { | 93 struct PathData { |
114 base::Lock lock; | 94 base::Lock lock; |
115 PathMap cache; // Cache mappings from path key to path value. | 95 PathMap cache; // Cache mappings from path key to path value. |
116 PathMap overrides; // Track path overrides. | 96 PathMap overrides; // Track path overrides. |
117 Provider* providers; // Linked list of path service providers. | 97 Provider* providers; // Linked list of path service providers. |
118 bool cache_disabled; // Don't use cache if true; | 98 bool cache_disabled; // Don't use cache if true; |
119 | 99 |
120 PathData() : cache_disabled(false) { | 100 PathData() : cache_disabled(false) { |
121 #if defined(OS_WIN) | 101 #if defined(OS_MACOSX) |
122 providers = &base_provider_win; | |
123 #elif defined(OS_MACOSX) | |
124 providers = &base_provider_mac; | 102 providers = &base_provider_mac; |
125 #elif defined(OS_ANDROID) | 103 #elif defined(OS_ANDROID) |
126 providers = &base_provider_android; | 104 providers = &base_provider_android; |
127 #elif defined(OS_POSIX) | 105 #elif defined(OS_POSIX) |
128 providers = &base_provider_posix; | 106 providers = &base_provider_posix; |
129 #endif | 107 #endif |
130 } | 108 } |
131 | 109 |
132 ~PathData() { | 110 ~PathData() { |
133 Provider* p = providers; | 111 Provider* p = providers; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 310 |
333 // static | 311 // static |
334 void PathService::DisableCache() { | 312 void PathService::DisableCache() { |
335 PathData* path_data = GetPathData(); | 313 PathData* path_data = GetPathData(); |
336 DCHECK(path_data); | 314 DCHECK(path_data); |
337 | 315 |
338 base::AutoLock scoped_lock(path_data->lock); | 316 base::AutoLock scoped_lock(path_data->lock); |
339 path_data->cache.clear(); | 317 path_data->cache.clear(); |
340 path_data->cache_disabled = true; | 318 path_data->cache_disabled = true; |
341 } | 319 } |
OLD | NEW |