1// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "components/policy/core/common/cloud/external_policy_data_updater.h" 14#include "components/policy/core/common/policy_namespace.h" 15#include "components/policy/policy_export.h" 16 17namespace base { 18class SequencedTaskRunner; 19} 20 21namespace enterprise_management { 22class PolicyFetchResponse; 23} 24 25namespace policy { 26 27class ComponentCloudPolicyStore; 28class ExternalPolicyDataFetcher; 29 30// This class downloads external policy data, given PolicyFetchResponses. 31// It validates the PolicyFetchResponse and its corresponding data, and caches 32// them in a ComponentCloudPolicyStore. It also enforces size limits on what's 33// cached. 34// It retries to download the policy data periodically when a download fails. 35class POLICY_EXPORT ComponentCloudPolicyUpdater { 36 public: 37 // This class runs on the background thread represented by |task_runner|, 38 // which must support file I/O. All network I/O is delegated to the 39 // |external_policy_data_fetcher|. 40 ComponentCloudPolicyUpdater( 41 scoped_refptr<base::SequencedTaskRunner> task_runner, 42 scoped_ptr<ExternalPolicyDataFetcher> external_policy_data_fetcher, 43 ComponentCloudPolicyStore* store); 44 ~ComponentCloudPolicyUpdater(); 45 46 // |response| is the latest policy information fetched for some component. 47 // This method schedules the download of the policy data, if |response| is 48 // validated. If the downloaded data also passes validation then that data 49 // will be passed to the |store_|. 50 void UpdateExternalPolicy( 51 scoped_ptr<enterprise_management::PolicyFetchResponse> response); 52 53 // Cancels any pending operations for the given namespace. 54 void CancelUpdate(const PolicyNamespace& ns); 55 56 private: 57 std::string NamespaceToKey(const PolicyNamespace& ns); 58 59 ComponentCloudPolicyStore* store_; 60 ExternalPolicyDataUpdater external_policy_data_updater_; 61 62 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyUpdater); 63}; 64 65} // namespace policy 66 67#endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_COMPONENT_CLOUD_POLICY_UPDATER_H_ 68