| 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> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/lazy_instance.h" | |
| 17 #include "base/logging.h" | 16 #include "base/logging.h" |
| 18 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 | 21 |
| 23 bool PathProvider(int key, FilePath* result); | 22 bool PathProvider(int key, FilePath* result); |
| 24 | 23 |
| 25 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 26 bool PathProviderWin(int key, FilePath* result); | 25 bool PathProviderWin(int key, FilePath* result); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 #elif defined(OS_MACOSX) | 121 #elif defined(OS_MACOSX) |
| 123 providers = &base_provider_mac; | 122 providers = &base_provider_mac; |
| 124 #elif defined(OS_ANDROID) | 123 #elif defined(OS_ANDROID) |
| 125 providers = &base_provider_android; | 124 providers = &base_provider_android; |
| 126 #elif defined(OS_POSIX) | 125 #elif defined(OS_POSIX) |
| 127 providers = &base_provider_posix; | 126 providers = &base_provider_posix; |
| 128 #endif | 127 #endif |
| 129 } | 128 } |
| 130 }; | 129 }; |
| 131 | 130 |
| 132 static LazyInstance<PathData>::Leaky g_path_data = LAZY_INSTANCE_INITIALIZER; | |
| 133 | |
| 134 static PathData* GetPathData() { | 131 static PathData* GetPathData() { |
| 135 return g_path_data.Pointer(); | 132 static auto path_data = new PathData(); |
| 133 return path_data; |
| 136 } | 134 } |
| 137 | 135 |
| 138 // Tries to find |key| in the cache. |path_data| should be locked by the caller! | 136 // Tries to find |key| in the cache. |path_data| should be locked by the caller! |
| 139 bool LockedGetFromCache(int key, const PathData* path_data, FilePath* result) { | 137 bool LockedGetFromCache(int key, const PathData* path_data, FilePath* result) { |
| 140 if (path_data->cache_disabled) | 138 if (path_data->cache_disabled) |
| 141 return false; | 139 return false; |
| 142 // check for a cached version | 140 // check for a cached version |
| 143 PathMap::const_iterator it = path_data->cache.find(key); | 141 PathMap::const_iterator it = path_data->cache.find(key); |
| 144 if (it != path_data->cache.end()) { | 142 if (it != path_data->cache.end()) { |
| 145 *result = it->second; | 143 *result = it->second; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 void PathService::DisableCache() { | 320 void PathService::DisableCache() { |
| 323 PathData* path_data = GetPathData(); | 321 PathData* path_data = GetPathData(); |
| 324 DCHECK(path_data); | 322 DCHECK(path_data); |
| 325 | 323 |
| 326 AutoLock scoped_lock(path_data->lock); | 324 AutoLock scoped_lock(path_data->lock); |
| 327 path_data->cache.clear(); | 325 path_data->cache.clear(); |
| 328 path_data->cache_disabled = true; | 326 path_data->cache_disabled = true; |
| 329 } | 327 } |
| 330 | 328 |
| 331 } // namespace base | 329 } // namespace base |
| OLD | NEW |