summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/path_service.cc38
-rw-r--r--base/path_service.h4
2 files changed, 15 insertions, 27 deletions
diff --git a/base/path_service.cc b/base/path_service.cc
index 7b3b297..e363fe6 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -32,6 +32,7 @@ namespace base {
namespace {
typedef base::hash_map<int, FilePath> PathMap;
+typedef base::hash_set<int> PathSet;
// We keep a linked list of providers. In a debug build we ensure that no two
// providers claim overlapping keys.
@@ -94,8 +95,8 @@ static Provider base_provider_posix = {
struct PathData {
Lock lock;
- PathMap cache; // Cache mappings from path key to path value.
- PathMap overrides; // Track path overrides.
+ PathMap cache; // Track mappings from path key to path value.
+ PathSet overrides; // Track whether a path has been overridden.
Provider* providers; // Linked list of path service providers.
PathData() {
@@ -141,20 +142,6 @@ bool PathService::GetFromCache(int key, FilePath* result) {
}
// static
-bool PathService::GetFromOverrides(int key, FilePath* result) {
- PathData* path_data = GetPathData();
- AutoLock scoped_lock(path_data->lock);
-
- // check for an overriden version.
- PathMap::const_iterator it = path_data->overrides.find(key);
- if (it != path_data->overrides.end()) {
- *result = it->second;
- return true;
- }
- return false;
-}
-
-// static
void PathService::AddToCache(int key, const FilePath& path) {
PathData* path_data = GetPathData();
AutoLock scoped_lock(path_data->lock);
@@ -179,9 +166,6 @@ bool PathService::Get(int key, FilePath* result) {
if (GetFromCache(key, result))
return true;
- if (GetFromOverrides(key, result))
- return true;
-
FilePath path;
// search providers for the requested path
@@ -216,6 +200,14 @@ bool PathService::Get(int key, std::wstring* result) {
}
#endif
+bool PathService::IsOverridden(int key) {
+ PathData* path_data = GetPathData();
+ DCHECK(path_data);
+
+ AutoLock scoped_lock(path_data->lock);
+ return path_data->overrides.find(key) != path_data->overrides.end();
+}
+
bool PathService::Override(int key, const FilePath& path) {
PathData* path_data = GetPathData();
DCHECK(path_data);
@@ -237,14 +229,8 @@ bool PathService::Override(int key, const FilePath& path) {
return false;
AutoLock scoped_lock(path_data->lock);
-
- // Clear the cache now. Some of its entries could have depended
- // on the value we are overriding, and are now out of sync with reality.
- path_data->cache.clear();
-
path_data->cache[key] = file_path;
- path_data->overrides[key] = file_path;
-
+ path_data->overrides.insert(key);
return true;
}
diff --git a/base/path_service.h b/base/path_service.h
index 4d99cdc..2b59247 100644
--- a/base/path_service.h
+++ b/base/path_service.h
@@ -45,6 +45,9 @@ class PathService {
// over the lifetime of the app, so this method should be used with caution.
static bool Override(int key, const FilePath& path);
+ // Return whether a path was overridden.
+ static bool IsOverridden(int key);
+
// To extend the set of supported keys, you can register a path provider,
// which is just a function mirroring PathService::Get. The ProviderFunc
// returns false if it cannot provide a non-empty path for the given key.
@@ -62,7 +65,6 @@ class PathService {
int key_end);
private:
static bool GetFromCache(int key, FilePath* path);
- static bool GetFromOverrides(int key, FilePath* path);
static void AddToCache(int key, const FilePath& path);
};