This source file includes following definitions.
- external_policy_data_updater_
- UpdateExternalPolicy
- CancelUpdate
- NamespaceToKey
#include "components/policy/core/common/cloud/component_cloud_policy_updater.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "components/policy/core/common/cloud/component_cloud_policy_store.h"
#include "components/policy/core/common/cloud/external_policy_data_fetcher.h"
#include "policy/proto/chrome_extension_policy.pb.h"
#include "policy/proto/device_management_backend.pb.h"
namespace em = enterprise_management;
namespace policy {
namespace {
const size_t kPolicyProtoMaxSize = 16 * 1024;
const int64 kPolicyDataMaxSize = 5 * 1024 * 1024;
const int64 kMaxParallelPolicyDataFetches = 2;
}
ComponentCloudPolicyUpdater::ComponentCloudPolicyUpdater(
scoped_refptr<base::SequencedTaskRunner> task_runner,
scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher,
ComponentCloudPolicyStore* store)
: store_(store),
external_policy_data_updater_(task_runner,
external_policy_data_fetcher.Pass(),
kMaxParallelPolicyDataFetches) {
}
ComponentCloudPolicyUpdater::~ComponentCloudPolicyUpdater() {
}
void ComponentCloudPolicyUpdater::UpdateExternalPolicy(
scoped_ptr<em::PolicyFetchResponse> response) {
std::string serialized_response;
if (!response->SerializeToString(&serialized_response) ||
serialized_response.size() > kPolicyProtoMaxSize) {
return;
}
PolicyNamespace ns;
em::ExternalPolicyData data;
if (!store_->ValidatePolicy(response.Pass(), &ns, &data)) {
LOG(ERROR) << "Failed to validate component policy fetched from DMServer";
return;
}
const std::string& cached_hash = store_->GetCachedHash(ns);
if (!cached_hash.empty() && data.secure_hash() == cached_hash)
return;
if (data.download_auth_method() != em::ExternalPolicyData::NONE)
return;
const std::string key = NamespaceToKey(ns);
if (data.download_url().empty() || !data.has_secure_hash()) {
external_policy_data_updater_.CancelExternalDataFetch(key);
store_->Delete(ns);
} else {
external_policy_data_updater_.FetchExternalData(
key,
ExternalPolicyDataUpdater::Request(data.download_url(),
data.secure_hash(),
kPolicyDataMaxSize),
base::Bind(&ComponentCloudPolicyStore::Store, base::Unretained(store_),
ns,
serialized_response,
data.secure_hash()));
}
}
void ComponentCloudPolicyUpdater::CancelUpdate(const PolicyNamespace& ns) {
external_policy_data_updater_.CancelExternalDataFetch(NamespaceToKey(ns));
}
std::string ComponentCloudPolicyUpdater::NamespaceToKey(
const PolicyNamespace& ns) {
const std::string domain = base::IntToString(ns.domain);
const std::string size = base::IntToString(domain.size());
return size + ":" + domain + ":" + ns.component_id;
}
}