diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-11 15:38:27 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-11 15:38:27 +0000 |
commit | 6723f835ff0247e5bffad9e92d8d42a8c3ae1b3b (patch) | |
tree | 874b2b79287e69bd58ca6419c764ed26e2573829 /base/path_service.cc | |
parent | abfd15b40f52900239ec1fb443ade9eab11711f6 (diff) | |
download | chromium_src-6723f835ff0247e5bffad9e92d8d42a8c3ae1b3b.zip chromium_src-6723f835ff0247e5bffad9e92d8d42a8c3ae1b3b.tar.gz chromium_src-6723f835ff0247e5bffad9e92d8d42a8c3ae1b3b.tar.bz2 |
recursive_mutex
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/path_service.cc')
-rw-r--r-- | base/path_service.cc | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/base/path_service.cc b/base/path_service.cc index 8205b03..1601513 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -121,6 +121,25 @@ PathData* path_data = new PathData(); } // namespace + +bool PathService::GetFromCache(int key, std::wstring* result) { + AutoLock scoped_lock(path_data->lock); + + // check for a cached version + PathMap::const_iterator it = path_data->cache.find(key); + if (it != path_data->cache.end()) { + *result = it->second; + return true; + } + return false; +} + +void PathService::AddToCache(int key, const std::wstring& path) { + AutoLock scoped_lock(path_data->lock); + // Save the computed path in our cache. + path_data->cache[key] = path; +} + // TODO(brettw): this function does not handle long paths (filename > MAX_PATH) // characters). This isn't supported very well by Windows right now, so it is // moot, but we should keep this in mind for the future. @@ -134,20 +153,14 @@ bool PathService::Get(int key, std::wstring* result) { if (key == base::DIR_CURRENT) return file_util::GetCurrentDirectory(result); - // TODO(darin): it would be nice to avoid holding this lock while calling out - // to the path providers. - AutoLock scoped_lock(path_data->lock); - - // check for a cached version - PathMap::const_iterator it = path_data->cache.find(key); - if (it != path_data->cache.end()) { - *result = it->second; + if (GetFromCache(key, result)) return true; - } - + std::wstring path; // search providers for the requested path + // NOTE: it should be safe to iterate here without the lock + // since RegisterProvider always prepends. Provider* provider = path_data->providers; while (provider) { if (provider->func(key, &path)) @@ -159,9 +172,8 @@ bool PathService::Get(int key, std::wstring* result) { if (path.empty()) return false; - // Save the computed path in our cache. - path_data->cache[key] = path; - + AddToCache(key, path); + result->swap(path); return true; } @@ -190,9 +202,9 @@ bool PathService::Override(int key, const std::wstring& path) { // TODO: refactor all of the path code throughout the project to use a // per-platform path type char file_path_buf[PATH_MAX]; - if (!realpath(WideToNativeMB(path).c_str(), file_path_buf)) + if (!realpath(WideToUTF8(path).c_str(), file_path_buf)) return false; - std::wstring file_path(NativeMBToWide(file_path_buf)); + std::wstring file_path(UTF8ToWide(file_path_buf)); #endif // make sure the directory exists: |