1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "chromeos/dbus/session_manager_client.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/ownership/owner_key_util.h"
18 #include "components/ownership/owner_settings_service.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
30 class SessionManagerOperation
;
32 // The class is a profile-keyed service which holds public/private
33 // keypair corresponds to a profile. The keypair is reloaded automatically when
34 // profile is created and TPM token is ready. Note that the private part of a
35 // key can be loaded only for the owner.
37 // TODO (ygorshenin@): move write path for device settings here
38 // (crbug.com/230018).
39 class OwnerSettingsServiceChromeOS
: public ownership::OwnerSettingsService
,
40 public content::NotificationObserver
,
41 public SessionManagerClient::Observer
{
43 virtual ~OwnerSettingsServiceChromeOS();
45 void OnTPMTokenReady(bool tpm_token_enabled
);
47 // ownership::OwnerSettingsService implementation:
48 virtual void SignAndStorePolicyAsync(
49 scoped_ptr
<enterprise_management::PolicyData
> policy
,
50 const base::Closure
& callback
) override
;
52 // NotificationObserver implementation:
53 virtual void Observe(int type
,
54 const content::NotificationSource
& source
,
55 const content::NotificationDetails
& details
) override
;
57 // SessionManagerClient::Observer:
58 virtual void OwnerKeySet(bool success
) override
;
60 // Checks if the user is the device owner, without the user profile having to
61 // been initialized. Should be used only if login state is in safe mode.
62 static void IsOwnerForSafeModeAsync(
63 const std::string
& user_hash
,
64 const scoped_refptr
<ownership::OwnerKeyUtil
>& owner_key_util
,
65 const IsOwnerCallback
& callback
);
67 static void SetDeviceSettingsServiceForTesting(
68 DeviceSettingsService
* device_settings_service
);
71 friend class OwnerSettingsServiceChromeOSFactory
;
73 OwnerSettingsServiceChromeOS(
75 const scoped_refptr
<ownership::OwnerKeyUtil
>& owner_key_util
);
77 // OwnerSettingsService protected interface overrides:
79 // Reloads private key from profile's NSS slots, responds via |callback|.
80 virtual void ReloadKeypairImpl(const base::Callback
<
81 void(const scoped_refptr
<ownership::PublicKey
>& public_key
,
82 const scoped_refptr
<ownership::PrivateKey
>& private_key
)>& callback
)
85 // Possibly notifies DeviceSettingsService that owner's keypair is loaded.
86 virtual void OnPostKeypairLoadedActions() override
;
88 // Performs next operation in the queue.
89 void StartNextOperation();
91 // Called when sign-and-store operation completes it's work.
92 void HandleCompletedOperation(const base::Closure
& callback
,
93 SessionManagerOperation
* operation
,
94 DeviceSettingsService::Status status
);
96 // Profile this service instance belongs to.
99 // User ID this service instance belongs to.
100 std::string user_id_
;
102 // Whether profile still needs to be initialized.
103 bool waiting_for_profile_creation_
;
105 // Whether TPM token still needs to be initialized.
106 bool waiting_for_tpm_token_
;
108 // The queue of pending sign-and-store operations. The first operation on the
109 // queue is currently active; it gets removed and destroyed once it completes.
110 std::deque
<SessionManagerOperation
*> pending_operations_
;
112 content::NotificationRegistrar registrar_
;
114 base::WeakPtrFactory
<OwnerSettingsServiceChromeOS
> weak_factory_
;
116 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS
);
119 } // namespace chromeos
121 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_