summaryrefslogtreecommitdiffstats
path: root/base/path_service.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 20:29:17 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 20:29:17 +0000
commitd6b4f43e5ba0048e2d72c2801c694135d32fa7e4 (patch)
tree049adc435c74c0400eae67f22e6e01979e6fcde7 /base/path_service.cc
parentc9af00d21e67b4dee15ec54655d30cb9f9139972 (diff)
downloadchromium_src-d6b4f43e5ba0048e2d72c2801c694135d32fa7e4.zip
chromium_src-d6b4f43e5ba0048e2d72c2801c694135d32fa7e4.tar.gz
chromium_src-d6b4f43e5ba0048e2d72c2801c694135d32fa7e4.tar.bz2
Fix CheckFalseTest.CheckFails on Linux after my change to ui_test.
This makes PathService clear its cache after overriding a path. We have many paths depending on each other, so this is necessary to avoid inconsistencies. TEST=ui_tests in Release mode BUG=49838 Review URL: http://codereview.chromium.org/2805100 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/path_service.cc')
-rw-r--r--base/path_service.cc45
1 files changed, 32 insertions, 13 deletions
diff --git a/base/path_service.cc b/base/path_service.cc
index 57cbc33..ee94c16 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -31,7 +31,6 @@ 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 +93,8 @@ static Provider base_provider_posix = {
struct PathData {
Lock lock;
- PathMap cache; // Track mappings from path key to path value.
- PathSet overrides; // Track whether a path has been overridden.
+ PathMap cache; // Cache mappings from path key to path value.
+ PathMap overrides; // Track path overrides.
Provider* providers; // Linked list of path service providers.
PathData() {
@@ -141,6 +140,20 @@ 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);
@@ -162,8 +175,15 @@ bool PathService::Get(int key, FilePath* result) {
if (key == base::DIR_CURRENT)
return file_util::GetCurrentDirectory(result);
- if (GetFromCache(key, result))
+ if (GetFromCache(key, result)) {
+ LOG(ERROR) << "Key: " << key << " returning " << result->value() << " from cache.";
return true;
+ }
+
+ if (GetFromOverrides(key, result)) {
+ LOG(ERROR) << "Key: " << key << " returning " << result->value() << " from overrides.";
+ return true;
+ }
FilePath path;
@@ -184,6 +204,7 @@ bool PathService::Get(int key, FilePath* result) {
AddToCache(key, path);
*result = path;
+ LOG(ERROR) << "Key: " << key << " returning " << result->value() << ".";
return true;
}
@@ -199,14 +220,6 @@ 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);
@@ -228,8 +241,14 @@ 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.insert(key);
+ path_data->overrides[key] = file_path;
+
return true;
}