| OLD | NEW |
| 1 // Copyright (c) 2011 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 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (path.empty()) | 215 if (path.empty()) |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 AddToCache(key, path); | 218 AddToCache(key, path); |
| 219 | 219 |
| 220 *result = path; | 220 *result = path; |
| 221 return true; | 221 return true; |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool PathService::Override(int key, const FilePath& path) { | 224 bool PathService::Override(int key, const FilePath& path) { |
| 225 // Just call the full function with true for the value of |create|. |
| 226 return OverrideAndCreateIfNeeded(key, path, true); |
| 227 } |
| 228 |
| 229 bool PathService::OverrideAndCreateIfNeeded(int key, |
| 230 const FilePath& path, |
| 231 bool create) { |
| 225 PathData* path_data = GetPathData(); | 232 PathData* path_data = GetPathData(); |
| 226 DCHECK(path_data); | 233 DCHECK(path_data); |
| 227 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; | 234 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; |
| 228 | 235 |
| 229 FilePath file_path = path; | 236 FilePath file_path = path; |
| 230 | 237 |
| 231 // Make sure the directory exists. We need to do this before we translate | 238 // For some locations this will fail if called from inside the sandbox there- |
| 232 // this to the absolute path because on POSIX, AbsolutePath fails if called | 239 // fore we protect this call with a flag. |
| 233 // on a non-existent path. | 240 if (create) { |
| 234 if (!file_util::PathExists(file_path) && | 241 // Make sure the directory exists. We need to do this before we translate |
| 235 !file_util::CreateDirectory(file_path)) | 242 // this to the absolute path because on POSIX, AbsolutePath fails if called |
| 236 return false; | 243 // on a non-existent path. |
| 244 if (!file_util::PathExists(file_path) && |
| 245 !file_util::CreateDirectory(file_path)) |
| 246 return false; |
| 247 } |
| 237 | 248 |
| 238 // We need to have an absolute path, as extensions and plugins don't like | 249 // We need to have an absolute path, as extensions and plugins don't like |
| 239 // relative paths, and will gladly crash the browser in CHECK()s if they get a | 250 // relative paths, and will gladly crash the browser in CHECK()s if they get a |
| 240 // relative path. | 251 // relative path. |
| 241 if (!file_util::AbsolutePath(&file_path)) | 252 if (!file_util::AbsolutePath(&file_path)) |
| 242 return false; | 253 return false; |
| 243 | 254 |
| 244 base::AutoLock scoped_lock(path_data->lock); | 255 base::AutoLock scoped_lock(path_data->lock); |
| 245 | 256 |
| 246 // Clear the cache now. Some of its entries could have depended | 257 // Clear the cache now. Some of its entries could have depended |
| (...skipping 28 matching lines...) Expand all Loading... |
| 275 p = new Provider; | 286 p = new Provider; |
| 276 p->is_static = false; | 287 p->is_static = false; |
| 277 p->func = func; | 288 p->func = func; |
| 278 p->next = path_data->providers; | 289 p->next = path_data->providers; |
| 279 #ifndef NDEBUG | 290 #ifndef NDEBUG |
| 280 p->key_start = key_start; | 291 p->key_start = key_start; |
| 281 p->key_end = key_end; | 292 p->key_end = key_end; |
| 282 #endif | 293 #endif |
| 283 path_data->providers = p; | 294 path_data->providers = p; |
| 284 } | 295 } |
| OLD | NEW |