Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | |
| 6 #define CHROME_BROWSER_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "chrome/browser/policy/cloud_policy_client.h" | |
| 15 #include "chrome/browser/policy/cloud_policy_store.h" | |
| 16 #include "chrome/browser/policy/cloud_policy_validator.h" | |
| 17 #include "chrome/browser/policy/device_cloud_policy_manager_chromeos.h" | |
| 18 | |
| 19 namespace enterprise_management { | |
| 20 class PolicyFetchResponse; | |
| 21 } | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 class EnterpriseInstallAttributes; | |
| 26 | |
| 27 // Implements the logic that establishes enterprise enrollment for Chromium OS | |
| 28 // devices. The process is as follows: | |
| 29 // 1. Given an auth token, register with the policy service. | |
| 30 // 2. Download the initial policy blob from the service. | |
| 31 // 3. Verify the policy blob. Everything up to this point doesn't touch device | |
| 32 // state. | |
| 33 // 4. Establish the device lock in installation-time attributes. | |
| 34 // 5. Store the policy blob. | |
| 35 class EnrollmentHandlerChromeOS : public CloudPolicyClient::Observer, | |
| 36 public CloudPolicyStore::Observer { | |
| 37 public: | |
| 38 typedef DeviceCloudPolicyManagerChromeOS::AllowedDeviceModes | |
| 39 AllowedDeviceModes; | |
| 40 typedef DeviceCloudPolicyManagerChromeOS::EnrollmentCallback | |
| 41 CompletionCallback; | |
|
Joao da Silva
2012/10/23 18:58:50
Why the different names?
Mattias Nissler (ping if slow)
2012/10/24 10:33:18
That's a code evolution artifact :) Fixed.
| |
| 42 | |
| 43 // |store| and |install_attributes| must remain valid for the life time of the | |
| 44 // enrollment handler. |allowed_device_modes| determines what device modes | |
| 45 // are acceptable. If the mode specified by the server is not acceptable, | |
| 46 // enrollment will fail with an EnrollmentStatus indicating | |
| 47 // STATUS_REGISTRATION_BAD_MODE. | |
| 48 EnrollmentHandlerChromeOS(DeviceCloudPolicyStoreChromeOS* store, | |
| 49 EnterpriseInstallAttributes* install_attributes, | |
| 50 scoped_ptr<CloudPolicyClient> client, | |
| 51 const std::string& auth_token, | |
| 52 const AllowedDeviceModes& allowed_device_modes, | |
| 53 const CompletionCallback& completion_callback); | |
| 54 virtual ~EnrollmentHandlerChromeOS(); | |
| 55 | |
| 56 // Starts the enrollment process and reports the result to | |
| 57 // |completion_callback_|. | |
| 58 void StartEnrollment(); | |
| 59 | |
| 60 // Releases the client. | |
| 61 scoped_ptr<CloudPolicyClient> ReleaseClient(); | |
| 62 | |
| 63 // CloudPolicyClient::Observer: | |
| 64 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | |
| 65 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | |
| 66 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | |
| 67 | |
| 68 // CloudPolicyStore::Observer: | |
| 69 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | |
| 70 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | |
| 71 | |
| 72 private: | |
| 73 // Indicates what step of the process is currently pending. These steps need | |
| 74 // to be listed in the order they are traversed in. | |
| 75 enum EnrollmentStep { | |
| 76 STEP_PENDING, // Not started yet. | |
| 77 STEP_REGISTRATION, // Currently registering the client. | |
| 78 STEP_POLICY_FETCH, // Fetching policy. | |
| 79 STEP_VALIDATION, // Policy validation. | |
| 80 STEP_LOCK_DEVICE, // Writing installation-time attributes. | |
| 81 STEP_STORE_POLICY, // Storing policy. | |
| 82 STEP_FINISHED, // Enrollment process finished, no further action. | |
| 83 }; | |
| 84 | |
| 85 // Starts registration if the store is initialized. | |
| 86 void AttemptRegistration(); | |
| 87 | |
| 88 // Handles the policy validation result, proceeding with installation-time | |
| 89 // attributes locking if successful. | |
| 90 void PolicyValidated(DeviceCloudPolicyValidator* validator); | |
| 91 | |
| 92 // Writes install attributes and proceeds to policy installation. If | |
| 93 // unsuccessful, reports the result. | |
| 94 void WriteInstallAttributes(const std::string& user, | |
| 95 DeviceMode device_mode, | |
| 96 const std::string& device_id); | |
| 97 | |
| 98 // Drops any ongoing actions. | |
| 99 void Stop(); | |
| 100 | |
| 101 // Reports the result of the enrollment process to the initiator. | |
| 102 void ReportResult(EnrollmentStatus status); | |
| 103 | |
| 104 DeviceCloudPolicyStoreChromeOS* store_; | |
| 105 EnterpriseInstallAttributes* install_attributes_; | |
| 106 scoped_ptr<CloudPolicyClient> client_; | |
| 107 | |
| 108 std::string auth_token_; | |
| 109 AllowedDeviceModes allowed_device_modes_; | |
| 110 CompletionCallback completion_callback_; | |
| 111 | |
| 112 // The device mode as received in the registration request. | |
| 113 DeviceMode device_mode_; | |
| 114 | |
| 115 // The validated policy response to be installed in the store. | |
| 116 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; | |
| 117 | |
| 118 // Current enrollment step. | |
| 119 EnrollmentStep enrollment_step_; | |
| 120 | |
| 121 // Total amount of time in milliseconds spent waiting for lockbox | |
| 122 // initialization. | |
| 123 int lockbox_init_duration_; | |
| 124 | |
| 125 base::WeakPtrFactory<EnrollmentHandlerChromeOS> weak_factory_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(EnrollmentHandlerChromeOS); | |
| 128 }; | |
| 129 | |
| 130 } // namespace policy | |
| 131 | |
| 132 #endif // CHROME_BROWSER_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | |
| OLD | NEW |