Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_cloud_policy_initializer.h
blob69d1bcebdee189cb25583ad232ab9aed21bc1e2b
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INITIALIZER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INITIALIZER_H_
8 #include <bitset>
9 #include <string>
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
17 #include "components/policy/core/common/cloud/cloud_policy_client.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
19 #include "components/policy/core/common/cloud/cloud_policy_store.h"
21 class PrefService;
23 namespace base {
24 class SequencedTaskRunner;
27 namespace chromeos {
28 class OwnerSettingsServiceChromeOS;
31 namespace policy {
33 class DeviceCloudPolicyManagerChromeOS;
34 class DeviceCloudPolicyStoreChromeOS;
35 class DeviceManagementService;
36 struct EnrollmentConfig;
37 class EnrollmentHandlerChromeOS;
38 class EnrollmentStatus;
39 class EnterpriseInstallAttributes;
41 // This class connects DCPM to the correct device management service, and
42 // handles the enrollment process.
43 class DeviceCloudPolicyInitializer : public CloudPolicyStore::Observer {
44 public:
45 typedef std::bitset<32> AllowedDeviceModes;
46 typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback;
48 // |background_task_runner| is used to execute long-running background tasks
49 // that may involve file I/O.
50 DeviceCloudPolicyInitializer(
51 PrefService* local_state,
52 DeviceManagementService* enterprise_service,
53 DeviceManagementService* consumer_service,
54 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
55 EnterpriseInstallAttributes* install_attributes,
56 ServerBackedStateKeysBroker* state_keys_broker,
57 DeviceCloudPolicyStoreChromeOS* device_store,
58 DeviceCloudPolicyManagerChromeOS* manager);
60 ~DeviceCloudPolicyInitializer() override;
62 virtual void Init();
63 virtual void Shutdown();
65 // Starts enrollment or re-enrollment. Once the enrollment process completes,
66 // |enrollment_callback| is invoked and gets passed the status of the
67 // operation.
68 // |allowed_modes| specifies acceptable DEVICE_MODE_* constants for
69 // enrollment.
70 // |management_mode| should be either MANAGEMENT_MODE_ENTERPRISE or
71 // MANAGEMENT_MODE_CONSUMER.
72 virtual void StartEnrollment(
73 ManagementMode management_mode,
74 DeviceManagementService* device_management_service,
75 chromeos::OwnerSettingsServiceChromeOS* owner_settings_service,
76 const EnrollmentConfig& enrollment_config,
77 const std::string& auth_token,
78 const AllowedDeviceModes& allowed_modes,
79 const EnrollmentCallback& enrollment_callback);
81 // Get the enrollment configuration that has been set up via signals such as
82 // device requisition, OEM manifest, pre-existing installation-time attributes
83 // or server-backed state retrieval. The configuration is stored in |config|,
84 // |config.mode| will be MODE_NONE if there is no prescribed configuration.
85 // |config.management_domain| will contain the domain the device is supposed
86 // to be enrolled to as decided by factors such as forced re-enrollment,
87 // enrollment recovery, or already-present install attributes. Note that
88 // |config.management_domain| may be non-empty even if |config.mode| is
89 // MODE_NONE.
90 EnrollmentConfig GetPrescribedEnrollmentConfig() const;
92 // CloudPolicyStore::Observer:
93 void OnStoreLoaded(CloudPolicyStore* store) override;
94 void OnStoreError(CloudPolicyStore* store) override;
96 private:
97 // Handles completion signaled by |enrollment_handler_|.
98 void EnrollmentCompleted(const EnrollmentCallback& enrollment_callback,
99 EnrollmentStatus status);
101 // Creates a new CloudPolicyClient.
102 scoped_ptr<CloudPolicyClient> CreateClient(
103 DeviceManagementService* device_management_service);
105 void TryToCreateClient();
106 void StartConnection(scoped_ptr<CloudPolicyClient> client);
108 PrefService* local_state_;
109 DeviceManagementService* enterprise_service_;
110 DeviceManagementService* consumer_service_;
111 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
112 EnterpriseInstallAttributes* install_attributes_;
113 ServerBackedStateKeysBroker* state_keys_broker_;
114 DeviceCloudPolicyStoreChromeOS* device_store_;
115 DeviceCloudPolicyManagerChromeOS* manager_;
116 bool is_initialized_;
118 // Non-NULL if there is an enrollment operation pending.
119 scoped_ptr<EnrollmentHandlerChromeOS> enrollment_handler_;
121 ServerBackedStateKeysBroker::Subscription state_keys_update_subscription_;
123 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInitializer);
126 } // namespace policy
128 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INITIALIZER_H_