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

Unified Diff: components/policy/core/common/cloud/resource_cache.cc

Issue 233423002: Don't upload extension IDs in the cloud policy protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed nits Created 6 years, 8 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
« no previous file with comments | « components/policy/core/common/cloud/component_cloud_policy_service_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/core/common/cloud/resource_cache.cc
diff --git a/components/policy/core/common/cloud/resource_cache.cc b/components/policy/core/common/cloud/resource_cache.cc
index 76221d14ba18438f9b3f694721baaa8da2a93424..49204101dac1f40ad860c61f306e4d953dc865ac 100644
--- a/components/policy/core/common/cloud/resource_cache.cc
+++ b/components/policy/core/common/cloud/resource_cache.cc
@@ -19,25 +19,27 @@ namespace {
// Verifies that |value| is not empty and encodes it into base64url format,
// which is safe to use as a file name on all platforms.
-bool Base64Encode(const std::string& value, std::string* encoded) {
+bool Base64UrlEncode(const std::string& value, std::string* encoded) {
DCHECK(!value.empty());
if (value.empty())
return false;
base::Base64Encode(value, encoded);
base::ReplaceChars(*encoded, "+", "-", encoded);
base::ReplaceChars(*encoded, "/", "_", encoded);
+ // Note: this encoding keeps the padding chars, though the "Baset64 with safe
+ // URL alphabet" encoding trims them. See Base64UrlDecode below.
return true;
}
// Decodes all elements of |input| from base64url format and stores the decoded
// elements in |output|.
-bool Base64Encode(const std::set<std::string>& input,
- std::set<std::string>* output) {
+bool Base64UrlEncode(const std::set<std::string>& input,
+ std::set<std::string>* output) {
output->clear();
for (std::set<std::string>::const_iterator it = input.begin();
it != input.end(); ++it) {
std::string encoded;
- if (!Base64Encode(*it, &encoded)) {
+ if (!Base64UrlEncode(*it, &encoded)) {
output->clear();
return false;
}
@@ -48,7 +50,7 @@ bool Base64Encode(const std::set<std::string>& input,
// Decodes |encoded| from base64url format and verifies that the result is not
// emtpy.
-bool Base64Decode(const std::string& encoded, std::string* value) {
+bool Base64UrlDecode(const std::string& encoded, std::string* value) {
std::string buffer;
base::ReplaceChars(encoded, "-", "+", &buffer);
base::ReplaceChars(buffer, "_", "/", &buffer);
@@ -120,7 +122,7 @@ void ResourceCache::LoadAllSubkeys(
// Only read from |subkey_path| if it is not a symlink and its name is
// a base64-encoded string.
if (!base::IsLink(path) &&
- Base64Decode(encoded_subkey, &subkey) &&
+ Base64UrlDecode(encoded_subkey, &subkey) &&
base::ReadFileToString(path, &data)) {
(*contents)[subkey].swap(data);
}
@@ -159,7 +161,7 @@ void ResourceCache::FilterSubkeys(const std::string& key,
std::string subkey;
// Delete files with invalid names, and files whose subkey doesn't pass the
// filter.
- if (!Base64Decode(subkey_path.BaseName().MaybeAsASCII(), &subkey) ||
+ if (!Base64UrlDecode(subkey_path.BaseName().MaybeAsASCII(), &subkey) ||
test.Run(subkey)) {
base::DeleteFile(subkey_path, true);
}
@@ -174,7 +176,7 @@ void ResourceCache::FilterSubkeys(const std::string& key,
void ResourceCache::PurgeOtherKeys(const std::set<std::string>& keys_to_keep) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
std::set<std::string> encoded_keys_to_keep;
- if (!Base64Encode(keys_to_keep, &encoded_keys_to_keep))
+ if (!Base64UrlEncode(keys_to_keep, &encoded_keys_to_keep))
return;
base::FileEnumerator enumerator(
@@ -196,7 +198,7 @@ void ResourceCache::PurgeOtherSubkeys(
return;
std::set<std::string> encoded_subkeys_to_keep;
- if (!Base64Encode(subkeys_to_keep, &encoded_subkeys_to_keep))
+ if (!Base64UrlEncode(subkeys_to_keep, &encoded_subkeys_to_keep))
return;
base::FileEnumerator enumerator(key_path, false, base::FileEnumerator::FILES);
@@ -216,7 +218,7 @@ bool ResourceCache::VerifyKeyPath(const std::string& key,
bool allow_create,
base::FilePath* path) {
std::string encoded;
- if (!Base64Encode(key, &encoded))
+ if (!Base64UrlEncode(key, &encoded))
return false;
*path = cache_dir_.AppendASCII(encoded);
return allow_create ? base::CreateDirectory(*path) :
@@ -230,7 +232,7 @@ bool ResourceCache::VerifyKeyPathAndGetSubkeyPath(const std::string& key,
base::FilePath key_path;
std::string encoded;
if (!VerifyKeyPath(key, allow_create_key, &key_path) ||
- !Base64Encode(subkey, &encoded)) {
+ !Base64UrlEncode(subkey, &encoded)) {
return false;
}
*path = key_path.AppendASCII(encoded);
« no previous file with comments | « components/policy/core/common/cloud/component_cloud_policy_service_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698