1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ENTERPRISE_BROWSER_CONTROLLER_CHROME_BROWSER_CLOUD_MANAGEMENT_HELPER_H_
#define COMPONENTS_ENTERPRISE_BROWSER_CONTROLLER_CHROME_BROWSER_CLOUD_MANAGEMENT_HELPER_H_
#include <memory>
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/scoped_observation.h"
#include "components/enterprise/browser/controller/browser_dm_token_storage.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_service.h"
class PrefService;
namespace network {
class SharedURLLoaderFactory;
}
namespace policy {
class ClientDataDelegate;
class CloudPolicyClient;
class CloudPolicyClientRegistrationHelper;
class MachineLevelUserCloudPolicyManager;
class DeviceManagementService;
// A helper class that register device with the enrollment token and client id.
class ChromeBrowserCloudManagementRegistrar {
public:
ChromeBrowserCloudManagementRegistrar(
DeviceManagementService* device_management_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
ChromeBrowserCloudManagementRegistrar(
const ChromeBrowserCloudManagementRegistrar&) = delete;
ChromeBrowserCloudManagementRegistrar& operator=(
const ChromeBrowserCloudManagementRegistrar&) = delete;
~ChromeBrowserCloudManagementRegistrar();
// The callback invoked once policy registration is complete. Passed
// |dm_token| and |client_id| parameters are empty if policy registration
// failed.
using CloudManagementRegistrationCallback =
base::OnceCallback<void(const std::string& dm_token,
const std::string& client_id)>;
// Registers a CloudPolicyClient for fetching machine level user policy.
void RegisterForCloudManagementWithEnrollmentToken(
const std::string& enrollment_token,
const std::string& client_id,
const ClientDataDelegate& client_data_delegate,
CloudManagementRegistrationCallback callback);
private:
void CallCloudManagementRegistrationCallback(
std::unique_ptr<CloudPolicyClient> client,
CloudManagementRegistrationCallback callback);
std::unique_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
raw_ptr<DeviceManagementService> device_management_service_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
};
// A helper class that setup registration and fetch policy.
class MachineLevelUserCloudPolicyFetcher : public CloudPolicyService::Observer {
public:
MachineLevelUserCloudPolicyFetcher(
MachineLevelUserCloudPolicyManager* policy_manager,
PrefService* local_state,
DeviceManagementService* device_management_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
MachineLevelUserCloudPolicyFetcher(
const MachineLevelUserCloudPolicyFetcher&) = delete;
MachineLevelUserCloudPolicyFetcher& operator=(
const MachineLevelUserCloudPolicyFetcher&) = delete;
~MachineLevelUserCloudPolicyFetcher() override;
// Initialize the cloud policy client and policy store then fetch
// the policy based on the |dm_token|. It should be called only once.
void SetupRegistrationAndFetchPolicy(const DMToken& dm_token,
const std::string& client_id);
// Add or remove |observer| to/from the CloudPolicyClient embedded in
// |policy_manager_|.
void AddClientObserver(CloudPolicyClient::Observer* observer);
void RemoveClientObserver(CloudPolicyClient::Observer* observer);
// Shuts down |policy_manager_| (removes and stops refreshing the cached cloud
// policy).
void Disconnect();
// CloudPolicyService::Observer:
void OnCloudPolicyServiceInitializationCompleted() override;
private:
void InitializeManager(std::unique_ptr<CloudPolicyClient> client);
// Fetch policy if device is enrolled.
void TryToFetchPolicy();
raw_ptr<MachineLevelUserCloudPolicyManager> policy_manager_;
raw_ptr<PrefService> local_state_;
raw_ptr<DeviceManagementService> device_management_service_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
base::ScopedObservation<CloudPolicyService, CloudPolicyService::Observer>
cloud_policy_service_observation_{this};
};
} // namespace policy
#endif // COMPONENTS_ENTERPRISE_BROWSER_CONTROLLER_CHROME_BROWSER_CLOUD_MANAGEMENT_HELPER_H_
|