1 // Copyright 2018 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_MACHINE_LEVEL_USER_CLOUD_POLICY_MANAGER_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_MACHINE_LEVEL_USER_CLOUD_POLICY_MANAGER_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "components/policy/core/common/cloud/cloud_policy_manager.h" 12 #include "services/network/public/cpp/network_connection_tracker.h" 13 14 class PrefService; 15 16 namespace policy { 17 18 class MachineLevelUserCloudPolicyStore; 19 20 // Implements a cloud policy manager that initializes the machine level user 21 // cloud policy. 22 class POLICY_EXPORT MachineLevelUserCloudPolicyManager 23 : public CloudPolicyManager { 24 public: 25 MachineLevelUserCloudPolicyManager( 26 std::unique_ptr<MachineLevelUserCloudPolicyStore> store, 27 std::unique_ptr<CloudExternalDataManager> external_data_manager, 28 const base::FilePath& policy_dir, 29 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 30 network::NetworkConnectionTrackerGetter 31 network_connection_tracker_getter); 32 ~MachineLevelUserCloudPolicyManager() override; 33 34 // Initializes the cloud connection. |local_state| must stay valid until this 35 // object is deleted or DisconnectAndRemovePolicy gets called. 36 void Connect(PrefService* local_state, 37 std::unique_ptr<CloudPolicyClient> client); 38 39 // Returns true if the underlying CloudPolicyClient is already registered. 40 bool IsClientRegistered(); 41 42 // Add or remove |observer| to/from the CloudPolicyClient embedded in |core_|. 43 void AddClientObserver(CloudPolicyClient::Observer* observer); 44 void RemoveClientObserver(CloudPolicyClient::Observer* observer); 45 store()46 MachineLevelUserCloudPolicyStore* store() { return store_.get(); } 47 48 // Shuts down the MachineLevelUserCloudPolicyManager (removes and stops 49 // refreshing the cached cloud policy). 50 void DisconnectAndRemovePolicy(); 51 52 // ConfigurationPolicyProvider: 53 void Init(SchemaRegistry* registry) override; 54 void Shutdown() override; 55 56 private: 57 // CloudPolicyStore::Observer: 58 void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) override; 59 60 std::unique_ptr<MachineLevelUserCloudPolicyStore> store_; 61 std::unique_ptr<CloudExternalDataManager> external_data_manager_; 62 63 const base::FilePath policy_dir_; 64 65 DISALLOW_COPY_AND_ASSIGN(MachineLevelUserCloudPolicyManager); 66 }; 67 68 } // namespace policy 69 70 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_MACHINE_LEVEL_USER_CLOUD_POLICY_MANAGER_H_ 71