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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h

Issue 548323003: Non-plafrom-specific part of an OwnerSettingsService is moved to components/ownership/*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" 14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
17 #include "chromeos/dbus/session_manager_client.h" 15 #include "chromeos/dbus/session_manager_client.h"
18 #include "chromeos/tpm_token_loader.h" 16 #include "chromeos/tpm_token_loader.h"
19 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/ownership/owner_settings_service.h"
20 #include "components/ownership/owner_key_util.h"
21 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
23 20
24 class Profile; 21 class Profile;
25 22
23 namespace ownership {
24 class OwnerKeyUtil;
25 }
26
26 namespace chromeos { 27 namespace chromeos {
27 28
28 class SessionManagerOperation; 29 class SessionManagerOperation;
29 30
30 // This class reloads owner key from profile NSS slots. 31 // The class is a profile-keyed service which holds public/private
32 // keypair corresponds to a profile. The keypair is reloaded automatically when
33 // profile is created and TPM token is ready. Note that the private part of a
34 // key can be loaded only for the owner.
31 // 35 //
32 // TODO (ygorshenin@): move write path for device settings here 36 // TODO (ygorshenin@): move write path for device settings here
33 // (crbug.com/230018). 37 // (crbug.com/230018).
34 class OwnerSettingsService : public DeviceSettingsService::PrivateKeyDelegate, 38 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService,
35 public KeyedService, 39 public content::NotificationObserver,
36 public content::NotificationObserver, 40 public TPMTokenLoader::Observer,
37 public TPMTokenLoader::Observer, 41 public SessionManagerClient::Observer {
38 public SessionManagerClient::Observer {
39 public: 42 public:
40 virtual ~OwnerSettingsService(); 43 virtual ~OwnerSettingsServiceChromeOS();
41 44
42 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { 45 // ownership::OwnerSettingsService implementation:
43 return weak_factory_.GetWeakPtr(); 46 virtual void SignAndStorePolicyAsync(
44 }
45
46 // DeviceSettingsService::PrivateKeyDelegate implementation:
47 virtual bool IsOwner() OVERRIDE;
48 virtual void IsOwnerAsync(const IsOwnerCallback& callback) OVERRIDE;
49 virtual bool AssembleAndSignPolicyAsync(
50 scoped_ptr<enterprise_management::PolicyData> policy, 47 scoped_ptr<enterprise_management::PolicyData> policy,
51 const AssembleAndSignPolicyCallback& callback) OVERRIDE;
52 virtual void SignAndStoreAsync(
53 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings,
54 const base::Closure& callback) OVERRIDE;
55 virtual void SetManagementSettingsAsync(
56 enterprise_management::PolicyData::ManagementMode management_mode,
57 const std::string& request_token,
58 const std::string& device_id,
59 const base::Closure& callback) OVERRIDE; 48 const base::Closure& callback) OVERRIDE;
60 49
61 // NotificationObserver implementation: 50 // NotificationObserver implementation:
62 virtual void Observe(int type, 51 virtual void Observe(int type,
63 const content::NotificationSource& source, 52 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE; 53 const content::NotificationDetails& details) OVERRIDE;
65 54
66 // TPMTokenLoader::Observer: 55 // TPMTokenLoader::Observer:
67 virtual void OnTPMTokenReady() OVERRIDE; 56 virtual void OnTPMTokenReady() OVERRIDE;
68 57
69 // SessionManagerClient::Observer: 58 // SessionManagerClient::Observer:
70 virtual void OwnerKeySet(bool success) OVERRIDE; 59 virtual void OwnerKeySet(bool success) OVERRIDE;
71 60
72 // Checks if the user is the device owner, without the user profile having to 61 // Checks if the user is the device owner, without the user profile having to
73 // been initialized. Should be used only if login state is in safe mode. 62 // been initialized. Should be used only if login state is in safe mode.
74 static void IsOwnerForSafeModeAsync( 63 static void IsOwnerForSafeModeAsync(
75 const std::string& user_id, 64 const std::string& user_id,
76 const std::string& user_hash, 65 const std::string& user_hash,
77 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, 66 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util,
78 const IsOwnerCallback& callback); 67 const IsOwnerCallback& callback);
79 68
80 static void SetDeviceSettingsServiceForTesting( 69 static void SetDeviceSettingsServiceForTesting(
81 DeviceSettingsService* device_settings_service); 70 DeviceSettingsService* device_settings_service);
82 71
83 private: 72 private:
84 friend class OwnerSettingsServiceFactory; 73 friend class OwnerSettingsServiceChromeOSFactory;
85 74
86 OwnerSettingsService( 75 OwnerSettingsServiceChromeOS(
87 Profile* profile, 76 Profile* profile,
88 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); 77 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
89 78
90 // Reloads private key from profile's NSS slots. Responds via call 79 // OwnerSettingsService protected interface overrides:
91 // to OnPrivateKeyLoaded().
92 void ReloadPrivateKey();
93 80
94 // Called when ReloadPrivateKey() completes it's work. 81 // Reloads private key from profile's NSS slots, responds via |callback|.
95 void OnPrivateKeyLoaded(scoped_refptr<ownership::PublicKey> public_key, 82 virtual void ReloadKeypairImpl(const base::Callback<
96 scoped_refptr<ownership::PrivateKey> private_key); 83 void(const scoped_refptr<ownership::PublicKey>& public_key,
84 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback)
85 OVERRIDE;
97 86
98 // Puts request to perform sign-and-store operation in the queue. 87 // Possibly notifies DeviceSettingsService that owner's keypair is loaded.
99 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, 88 virtual void OnPostKeypairLoadedActions() OVERRIDE;
100 const base::Closure& callback);
101 89
102 // Performs next operation in the queue. 90 // Performs next operation in the queue.
103 void StartNextOperation(); 91 void StartNextOperation();
104 92
105 // Called when sign-and-store operation completes it's work. 93 // Called when sign-and-store operation completes it's work.
106 void HandleCompletedOperation(const base::Closure& callback, 94 void HandleCompletedOperation(const base::Closure& callback,
107 SessionManagerOperation* operation, 95 SessionManagerOperation* operation,
108 DeviceSettingsService::Status status); 96 DeviceSettingsService::Status status);
109 97
110 // Called when it's not possible to store settings.
111 void HandleError(DeviceSettingsService::Status status,
112 const base::Closure& callback);
113
114 // Returns testing instance of OwnerKeyUtil when it's set, otherwise
115 // returns |owner_key_util_|.
116 scoped_refptr<ownership::OwnerKeyUtil> GetOwnerKeyUtil();
117
118 // Returns testing instance of DeviceSettingsService when it's set,
119 // otherwise returns pointer to a singleton instance, when it's
120 // initialized.
121 DeviceSettingsService* GetDeviceSettingsService();
122
123 // Profile this service instance belongs to. 98 // Profile this service instance belongs to.
124 Profile* profile_; 99 Profile* profile_;
125 100
126 // User ID this service instance belongs to. 101 // User ID this service instance belongs to.
127 std::string user_id_; 102 std::string user_id_;
128 103
129 scoped_refptr<ownership::PublicKey> public_key_;
130
131 scoped_refptr<ownership::PrivateKey> private_key_;
132
133 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_;
134
135 std::vector<IsOwnerCallback> pending_is_owner_callbacks_;
136
137 // Whether profile still needs to be initialized. 104 // Whether profile still needs to be initialized.
138 bool waiting_for_profile_creation_; 105 bool waiting_for_profile_creation_;
139 106
140 // Whether TPM token still needs to be initialized. 107 // Whether TPM token still needs to be initialized.
141 bool waiting_for_tpm_token_; 108 bool waiting_for_tpm_token_;
142 109
143 // The queue of pending sign-and-store operations. The first operation on the 110 // The queue of pending sign-and-store operations. The first operation on the
144 // queue is currently active; it gets removed and destroyed once it completes. 111 // queue is currently active; it gets removed and destroyed once it completes.
145 std::deque<SessionManagerOperation*> pending_operations_; 112 std::deque<SessionManagerOperation*> pending_operations_;
146 113
147 content::NotificationRegistrar registrar_; 114 content::NotificationRegistrar registrar_;
148 115
149 base::ThreadChecker thread_checker_; 116 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_;
150 117
151 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; 118 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS);
152
153 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService);
154 }; 119 };
155 120
156 } // namespace chromeos 121 } // namespace chromeos
157 122
158 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ 123 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698