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, std::wstring* result); | 22 bool PathProvider(int key, FilePath* result); |
23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
24 bool PathProviderWin(int key, std::wstring* result); | 24 bool PathProviderWin(int key, FilePath* result); |
25 #elif defined(OS_MACOSX) | 25 #elif defined(OS_MACOSX) |
26 bool PathProviderMac(int key, std::wstring* result); | 26 bool PathProviderMac(int key, FilePath* result); |
27 #elif defined(OS_LINUX) | 27 #elif defined(OS_LINUX) |
28 bool PathProviderLinux(int key, std::wstring* 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 |
38 // providers claim overlapping keys. | 38 // providers claim overlapping keys. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 DCHECK(result); | 159 DCHECK(result); |
160 DCHECK(key >= base::DIR_CURRENT); | 160 DCHECK(key >= base::DIR_CURRENT); |
161 | 161 |
162 // special case the current directory because it can never be cached | 162 // special case the current directory because it can never be cached |
163 if (key == base::DIR_CURRENT) | 163 if (key == base::DIR_CURRENT) |
164 return file_util::GetCurrentDirectory(result); | 164 return file_util::GetCurrentDirectory(result); |
165 | 165 |
166 if (GetFromCache(key, result)) | 166 if (GetFromCache(key, result)) |
167 return true; | 167 return true; |
168 | 168 |
169 std::wstring path_string; | 169 FilePath path; |
170 | 170 |
171 // search providers for the requested path | 171 // search providers for the requested path |
172 // NOTE: it should be safe to iterate here without the lock | 172 // NOTE: it should be safe to iterate here without the lock |
173 // since RegisterProvider always prepends. | 173 // since RegisterProvider always prepends. |
174 Provider* provider = path_data->providers; | 174 Provider* provider = path_data->providers; |
175 while (provider) { | 175 while (provider) { |
176 if (provider->func(key, &path_string)) | 176 if (provider->func(key, &path)) |
177 break; | 177 break; |
178 DCHECK(path_string.empty()) << "provider should not have modified path"; | 178 DCHECK(path.value().empty()) << "provider should not have modified path"; |
179 provider = provider->next; | 179 provider = provider->next; |
180 } | 180 } |
181 | 181 |
182 if (path_string.empty()) | 182 if (path.value().empty()) |
183 return false; | 183 return false; |
184 | 184 |
185 FilePath path = FilePath::FromWStringHack(path_string); | |
186 AddToCache(key, path); | 185 AddToCache(key, path); |
187 | 186 |
188 *result = path; | 187 *result = path; |
189 return true; | 188 return true; |
190 } | 189 } |
191 | 190 |
192 // static | 191 // static |
193 bool PathService::Get(int key, std::wstring* result) { | 192 bool PathService::Get(int key, std::wstring* result) { |
194 // Deprecated compatibility function. | 193 // Deprecated compatibility function. |
195 FilePath path; | 194 FilePath path; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 p = new Provider; | 253 p = new Provider; |
255 p->is_static = false; | 254 p->is_static = false; |
256 p->func = func; | 255 p->func = func; |
257 p->next = path_data->providers; | 256 p->next = path_data->providers; |
258 #ifndef NDEBUG | 257 #ifndef NDEBUG |
259 p->key_start = key_start; | 258 p->key_start = key_start; |
260 p->key_end = key_end; | 259 p->key_end = key_end; |
261 #endif | 260 #endif |
262 path_data->providers = p; | 261 path_data->providers = p; |
263 } | 262 } |
OLD | NEW |