1// Copyright 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_CLOUD_EXTERNAL_DATA_MANAGER_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_EXTERNAL_DATA_MANAGER_H_ 7 8#include <map> 9#include <string> 10 11#include "base/basictypes.h" 12#include "base/memory/ref_counted.h" 13#include "base/memory/weak_ptr.h" 14#include "components/policy/core/common/external_data_manager.h" 15#include "components/policy/policy_export.h" 16 17namespace net { 18class URLRequestContextGetter; 19} 20 21namespace policy { 22 23class CloudPolicyStore; 24 25// Downloads, verifies, caches and retrieves external data referenced by 26// policies. 27// This a common base class used by cloud policy implementations and mocks. 28class POLICY_EXPORT CloudExternalDataManager : public ExternalDataManager { 29 public: 30 struct POLICY_EXPORT MetadataEntry { 31 MetadataEntry(); 32 MetadataEntry(const std::string& url, const std::string& hash); 33 34 bool operator!=(const MetadataEntry& other) const; 35 36 std::string url; 37 std::string hash; 38 }; 39 // Maps from policy names to the metadata specifying the external data that 40 // each of the policies references. 41 typedef std::map<std::string, MetadataEntry> Metadata; 42 43 CloudExternalDataManager(); 44 virtual ~CloudExternalDataManager(); 45 46 // Sets the source of external data references to |policy_store|. The manager 47 // will start observing |policy_store| so that when external data references 48 // change, obsolete data can be deleted and new data can be downloaded. If the 49 // |policy_store| is destroyed before the manager, the connection must be 50 // severed first by calling SetPolicyStore(NULL). 51 virtual void SetPolicyStore(CloudPolicyStore* policy_store); 52 53 // Called by the |policy_store_| when policy changes. 54 virtual void OnPolicyStoreLoaded() = 0; 55 56 // Allows the manager to download external data by constructing URLFetchers 57 // from |request_context|. 58 virtual void Connect( 59 scoped_refptr<net::URLRequestContextGetter> request_context) = 0; 60 61 // Prevents further external data downloads and aborts any downloads currently 62 // in progress. 63 virtual void Disconnect() = 0; 64 65 protected: 66 CloudPolicyStore* policy_store_; // Not owned. 67 68 base::WeakPtrFactory<CloudExternalDataManager> weak_factory_; 69 70 DISALLOW_COPY_AND_ASSIGN(CloudExternalDataManager); 71}; 72 73} // namespace policy 74 75#endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_EXTERNAL_DATA_MANAGER_H_ 76