| 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_CHROMEOS_SETTINGS_SESSION_MANAGER_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SESSION_MANAGER_OPERATION_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 13 |
| 14 namespace enterprise_management { |
| 15 class ChromeDeviceSettingsProto; |
| 16 class PolicyData; |
| 17 } |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 class OwnerKeyUtil; |
| 22 class SessionManagerClient; |
| 23 |
| 24 // Handles a single transaction with session manager. This is a virtual base |
| 25 // class that contains common infrastructure for key and policy loading. There |
| 26 // are subclasses for loading, storing and signing policy blobs. |
| 27 class SessionManagerOperation { |
| 28 public: |
| 29 typedef base::Callback<void(SessionManagerOperation*, |
| 30 DeviceSettingsService::Status)> Callback; |
| 31 |
| 32 // Creates a new load operation. |
| 33 explicit SessionManagerOperation(const Callback& callback); |
| 34 virtual ~SessionManagerOperation(); |
| 35 |
| 36 // Starts the operation. |
| 37 void Start(SessionManagerClient* session_manager_client, |
| 38 scoped_refptr<OwnerKeyUtil> owner_key_util, |
| 39 scoped_refptr<OwnerKey> owner_key); |
| 40 |
| 41 // Restarts a load operation (if that part is already in progress). |
| 42 void RestartLoad(bool key_changed); |
| 43 |
| 44 // Accessors for recovering the loaded policy data after completion. |
| 45 scoped_ptr<enterprise_management::PolicyData>& policy_data() { |
| 46 return policy_data_; |
| 47 } |
| 48 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto>& |
| 49 device_settings() { |
| 50 return device_settings_; |
| 51 } |
| 52 |
| 53 // Owner key as configured/loaded from disk. |
| 54 scoped_refptr<OwnerKey> owner_key() { |
| 55 return owner_key_; |
| 56 } |
| 57 |
| 58 // Whether the load operation is underway. |
| 59 bool is_loading() const { |
| 60 return is_loading_; |
| 61 } |
| 62 |
| 63 void set_force_key_load(bool force_key_load) { |
| 64 force_key_load_ = force_key_load; |
| 65 } |
| 66 |
| 67 protected: |
| 68 // Runs the operation. The result is reported through |callback_|. |
| 69 virtual void Run() = 0; |
| 70 |
| 71 // Ensures the owner key is loaded. |
| 72 void EnsureOwnerKey(const base::Closure& callback); |
| 73 |
| 74 // Starts a load operation. |
| 75 void StartLoading(); |
| 76 |
| 77 // Reports the result status of the operation. Once this gets called, the |
| 78 // operation should not perform further processing or trigger callbacks. |
| 79 void ReportResult(DeviceSettingsService::Status status); |
| 80 |
| 81 SessionManagerClient* session_manager_client() { |
| 82 return session_manager_client_; |
| 83 } |
| 84 |
| 85 private: |
| 86 // Loads the owner key from disk. Must be run on a thread that can do I/O. |
| 87 static scoped_refptr<OwnerKey> LoadOwnerKey( |
| 88 scoped_refptr<OwnerKeyUtil> util, |
| 89 scoped_refptr<OwnerKey> current_key); |
| 90 |
| 91 // Stores the owner key loaded by LoadOwnerKey and calls |callback|. |
| 92 void StoreOwnerKey(const base::Closure& callback, |
| 93 scoped_refptr<OwnerKey> new_key); |
| 94 |
| 95 // Triggers a device settings load. |
| 96 void RetrieveDeviceSettings(); |
| 97 |
| 98 // Validates device settings after retrieval from session_manager. |
| 99 void ValidateDeviceSettings(const std::string& policy_blob); |
| 100 |
| 101 // Extracts status and device settings from the validator and reports them. |
| 102 void ReportValidatorStatus(policy::DeviceCloudPolicyValidator* validator); |
| 103 |
| 104 SessionManagerClient* session_manager_client_; |
| 105 scoped_refptr<OwnerKeyUtil> owner_key_util_; |
| 106 |
| 107 base::WeakPtrFactory<SessionManagerOperation> weak_factory_; |
| 108 |
| 109 Callback callback_; |
| 110 |
| 111 scoped_refptr<OwnerKey> owner_key_; |
| 112 bool force_key_load_; |
| 113 |
| 114 bool is_loading_; |
| 115 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
| 116 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(SessionManagerOperation); |
| 119 }; |
| 120 |
| 121 // This operation loads the public owner key from disk if appropriate, fetches |
| 122 // the policy blob from session manager, and validates the loaded policy blob. |
| 123 class LoadSettingsOperation : public SessionManagerOperation { |
| 124 public: |
| 125 // Creates a new load operation. |
| 126 explicit LoadSettingsOperation(const Callback& callback); |
| 127 virtual ~LoadSettingsOperation(); |
| 128 |
| 129 protected: |
| 130 // SessionManagerOperation: |
| 131 virtual void Run() OVERRIDE; |
| 132 |
| 133 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(LoadSettingsOperation); |
| 135 }; |
| 136 |
| 137 // Stores a pre-generated policy blob and reloads the device settings from |
| 138 // session_manager. |
| 139 class StoreSettingsOperation : public SessionManagerOperation { |
| 140 public: |
| 141 // Creates a new store operation. |
| 142 StoreSettingsOperation(const Callback& callback, |
| 143 const std::string& policy_blob); |
| 144 virtual ~StoreSettingsOperation(); |
| 145 |
| 146 protected: |
| 147 // SessionManagerOperation: |
| 148 virtual void Run() OVERRIDE; |
| 149 |
| 150 private: |
| 151 // Handles the result of the store operation and triggers the load. |
| 152 void HandleStoreResult(bool success); |
| 153 |
| 154 std::string policy_blob_; |
| 155 |
| 156 base::WeakPtrFactory<StoreSettingsOperation> weak_factory_; |
| 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(StoreSettingsOperation); |
| 159 }; |
| 160 |
| 161 // Signs device settings and stores the resulting blob to session_manager. |
| 162 class SignAndStoreSettingsOperation : public SessionManagerOperation { |
| 163 public: |
| 164 // Creates a new sign-and-store operation. |
| 165 SignAndStoreSettingsOperation( |
| 166 const Callback& callback, |
| 167 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, |
| 168 const std::string& username); |
| 169 virtual ~SignAndStoreSettingsOperation(); |
| 170 |
| 171 // SessionManagerOperation: |
| 172 virtual void Run() OVERRIDE; |
| 173 |
| 174 private: |
| 175 // Given an owner key, starts the signing operation. |
| 176 void StartSigning(); |
| 177 |
| 178 // Builds the policy blob and signs it using the owner key. |
| 179 static std::string AssembleAndSignPolicy( |
| 180 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings, |
| 181 const std::string& username, |
| 182 scoped_refptr<OwnerKey> owner_key); |
| 183 |
| 184 // Stores the signed device settings blob. |
| 185 void StoreDeviceSettingsBlob(std::string device_settings_blob); |
| 186 |
| 187 // Handles the result of the store operation and triggers the load. |
| 188 void HandleStoreResult(bool success); |
| 189 |
| 190 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings_; |
| 191 std::string username_; |
| 192 |
| 193 base::WeakPtrFactory<SignAndStoreSettingsOperation> weak_factory_; |
| 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(SignAndStoreSettingsOperation); |
| 196 }; |
| 197 |
| 198 } // namespace |
| 199 |
| 200 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SESSION_MANAGER_OPERATION_H_ |
| OLD | NEW |