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

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

Issue 565293003: Revert of 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
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_
7
8 #include <deque>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/compiler_specific.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"
17 #include "chromeos/dbus/session_manager_client.h"
18 #include "components/keyed_service/core/keyed_service.h"
19 #include "components/ownership/owner_key_util.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22
23 class Profile;
24
25 namespace chromeos {
26
27 class SessionManagerOperation;
28
29 // This class reloads owner key from profile NSS slots.
30 //
31 // TODO (ygorshenin@): move write path for device settings here
32 // (crbug.com/230018).
33 class OwnerSettingsService : public DeviceSettingsService::PrivateKeyDelegate,
34 public KeyedService,
35 public content::NotificationObserver,
36 public SessionManagerClient::Observer {
37 public:
38 virtual ~OwnerSettingsService();
39
40 base::WeakPtr<OwnerSettingsService> as_weak_ptr() {
41 return weak_factory_.GetWeakPtr();
42 }
43
44 void OnTPMTokenReady(bool tpm_token_enabled);
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,
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;
60
61 // NotificationObserver implementation:
62 virtual void Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE;
65
66 // SessionManagerClient::Observer:
67 virtual void OwnerKeySet(bool success) OVERRIDE;
68
69 // Checks if the user is the device owner, without the user profile having to
70 // been initialized. Should be used only if login state is in safe mode.
71 static void IsOwnerForSafeModeAsync(
72 const std::string& user_hash,
73 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util,
74 const IsOwnerCallback& callback);
75
76 static void SetDeviceSettingsServiceForTesting(
77 DeviceSettingsService* device_settings_service);
78
79 private:
80 friend class OwnerSettingsServiceFactory;
81
82 OwnerSettingsService(
83 Profile* profile,
84 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
85
86 // Reloads private key from profile's NSS slots. Responds via call
87 // to OnPrivateKeyLoaded().
88 void ReloadPrivateKey();
89
90 // Called when ReloadPrivateKey() completes it's work.
91 void OnPrivateKeyLoaded(scoped_refptr<ownership::PublicKey> public_key,
92 scoped_refptr<ownership::PrivateKey> private_key);
93
94 // Puts request to perform sign-and-store operation in the queue.
95 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy,
96 const base::Closure& callback);
97
98 // Performs next operation in the queue.
99 void StartNextOperation();
100
101 // Called when sign-and-store operation completes it's work.
102 void HandleCompletedOperation(const base::Closure& callback,
103 SessionManagerOperation* operation,
104 DeviceSettingsService::Status status);
105
106 // Called when it's not possible to store settings.
107 void HandleError(DeviceSettingsService::Status status,
108 const base::Closure& callback);
109
110 // Returns testing instance of OwnerKeyUtil when it's set, otherwise
111 // returns |owner_key_util_|.
112 scoped_refptr<ownership::OwnerKeyUtil> GetOwnerKeyUtil();
113
114 // Returns testing instance of DeviceSettingsService when it's set,
115 // otherwise returns pointer to a singleton instance, when it's
116 // initialized.
117 DeviceSettingsService* GetDeviceSettingsService();
118
119 // Profile this service instance belongs to.
120 Profile* profile_;
121
122 // User ID this service instance belongs to.
123 std::string user_id_;
124
125 scoped_refptr<ownership::PublicKey> public_key_;
126
127 scoped_refptr<ownership::PrivateKey> private_key_;
128
129 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_;
130
131 std::vector<IsOwnerCallback> pending_is_owner_callbacks_;
132
133 // Whether profile still needs to be initialized.
134 bool waiting_for_profile_creation_;
135
136 // Whether TPM token still needs to be initialized.
137 bool waiting_for_tpm_token_;
138
139 // The queue of pending sign-and-store operations. The first operation on the
140 // queue is currently active; it gets removed and destroyed once it completes.
141 std::deque<SessionManagerOperation*> pending_operations_;
142
143 content::NotificationRegistrar registrar_;
144
145 base::ThreadChecker thread_checker_;
146
147 base::WeakPtrFactory<OwnerSettingsService> weak_factory_;
148
149 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService);
150 };
151
152 } // namespace chromeos
153
154 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698