| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 // static | 160 // static |
| 161 bool PathService::GetFromOverrides(int key, FilePath* result) { | 161 bool PathService::GetFromOverrides(int key, FilePath* result) { |
| 162 PathData* path_data = GetPathData(); | 162 PathData* path_data = GetPathData(); |
| 163 base::AutoLock scoped_lock(path_data->lock); | 163 base::AutoLock scoped_lock(path_data->lock); |
| 164 | 164 |
| 165 // check for an overriden version. | 165 // check for an overridden version. |
| 166 PathMap::const_iterator it = path_data->overrides.find(key); | 166 PathMap::const_iterator it = path_data->overrides.find(key); |
| 167 if (it != path_data->overrides.end()) { | 167 if (it != path_data->overrides.end()) { |
| 168 *result = it->second; | 168 *result = it->second; |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // static | 174 // static |
| 175 void PathService::AddToCache(int key, const FilePath& path) { | 175 void PathService::AddToCache(int key, const FilePath& path) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 bool PathService::Override(int key, const FilePath& path) { | 224 bool PathService::Override(int key, const FilePath& path) { |
| 225 PathData* path_data = GetPathData(); | 225 PathData* path_data = GetPathData(); |
| 226 DCHECK(path_data); | 226 DCHECK(path_data); |
| 227 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; | 227 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; |
| 228 | 228 |
| 229 FilePath file_path = path; | 229 FilePath file_path = path; |
| 230 | 230 |
| 231 // Make sure the directory exists. We need to do this before we translate | 231 // Make sure the directory exists. We need to do this before we translate |
| 232 // this to the absolute path because on POSIX, AbsolutePath fails if called | 232 // this to the absolute path because on POSIX, AbsolutePath fails if called |
| 233 // on a non-existant path. | 233 // on a non-existent path. |
| 234 if (!file_util::PathExists(file_path) && | 234 if (!file_util::PathExists(file_path) && |
| 235 !file_util::CreateDirectory(file_path)) | 235 !file_util::CreateDirectory(file_path)) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| 238 // We need to have an absolute path, as extensions and plugins don't like | 238 // We need to have an absolute path, as extensions and plugins don't like |
| 239 // relative paths, and will glady crash the browser in CHECK()s if they get a | 239 // relative paths, and will gladly crash the browser in CHECK()s if they get a |
| 240 // relative path. | 240 // relative path. |
| 241 if (!file_util::AbsolutePath(&file_path)) | 241 if (!file_util::AbsolutePath(&file_path)) |
| 242 return false; | 242 return false; |
| 243 | 243 |
| 244 base::AutoLock scoped_lock(path_data->lock); | 244 base::AutoLock scoped_lock(path_data->lock); |
| 245 | 245 |
| 246 // Clear the cache now. Some of its entries could have depended | 246 // Clear the cache now. Some of its entries could have depended |
| 247 // on the value we are overriding, and are now out of sync with reality. | 247 // on the value we are overriding, and are now out of sync with reality. |
| 248 path_data->cache.clear(); | 248 path_data->cache.clear(); |
| 249 | 249 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 275 p = new Provider; | 275 p = new Provider; |
| 276 p->is_static = false; | 276 p->is_static = false; |
| 277 p->func = func; | 277 p->func = func; |
| 278 p->next = path_data->providers; | 278 p->next = path_data->providers; |
| 279 #ifndef NDEBUG | 279 #ifndef NDEBUG |
| 280 p->key_start = key_start; | 280 p->key_start = key_start; |
| 281 p->key_end = key_end; | 281 p->key_end = key_end; |
| 282 #endif | 282 #endif |
| 283 path_data->providers = p; | 283 path_data->providers = p; |
| 284 } | 284 } |
| OLD | NEW |