Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_validator.h" | 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_validator.h" |
| 16 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 17 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 18 #include "google_apis/gaia/gaia_oauth_client.h" | |
| 18 | 19 |
| 19 namespace enterprise_management { | 20 namespace enterprise_management { |
| 20 class PolicyFetchResponse; | 21 class PolicyFetchResponse; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace policy { | 24 namespace policy { |
| 24 | 25 |
| 25 class EnterpriseInstallAttributes; | 26 class EnterpriseInstallAttributes; |
| 26 | 27 |
| 27 // Implements the logic that establishes enterprise enrollment for Chromium OS | 28 // Implements the logic that establishes enterprise enrollment for Chromium OS |
| 28 // devices. The process is as follows: | 29 // devices. The process is as follows: |
| 29 // 1. Given an auth token, register with the policy service. | 30 // 1. Given an auth token, register with the policy service. |
| 30 // 2. Download the initial policy blob from the service. | 31 // 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 // 3. Download the OAuth2 authorization code for device-level API access. |
| 33 // 4. Download the OAuth2 refresh token for device-level API access and store | |
| 34 // it. | |
| 35 // 5. Verify the policy blob. Everything up to this point doesn't touch device | |
|
Mattias Nissler (ping if slow)
2013/03/19 06:33:08
I think we should first verify the policy blob and
David Roche
2013/04/02 01:59:25
Right now the validate step also saves the policy
Mattias Nissler (ping if slow)
2013/04/02 14:16:46
Validation and locking already have their separate
| |
| 32 // state. | 36 // state. |
| 33 // 4. Establish the device lock in installation-time attributes. | 37 // 6. Establish the device lock in installation-time attributes. |
| 34 // 5. Store the policy blob. | 38 // 7. Store the policy blob. |
| 35 class EnrollmentHandlerChromeOS : public CloudPolicyClient::Observer, | 39 class EnrollmentHandlerChromeOS : public CloudPolicyClient::Observer, |
| 36 public CloudPolicyStore::Observer { | 40 public CloudPolicyStore::Observer, |
| 41 public gaia::GaiaOAuthClient::Delegate { | |
| 37 public: | 42 public: |
| 38 typedef DeviceCloudPolicyManagerChromeOS::AllowedDeviceModes | 43 typedef DeviceCloudPolicyManagerChromeOS::AllowedDeviceModes |
| 39 AllowedDeviceModes; | 44 AllowedDeviceModes; |
| 40 typedef DeviceCloudPolicyManagerChromeOS::EnrollmentCallback | 45 typedef DeviceCloudPolicyManagerChromeOS::EnrollmentCallback |
| 41 EnrollmentCallback; | 46 EnrollmentCallback; |
| 42 | 47 |
| 43 // |store| and |install_attributes| must remain valid for the life time of the | 48 // |store| and |install_attributes| must remain valid for the life time of the |
| 44 // enrollment handler. |allowed_device_modes| determines what device modes | 49 // enrollment handler. |allowed_device_modes| determines what device modes |
| 45 // are acceptable. If the mode specified by the server is not acceptable, | 50 // are acceptable. If the mode specified by the server is not acceptable, |
| 46 // enrollment will fail with an EnrollmentStatus indicating | 51 // enrollment will fail with an EnrollmentStatus indicating |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 58 // Starts the enrollment process and reports the result to | 63 // Starts the enrollment process and reports the result to |
| 59 // |completion_callback_|. | 64 // |completion_callback_|. |
| 60 void StartEnrollment(); | 65 void StartEnrollment(); |
| 61 | 66 |
| 62 // Releases the client. | 67 // Releases the client. |
| 63 scoped_ptr<CloudPolicyClient> ReleaseClient(); | 68 scoped_ptr<CloudPolicyClient> ReleaseClient(); |
| 64 | 69 |
| 65 // CloudPolicyClient::Observer: | 70 // CloudPolicyClient::Observer: |
| 66 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 71 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 67 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 72 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 73 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client) OVERRIDE; | |
| 68 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 74 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 69 | 75 |
| 70 // CloudPolicyStore::Observer: | 76 // CloudPolicyStore::Observer: |
| 71 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 77 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
| 72 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 78 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
| 73 | 79 |
| 80 // GaiaOAuthClient::Delegate: | |
| 81 virtual void OnGetTokensResponse(const std::string& refresh_token, | |
| 82 const std::string& access_token, | |
| 83 int expires_in_seconds) OVERRIDE; | |
| 84 virtual void OnRefreshTokenResponse(const std::string& access_token, | |
| 85 int expires_in_seconds) OVERRIDE; | |
| 86 virtual void OnOAuthError() OVERRIDE; | |
| 87 virtual void OnNetworkError(int response_code) OVERRIDE; | |
| 88 | |
| 74 private: | 89 private: |
| 75 // Indicates what step of the process is currently pending. These steps need | 90 // Indicates what step of the process is currently pending. These steps need |
| 76 // to be listed in the order they are traversed in. | 91 // to be listed in the order they are traversed in. |
| 77 enum EnrollmentStep { | 92 enum EnrollmentStep { |
| 78 STEP_PENDING, // Not started yet. | 93 STEP_PENDING, // Not started yet. |
| 79 STEP_LOADING_STORE, // Waiting for |store_| to initialize. | 94 STEP_LOADING_STORE, // Waiting for |store_| to initialize. |
| 80 STEP_REGISTRATION, // Currently registering the client. | 95 STEP_REGISTRATION, // Currently registering the client. |
| 81 STEP_POLICY_FETCH, // Fetching policy. | 96 STEP_ROBOT_AUTH_FETCH, // Fetching device API auth codes. |
| 82 STEP_VALIDATION, // Policy validation. | 97 STEP_ROBOT_AUTH_REFRESH, // Fetching/storing device API refresh tokens. |
| 83 STEP_LOCK_DEVICE, // Writing installation-time attributes. | 98 STEP_POLICY_FETCH, // Fetching policy. |
| 84 STEP_STORE_POLICY, // Storing policy. | 99 STEP_VALIDATION, // Policy validation. |
| 85 STEP_FINISHED, // Enrollment process finished, no further action. | 100 STEP_LOCK_DEVICE, // Writing installation-time attributes. |
| 101 STEP_STORE_POLICY, // Storing policy. | |
| 102 STEP_FINISHED, // Enrollment process finished, no further action. | |
| 86 }; | 103 }; |
| 87 | 104 |
| 88 // Starts registration if the store is initialized. | 105 // Starts registration if the store is initialized. |
| 89 void AttemptRegistration(); | 106 void AttemptRegistration(); |
| 90 | 107 |
| 91 // Handles the policy validation result, proceeding with installation-time | 108 // Handles the policy validation result, proceeding with installation-time |
| 92 // attributes locking if successful. | 109 // attributes locking if successful. |
| 93 void PolicyValidated(DeviceCloudPolicyValidator* validator); | 110 void PolicyValidated(DeviceCloudPolicyValidator* validator); |
| 94 | 111 |
| 95 // Writes install attributes and proceeds to policy installation. If | 112 // Writes install attributes and proceeds to policy installation. If |
| 96 // unsuccessful, reports the result. | 113 // unsuccessful, reports the result. |
| 97 void WriteInstallAttributes(const std::string& user, | 114 void WriteInstallAttributes(const std::string& user, |
| 98 DeviceMode device_mode, | 115 DeviceMode device_mode, |
| 99 const std::string& device_id); | 116 const std::string& device_id); |
| 100 | 117 |
| 101 // Drops any ongoing actions. | 118 // Drops any ongoing actions. |
| 102 void Stop(); | 119 void Stop(); |
| 103 | 120 |
| 104 // Reports the result of the enrollment process to the initiator. | 121 // Reports the result of the enrollment process to the initiator. |
| 105 void ReportResult(EnrollmentStatus status); | 122 void ReportResult(EnrollmentStatus status); |
| 106 | 123 |
| 107 DeviceCloudPolicyStoreChromeOS* store_; | 124 DeviceCloudPolicyStoreChromeOS* store_; |
| 108 EnterpriseInstallAttributes* install_attributes_; | 125 EnterpriseInstallAttributes* install_attributes_; |
| 109 scoped_ptr<CloudPolicyClient> client_; | 126 scoped_ptr<CloudPolicyClient> client_; |
| 127 scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_; | |
| 110 | 128 |
| 111 std::string auth_token_; | 129 std::string auth_token_; |
| 112 std::string client_id_; | 130 std::string client_id_; |
| 113 bool is_auto_enrollment_; | 131 bool is_auto_enrollment_; |
| 114 AllowedDeviceModes allowed_device_modes_; | 132 AllowedDeviceModes allowed_device_modes_; |
| 115 EnrollmentCallback completion_callback_; | 133 EnrollmentCallback completion_callback_; |
| 116 | 134 |
| 117 // The device mode as received in the registration request. | 135 // The device mode as received in the registration request. |
| 118 DeviceMode device_mode_; | 136 DeviceMode device_mode_; |
| 119 | 137 |
| 120 // The validated policy response to be installed in the store. | 138 // The validated policy response to be installed in the store. |
| 121 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; | 139 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_; |
| 122 | 140 |
| 123 // Current enrollment step. | 141 // Current enrollment step. |
| 124 EnrollmentStep enrollment_step_; | 142 EnrollmentStep enrollment_step_; |
| 125 | 143 |
| 126 // Total amount of time in milliseconds spent waiting for lockbox | 144 // Total amount of time in milliseconds spent waiting for lockbox |
| 127 // initialization. | 145 // initialization. |
| 128 int lockbox_init_duration_; | 146 int lockbox_init_duration_; |
| 129 | 147 |
| 130 base::WeakPtrFactory<EnrollmentHandlerChromeOS> weak_factory_; | 148 base::WeakPtrFactory<EnrollmentHandlerChromeOS> weak_factory_; |
| 131 | 149 |
| 132 DISALLOW_COPY_AND_ASSIGN(EnrollmentHandlerChromeOS); | 150 DISALLOW_COPY_AND_ASSIGN(EnrollmentHandlerChromeOS); |
| 133 }; | 151 }; |
| 134 | 152 |
| 135 } // namespace policy | 153 } // namespace policy |
| 136 | 154 |
| 137 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ | 155 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENROLLMENT_HANDLER_CHROMEOS_H_ |
| OLD | NEW |