Index: chrome/browser/chromeos/ownership/owner_settings_service.h |
diff --git a/chrome/browser/chromeos/ownership/owner_settings_service.h b/chrome/browser/chromeos/ownership/owner_settings_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..37bbabb52cd709f9c6c1da00a54ded3e23786450 |
--- /dev/null |
+++ b/chrome/browser/chromeos/ownership/owner_settings_service.h |
@@ -0,0 +1,154 @@ |
+// Copyright 2014 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_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
+#define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
+ |
+#include <deque> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/thread_checker.h" |
+#include "chrome/browser/chromeos/settings/device_settings_service.h" |
+#include "chromeos/dbus/session_manager_client.h" |
+#include "components/keyed_service/core/keyed_service.h" |
+#include "components/ownership/owner_key_util.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+ |
+class Profile; |
+ |
+namespace chromeos { |
+ |
+class SessionManagerOperation; |
+ |
+// This class reloads owner key from profile NSS slots. |
+// |
+// TODO (ygorshenin@): move write path for device settings here |
+// (crbug.com/230018). |
+class OwnerSettingsService : public DeviceSettingsService::PrivateKeyDelegate, |
+ public KeyedService, |
+ public content::NotificationObserver, |
+ public SessionManagerClient::Observer { |
+ public: |
+ virtual ~OwnerSettingsService(); |
+ |
+ base::WeakPtr<OwnerSettingsService> as_weak_ptr() { |
+ return weak_factory_.GetWeakPtr(); |
+ } |
+ |
+ void OnTPMTokenReady(bool tpm_token_enabled); |
+ |
+ // DeviceSettingsService::PrivateKeyDelegate implementation: |
+ virtual bool IsOwner() OVERRIDE; |
+ virtual void IsOwnerAsync(const IsOwnerCallback& callback) OVERRIDE; |
+ virtual bool AssembleAndSignPolicyAsync( |
+ scoped_ptr<enterprise_management::PolicyData> policy, |
+ const AssembleAndSignPolicyCallback& callback) OVERRIDE; |
+ virtual void SignAndStoreAsync( |
+ scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings, |
+ const base::Closure& callback) OVERRIDE; |
+ virtual void SetManagementSettingsAsync( |
+ enterprise_management::PolicyData::ManagementMode management_mode, |
+ const std::string& request_token, |
+ const std::string& device_id, |
+ const base::Closure& callback) OVERRIDE; |
+ |
+ // NotificationObserver implementation: |
+ virtual void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) OVERRIDE; |
+ |
+ // SessionManagerClient::Observer: |
+ virtual void OwnerKeySet(bool success) OVERRIDE; |
+ |
+ // Checks if the user is the device owner, without the user profile having to |
+ // been initialized. Should be used only if login state is in safe mode. |
+ static void IsOwnerForSafeModeAsync( |
+ const std::string& user_hash, |
+ const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, |
+ const IsOwnerCallback& callback); |
+ |
+ static void SetDeviceSettingsServiceForTesting( |
+ DeviceSettingsService* device_settings_service); |
+ |
+ private: |
+ friend class OwnerSettingsServiceFactory; |
+ |
+ OwnerSettingsService( |
+ Profile* profile, |
+ const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
+ |
+ // Reloads private key from profile's NSS slots. Responds via call |
+ // to OnPrivateKeyLoaded(). |
+ void ReloadPrivateKey(); |
+ |
+ // Called when ReloadPrivateKey() completes it's work. |
+ void OnPrivateKeyLoaded(scoped_refptr<ownership::PublicKey> public_key, |
+ scoped_refptr<ownership::PrivateKey> private_key); |
+ |
+ // Puts request to perform sign-and-store operation in the queue. |
+ void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, |
+ const base::Closure& callback); |
+ |
+ // Performs next operation in the queue. |
+ void StartNextOperation(); |
+ |
+ // Called when sign-and-store operation completes it's work. |
+ void HandleCompletedOperation(const base::Closure& callback, |
+ SessionManagerOperation* operation, |
+ DeviceSettingsService::Status status); |
+ |
+ // Called when it's not possible to store settings. |
+ void HandleError(DeviceSettingsService::Status status, |
+ const base::Closure& callback); |
+ |
+ // Returns testing instance of OwnerKeyUtil when it's set, otherwise |
+ // returns |owner_key_util_|. |
+ scoped_refptr<ownership::OwnerKeyUtil> GetOwnerKeyUtil(); |
+ |
+ // Returns testing instance of DeviceSettingsService when it's set, |
+ // otherwise returns pointer to a singleton instance, when it's |
+ // initialized. |
+ DeviceSettingsService* GetDeviceSettingsService(); |
+ |
+ // Profile this service instance belongs to. |
+ Profile* profile_; |
+ |
+ // User ID this service instance belongs to. |
+ std::string user_id_; |
+ |
+ scoped_refptr<ownership::PublicKey> public_key_; |
+ |
+ scoped_refptr<ownership::PrivateKey> private_key_; |
+ |
+ scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
+ |
+ std::vector<IsOwnerCallback> pending_is_owner_callbacks_; |
+ |
+ // Whether profile still needs to be initialized. |
+ bool waiting_for_profile_creation_; |
+ |
+ // Whether TPM token still needs to be initialized. |
+ bool waiting_for_tpm_token_; |
+ |
+ // The queue of pending sign-and-store operations. The first operation on the |
+ // queue is currently active; it gets removed and destroyed once it completes. |
+ std::deque<SessionManagerOperation*> pending_operations_; |
+ |
+ content::NotificationRegistrar registrar_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ base::WeakPtrFactory<OwnerSettingsService> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |