Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: chrome/browser/chromeos/login/session_manager_operation.h

Issue 10828032: Add DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/session_manager_operation.h
diff --git a/chrome/browser/chromeos/login/session_manager_operation.h b/chrome/browser/chromeos/login/session_manager_operation.h
new file mode 100644
index 0000000000000000000000000000000000000000..2f81f63299fb25ba2c4246ff8d3994130d8b919f
--- /dev/null
+++ b/chrome/browser/chromeos/login/session_manager_operation.h
@@ -0,0 +1,207 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_
+#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/login/device_settings_service.h"
+
+namespace enterprise_management {
+class ChromeDeviceSettingsProto;
+class PolicyData;
+}
+
+namespace chromeos {
+
+class OwnerKeyUtil;
+class SessionManagerClient;
+
+// Handles a single transaction with session manager. This is a virtual base
+// class that contains common infrastructure for key and policy loading. There
+// are subclasses for loading, storing and signing policy blobs.
+class SessionManagerOperation {
+ public:
+ typedef base::Callback<void(SessionManagerOperation*,
+ DeviceSettingsService::Status)>
+ Callback;
+
+ // Creates a new load operation.
+ SessionManagerOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
+ const Callback& callback);
+ virtual ~SessionManagerOperation();
+
+ // Runs the operation. The result is reported through |callback_|.
+ virtual void Run() = 0;
+
+ // Restarts a load operation (if that part is already in progress).
+ virtual void RestartLoad(bool key_changed);
+
+ // Accessors for recovering the loaded policy data after completion.
+ scoped_ptr<enterprise_management::PolicyData>& policy_data() {
+ return policy_data_;
+ }
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto>&
+ device_settings() {
+ return device_settings_;
+ }
+
+ // Owner key as configured/loaded from disk.
+ scoped_refptr<OwnerKey> owner_key() {
+ return owner_key_;
+ }
+
+ // Whether the load operation is underway.
+ bool is_loading() const {
+ return is_loading_;
+ }
+
+ void set_owner_key(scoped_refptr<OwnerKey> owner_key) {
+ owner_key_ = owner_key;
+ }
+
+ void set_force_key_load(bool force_key_load) {
+ force_key_load_ = force_key_load;
+ }
+
+ void set_session_manager_client(
+ SessionManagerClient* session_manager_client) {
+ session_manager_client_ = session_manager_client;
+ }
+
+ protected:
+ // Ensures the owner key is loaded.
+ void EnsureOwnerKey(const base::Closure& callback);
+
+ // Starts a load operation.
+ void StartLoading();
+
+ // Reports the result status of the operation. Once this gets called, the
+ // operation should not perform further processing or trigger callbacks.
+ void ReportResult(DeviceSettingsService::Status status);
+
+ SessionManagerClient* session_manager_client() {
+ return session_manager_client_;
+ }
+
+ private:
+ // Loads the owner key from disk. Must be run on a thread that can do I/O.
+ static scoped_refptr<OwnerKey> LoadOwnerKey(
+ scoped_refptr<OwnerKeyUtil> util,
+ scoped_refptr<OwnerKey> current_key);
+
+ // Stores the owner key loaded by LoadOwnerKey and calls |callback|.
+ void StoreOwnerKey(const base::Closure& callback,
+ scoped_refptr<OwnerKey> new_key);
+
+ // Triggers a device settings load.
+ void RetrieveDeviceSettings();
+
+ // Validates device settings after retrieval from session_manager.
+ void ValidateDeviceSettings(const std::string& policy_blob);
+
+ // Extracts status and device settings from the validator and reports them.
+ void ReportValidatorStatus(policy::DeviceCloudPolicyValidator* validator);
+
+ SessionManagerClient* session_manager_client_;
+ scoped_refptr<OwnerKeyUtil> owner_key_util_;
+
+ base::WeakPtrFactory<SessionManagerOperation> weak_factory_;
+
+ Callback callback_;
+
+ scoped_refptr<OwnerKey> owner_key_;
+ bool force_key_load_;
+
+ bool is_loading_;
+ scoped_ptr<enterprise_management::PolicyData> policy_data_;
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_;
+
+ DISALLOW_COPY_AND_ASSIGN(SessionManagerOperation);
+};
+
+// This operation loads the public owner key from disk if appropriate, fetches
+// the policy blob from session manager, and validates the loaded policy blob.
+class LoadSettingsOperation : public SessionManagerOperation {
+ public:
+ // Creates a new load operation.
+ LoadSettingsOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
+ const Callback& callback);
+ virtual ~LoadSettingsOperation();
+
+ // SessionManagerOperation:
+ virtual void Run() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoadSettingsOperation);
+};
+
+// Stores a pre-generated policy blob and reloads the device settings from
+// session_manager.
+class StoreSettingsOperation : public SessionManagerOperation {
+ public:
+ // Creates a new store operation.
+ StoreSettingsOperation(scoped_refptr<OwnerKeyUtil> owner_key_util,
+ const Callback& callback,
+ const std::string& policy_blob);
+ virtual ~StoreSettingsOperation();
+
+ // SessionManagerOperation:
+ virtual void Run() OVERRIDE;
+
+ private:
+ // Handles the result of the store operation and triggers the load.
+ void HandleStoreResult(bool success);
+
+ std::string policy_blob_;
+
+ base::WeakPtrFactory<StoreSettingsOperation> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(StoreSettingsOperation);
+};
+
+// Signs device settings and stores the resulting blob to session_manager.
+class SignAndStoreSettingsOperation : public SessionManagerOperation {
+ public:
+ // Creates a new sign-and-store operation.
+ SignAndStoreSettingsOperation(
+ scoped_refptr<OwnerKeyUtil> owner_key_util,
+ const Callback& callback,
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
+ const std::string& username);
+ virtual ~SignAndStoreSettingsOperation();
+
+ // SessionManagerOperation:
+ virtual void Run() OVERRIDE;
+
+ private:
+ // Given an owner key, starts the signing operation.
+ void StartSigning();
+
+ // Builds the policy blob and signs it using the owner key.
+ static std::string AssembleAndSignPolicy(
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
+ const std::string& username,
+ scoped_refptr<OwnerKey> owner_key);
+
+ // Stores the signed device settings blob.
+ void StoreDeviceSettingsBlob(std::string device_settings_blob);
+
+ // Handles the result of the store operation and triggers the load.
+ void HandleStoreResult(bool success);
+
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings_;
+ std::string username_;
+
+ base::WeakPtrFactory<SignAndStoreSettingsOperation> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(SignAndStoreSettingsOperation);
+};
+
+} // namespace
+
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_MANAGER_OPERATION_H_

Powered by Google App Engine
This is Rietveld 408576698