Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1863)

Unified Diff: chrome/browser/policy/cloud/resource_cache.cc

Issue 23868021: Prepare ExternalPolicyDataUpdater and ResourceCache for blocking pool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-uploading due to rietveld flake. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud/resource_cache.cc
diff --git a/chrome/browser/policy/cloud/resource_cache.cc b/chrome/browser/policy/cloud/resource_cache.cc
index 8cea6ca48cdda95ac9a88ade5d0f36da77ab4847..b71ff4656e699b738c310061d395f17db97a1972 100644
--- a/chrome/browser/policy/cloud/resource_cache.cc
+++ b/chrome/browser/policy/cloud/resource_cache.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
#include "base/logging.h"
+#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
namespace policy {
@@ -53,21 +54,21 @@ bool Base64Decode(const std::string& encoded, std::string* value) {
} // namespace
-ResourceCache::ResourceCache(const base::FilePath& cache_dir)
- : cache_dir_(cache_dir) {
- // Allow the cache to be created in a different thread than the thread that is
- // going to use it.
- DetachFromThread();
+ResourceCache::ResourceCache(
+ const base::FilePath& cache_dir,
+ scoped_refptr<base::SequencedTaskRunner> task_runner)
+ : cache_dir_(cache_dir),
+ task_runner_(task_runner) {
}
ResourceCache::~ResourceCache() {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
}
bool ResourceCache::Store(const std::string& key,
const std::string& subkey,
const std::string& data) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
base::FilePath subkey_path;
// Delete the file before writing to it. This ensures that the write does not
// follow a symlink planted at |subkey_path|, clobbering a file outside the
@@ -86,7 +87,7 @@ bool ResourceCache::Store(const std::string& key,
bool ResourceCache::Load(const std::string& key,
const std::string& subkey,
std::string* data) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
base::FilePath subkey_path;
// Only read from |subkey_path| if it is not a symlink.
if (!VerifyKeyPathAndGetSubkeyPath(key, false, subkey, &subkey_path) ||
@@ -100,7 +101,7 @@ bool ResourceCache::Load(const std::string& key,
void ResourceCache::LoadAllSubkeys(
const std::string& key,
std::map<std::string, std::string>* contents) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
contents->clear();
base::FilePath key_path;
if (!VerifyKeyPath(key, false, &key_path))
@@ -123,7 +124,7 @@ void ResourceCache::LoadAllSubkeys(
}
void ResourceCache::Delete(const std::string& key, const std::string& subkey) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
base::FilePath subkey_path;
if (VerifyKeyPathAndGetSubkeyPath(key, false, subkey, &subkey_path))
base::DeleteFile(subkey_path, false);
@@ -134,7 +135,7 @@ void ResourceCache::Delete(const std::string& key, const std::string& subkey) {
}
void ResourceCache::PurgeOtherKeys(const std::set<std::string>& keys_to_keep) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
std::set<std::string> encoded_keys_to_keep;
if (!Base64Encode(keys_to_keep, &encoded_keys_to_keep))
return;
@@ -152,7 +153,7 @@ void ResourceCache::PurgeOtherKeys(const std::set<std::string>& keys_to_keep) {
void ResourceCache::PurgeOtherSubkeys(
const std::string& key,
const std::set<std::string>& subkeys_to_keep) {
- DCHECK(CalledOnValidThread());
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
base::FilePath key_path;
if (!VerifyKeyPath(key, false, &key_path))
return;
« no previous file with comments | « chrome/browser/policy/cloud/resource_cache.h ('k') | chrome/browser/policy/cloud/resource_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698