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

Unified Diff: chrome/browser/component_updater/supervised_user_whitelist_installer.cc

Issue 1443033004: Supervised User whitelists: update to json format v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove l10n Created 5 years, 1 month 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/component_updater/supervised_user_whitelist_installer.cc
diff --git a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc b/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
index a266eecc310c72e0440bb0d889101a9803ba5a1c..5e82e8c666dfd0b162a1cf2aa1bee532d8f545df 100644
--- a/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
+++ b/chrome/browser/component_updater/supervised_user_whitelist_installer.cc
@@ -40,20 +40,33 @@ namespace {
const char kSanitizedWhitelistExtension[] = ".json";
-const char kWhitelist[] = "whitelist";
-const char kFile[] = "file";
+const char kWhitelistedContent[] = "whitelisted_content";
+const char kSites[] = "sites";
const char kClients[] = "clients";
const char kName[] = "name";
+// These are copies of extensions::manifest_keys::kName and kShortName. They
+// are duplicated here because we mustn't depend on code from extensions/
+// (since it's not built on Android).
+const char kExtensionName[] = "name";
+const char kExtensionShortName[] = "short_name";
+
+base::string16 GetWhitelistTitle(const base::DictionaryValue& manifest) {
+ base::string16 title;
+ if (!manifest.GetString(kExtensionShortName, &title))
+ manifest.GetString(kExtensionName, &title);
+ return title;
+}
+
base::FilePath GetRawWhitelistPath(const base::DictionaryValue& manifest,
const base::FilePath& install_dir) {
const base::DictionaryValue* whitelist_dict = nullptr;
- if (!manifest.GetDictionary(kWhitelist, &whitelist_dict))
+ if (!manifest.GetDictionary(kWhitelistedContent, &whitelist_dict))
return base::FilePath();
base::FilePath::StringType whitelist_file;
- if (!whitelist_dict->GetString(kFile, &whitelist_file))
+ if (!whitelist_dict->GetString(kSites, &whitelist_file))
return base::FilePath();
return install_dir.Append(whitelist_file);
@@ -187,10 +200,13 @@ void RemoveUnregisteredWhitelistsOnTaskRunner(
class SupervisedUserWhitelistComponentInstallerTraits
: public ComponentInstallerTraits {
public:
+ using RawWhitelistReadyCallback =
+ base::Callback<void(const base::string16&, const base::FilePath&)>;
+
SupervisedUserWhitelistComponentInstallerTraits(
const std::string& crx_id,
const std::string& name,
- const base::Callback<void(const base::FilePath&)>& callback)
+ const RawWhitelistReadyCallback& callback)
: crx_id_(crx_id), name_(name), callback_(callback) {}
~SupervisedUserWhitelistComponentInstallerTraits() override {}
@@ -210,7 +226,7 @@ class SupervisedUserWhitelistComponentInstallerTraits
std::string crx_id_;
std::string name_;
- base::Callback<void(const base::FilePath&)> callback_;
+ RawWhitelistReadyCallback callback_;
DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistComponentInstallerTraits);
};
@@ -238,7 +254,11 @@ void SupervisedUserWhitelistComponentInstallerTraits::ComponentReady(
const base::Version& version,
const base::FilePath& install_dir,
scoped_ptr<base::DictionaryValue> manifest) {
- callback_.Run(GetRawWhitelistPath(*manifest, install_dir));
+ // TODO(treib): Before getting the title, we should localize the manifest
+ // using extension_l10n_util::LocalizeExtension, but that doesn't exist on
+ // Android. crbug.com/558387
+ callback_.Run(GetWhitelistTitle(*manifest),
+ GetRawWhitelistPath(*manifest, install_dir));
}
base::FilePath
@@ -276,8 +296,10 @@ class SupervisedUserWhitelistInstallerImpl
const std::string& crx_id);
void OnRawWhitelistReady(const std::string& crx_id,
+ const base::string16& title,
const base::FilePath& whitelist_path);
- void OnSanitizedWhitelistReady(const std::string& crx_id);
+ void OnSanitizedWhitelistReady(const std::string& crx_id,
+ const base::string16& title);
// SupervisedUserWhitelistInstaller overrides:
void RegisterComponents() override;
@@ -369,6 +391,7 @@ bool SupervisedUserWhitelistInstallerImpl::UnregisterWhitelistInternal(
void SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady(
const std::string& crx_id,
+ const base::string16& title,
const base::FilePath& whitelist_path) {
cus_->GetSequencedTaskRunner()->PostTask(
FROM_HERE,
@@ -377,13 +400,14 @@ void SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady(
base::ThreadTaskRunnerHandle::Get(),
base::Bind(
&SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady,
- weak_ptr_factory_.GetWeakPtr(), crx_id)));
+ weak_ptr_factory_.GetWeakPtr(), crx_id, title)));
}
void SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady(
- const std::string& crx_id) {
+ const std::string& crx_id,
+ const base::string16& title) {
for (const WhitelistReadyCallback& callback : callbacks_)
- callback.Run(crx_id, GetSanitizedWhitelistPath(crx_id));
+ callback.Run(crx_id, title, GetSanitizedWhitelistPath(crx_id));
}
void SupervisedUserWhitelistInstallerImpl::RegisterComponents() {

Powered by Google App Engine
This is Rietveld 408576698