| 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) | 7 #if defined(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> |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 break; | 210 break; |
| 211 DCHECK(path.empty()) << "provider should not have modified path"; | 211 DCHECK(path.empty()) << "provider should not have modified path"; |
| 212 provider = provider->next; | 212 provider = provider->next; |
| 213 } | 213 } |
| 214 | 214 |
| 215 if (path.empty()) | 215 if (path.empty()) |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 if (path.ReferencesParent()) { | 218 if (path.ReferencesParent()) { |
| 219 // Make sure path service never returns a path with ".." in it. | 219 // Make sure path service never returns a path with ".." in it. |
| 220 if (!file_util::AbsolutePath(&path)) { | 220 path = path.AsAbsolute(); |
| 221 if (path.empty()) |
| 221 return false; | 222 return false; |
| 222 } | |
| 223 } | 223 } |
| 224 *result = path; | 224 *result = path; |
| 225 | 225 |
| 226 base::AutoLock scoped_lock(path_data->lock); | 226 base::AutoLock scoped_lock(path_data->lock); |
| 227 if (!path_data->cache_disabled) | 227 if (!path_data->cache_disabled) |
| 228 path_data->cache[key] = path; | 228 path_data->cache[key] = path; |
| 229 | 229 |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 | 232 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 243 PathData* path_data = GetPathData(); | 243 PathData* path_data = GetPathData(); |
| 244 DCHECK(path_data); | 244 DCHECK(path_data); |
| 245 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; | 245 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; |
| 246 | 246 |
| 247 FilePath file_path = path; | 247 FilePath file_path = path; |
| 248 | 248 |
| 249 // For some locations this will fail if called from inside the sandbox there- | 249 // For some locations this will fail if called from inside the sandbox there- |
| 250 // fore we protect this call with a flag. | 250 // fore we protect this call with a flag. |
| 251 if (create) { | 251 if (create) { |
| 252 // Make sure the directory exists. We need to do this before we translate | 252 // Make sure the directory exists. We need to do this before we translate |
| 253 // this to the absolute path because on POSIX, AbsolutePath fails if called | 253 // this to the absolute path because on POSIX, AsAbsolute fails if called |
| 254 // on a non-existent path. | 254 // on a non-existent path. |
| 255 if (!file_util::PathExists(file_path) && | 255 if (!file_util::PathExists(file_path) && |
| 256 !file_util::CreateDirectory(file_path)) | 256 !file_util::CreateDirectory(file_path)) |
| 257 return false; | 257 return false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 // We need to have an absolute path, as extensions and plugins don't like | 260 // We need to have an absolute path. |
| 261 // relative paths, and will gladly crash the browser in CHECK()s if they get a | 261 file_path = file_path.AsAbsolute(); |
| 262 // relative path. | 262 if (file_path.empty()) |
| 263 if (!file_util::AbsolutePath(&file_path)) | |
| 264 return false; | 263 return false; |
| 265 | 264 |
| 266 base::AutoLock scoped_lock(path_data->lock); | 265 base::AutoLock scoped_lock(path_data->lock); |
| 267 | 266 |
| 268 // Clear the cache now. Some of its entries could have depended | 267 // Clear the cache now. Some of its entries could have depended |
| 269 // on the value we are overriding, and are now out of sync with reality. | 268 // on the value we are overriding, and are now out of sync with reality. |
| 270 path_data->cache.clear(); | 269 path_data->cache.clear(); |
| 271 | 270 |
| 272 path_data->overrides[key] = file_path; | 271 path_data->overrides[key] = file_path; |
| 273 | 272 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 326 |
| 328 // static | 327 // static |
| 329 void PathService::DisableCache() { | 328 void PathService::DisableCache() { |
| 330 PathData* path_data = GetPathData(); | 329 PathData* path_data = GetPathData(); |
| 331 DCHECK(path_data); | 330 DCHECK(path_data); |
| 332 | 331 |
| 333 base::AutoLock scoped_lock(path_data->lock); | 332 base::AutoLock scoped_lock(path_data->lock); |
| 334 path_data->cache.clear(); | 333 path_data->cache.clear(); |
| 335 path_data->cache_disabled = true; | 334 path_data->cache_disabled = true; |
| 336 } | 335 } |
| OLD | NEW |