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

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: 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 // This class reloads owner key from profile NSS slots.
Nikita (slow) 2014/09/10 18:05:11 Please update comment.
ygorshenin1 2014/09/11 14:06:20 Done.
31 // 32 //
32 // TODO (ygorshenin@): move write path for device settings here 33 // TODO (ygorshenin@): move write path for device settings here
33 // (crbug.com/230018). 34 // (crbug.com/230018).
34 class OwnerSettingsService : public DeviceSettingsService::PrivateKeyDelegate, 35 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService,
35 public KeyedService, 36 public content::NotificationObserver,
36 public content::NotificationObserver, 37 public TPMTokenLoader::Observer,
37 public TPMTokenLoader::Observer, 38 public SessionManagerClient::Observer {
38 public SessionManagerClient::Observer {
39 public: 39 public:
40 virtual ~OwnerSettingsService(); 40 virtual ~OwnerSettingsServiceChromeOS();
41 41
42 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { 42 // ownership::OwnerSettingsService implementation:
43 return weak_factory_.GetWeakPtr(); 43 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, 44 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; 45 const base::Closure& callback) OVERRIDE;
60 46
61 // NotificationObserver implementation: 47 // NotificationObserver implementation:
62 virtual void Observe(int type, 48 virtual void Observe(int type,
63 const content::NotificationSource& source, 49 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE; 50 const content::NotificationDetails& details) OVERRIDE;
65 51
66 // TPMTokenLoader::Observer: 52 // TPMTokenLoader::Observer:
67 virtual void OnTPMTokenReady() OVERRIDE; 53 virtual void OnTPMTokenReady() OVERRIDE;
68 54
69 // SessionManagerClient::Observer: 55 // SessionManagerClient::Observer:
70 virtual void OwnerKeySet(bool success) OVERRIDE; 56 virtual void OwnerKeySet(bool success) OVERRIDE;
71 57
72 // Checks if the user is the device owner, without the user profile having to 58 // 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. 59 // been initialized. Should be used only if login state is in safe mode.
74 static void IsOwnerForSafeModeAsync( 60 static void IsOwnerForSafeModeAsync(
75 const std::string& user_id, 61 const std::string& user_id,
76 const std::string& user_hash, 62 const std::string& user_hash,
77 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, 63 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util,
78 const IsOwnerCallback& callback); 64 const IsOwnerCallback& callback);
79 65
80 static void SetDeviceSettingsServiceForTesting( 66 static void SetDeviceSettingsServiceForTesting(
81 DeviceSettingsService* device_settings_service); 67 DeviceSettingsService* device_settings_service);
82 68
83 private: 69 private:
84 friend class OwnerSettingsServiceFactory; 70 friend class OwnerSettingsServiceChromeOSFactory;
85 71
86 OwnerSettingsService( 72 OwnerSettingsServiceChromeOS(
87 Profile* profile, 73 Profile* profile,
88 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); 74 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
89 75
90 // Reloads private key from profile's NSS slots. Responds via call 76 // OwnerSettingsService protected interface overrides:
91 // to OnPrivateKeyLoaded().
92 void ReloadPrivateKey();
93 77
94 // Called when ReloadPrivateKey() completes it's work. 78 // Reloads private key from profile's NSS slots, responds via |callback|.
95 void OnPrivateKeyLoaded(scoped_refptr<ownership::PublicKey> public_key, 79 virtual void ReloadKeypairImpl(const base::Callback<
96 scoped_refptr<ownership::PrivateKey> private_key); 80 void(const scoped_refptr<ownership::PublicKey>& public_key,
81 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback)
82 OVERRIDE;
97 83
98 // Puts request to perform sign-and-store operation in the queue. 84 // Possibly notifies DeviceSettingsService that owner's keypair is loaded.
99 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, 85 virtual void OnPostKeypairLoadedActions() OVERRIDE;
100 const base::Closure& callback);
101 86
102 // Performs next operation in the queue. 87 // Performs next operation in the queue.
103 void StartNextOperation(); 88 void StartNextOperation();
104 89
105 // Called when sign-and-store operation completes it's work. 90 // Called when sign-and-store operation completes it's work.
106 void HandleCompletedOperation(const base::Closure& callback, 91 void HandleCompletedOperation(const base::Closure& callback,
107 SessionManagerOperation* operation, 92 SessionManagerOperation* operation,
108 DeviceSettingsService::Status status); 93 DeviceSettingsService::Status status);
109 94
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. 95 // Profile this service instance belongs to.
124 Profile* profile_; 96 Profile* profile_;
125 97
126 // User ID this service instance belongs to. 98 // User ID this service instance belongs to.
127 std::string user_id_; 99 std::string user_id_;
128 100
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. 101 // Whether profile still needs to be initialized.
138 bool waiting_for_profile_creation_; 102 bool waiting_for_profile_creation_;
139 103
140 // Whether TPM token still needs to be initialized. 104 // Whether TPM token still needs to be initialized.
141 bool waiting_for_tpm_token_; 105 bool waiting_for_tpm_token_;
142 106
143 // The queue of pending sign-and-store operations. The first operation on the 107 // 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. 108 // queue is currently active; it gets removed and destroyed once it completes.
145 std::deque<SessionManagerOperation*> pending_operations_; 109 std::deque<SessionManagerOperation*> pending_operations_;
146 110
147 content::NotificationRegistrar registrar_; 111 content::NotificationRegistrar registrar_;
148 112
149 base::ThreadChecker thread_checker_; 113 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_;
150 114
151 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; 115 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS);
152
153 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService);
154 }; 116 };
155 117
156 } // namespace chromeos 118 } // namespace chromeos
157 119
158 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ 120 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698