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

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

Issue 654263003: Implemented OwnerSettingsService::Set() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 6 years, 2 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_CHROMEOS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ 6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
7 7
8 #include <deque> 8 #include <queue>
9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/observer_list.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" 16 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #include "chromeos/dbus/session_manager_client.h" 17 #include "chromeos/dbus/session_manager_client.h"
16 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/ownership/owner_key_util.h" 19 #include "components/ownership/owner_key_util.h"
18 #include "components/ownership/owner_settings_service.h" 20 #include "components/ownership/owner_settings_service.h"
19 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
21 23
22 class Profile; 24 class Profile;
23 25
24 namespace ownership { 26 namespace ownership {
25 class OwnerKeyUtil; 27 class OwnerKeyUtil;
26 } 28 }
27 29
28 namespace chromeos { 30 namespace chromeos {
29 31
30 class SessionManagerOperation;
31
32 // The class is a profile-keyed service which holds public/private 32 // The class is a profile-keyed service which holds public/private
33 // keypair corresponds to a profile. The keypair is reloaded automatically when 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 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. 35 // key can be loaded only for the owner.
36 // 36 //
37 // TODO (ygorshenin@): move write path for device settings here 37 // TODO (ygorshenin@): move write path for device settings here
38 // (crbug.com/230018). 38 // (crbug.com/230018).
39 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, 39 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService,
40 public content::NotificationObserver, 40 public content::NotificationObserver,
41 public SessionManagerClient::Observer { 41 public SessionManagerClient::Observer,
42 public DeviceSettingsService::Observer {
42 public: 43 public:
44 class Observer {
45 public:
46 virtual ~Observer() {}
47 virtual void OnSetCompleted(bool success) = 0;
48 };
49
43 virtual ~OwnerSettingsServiceChromeOS(); 50 virtual ~OwnerSettingsServiceChromeOS();
44 51
45 void OnTPMTokenReady(bool tpm_token_enabled); 52 void OnTPMTokenReady(bool tpm_token_enabled);
46 53
47 // ownership::OwnerSettingsService implementation: 54 // ownership::OwnerSettingsService implementation:
48 virtual void SignAndStorePolicyAsync( 55 virtual bool HandlesSetting(const std::string& setting) override;
49 scoped_ptr<enterprise_management::PolicyData> policy, 56 virtual void Set(const std::string& setting,
50 const base::Closure& callback) override; 57 const base::Value& value) override;
51 58
52 // NotificationObserver implementation: 59 // NotificationObserver implementation:
53 virtual void Observe(int type, 60 virtual void Observe(int type,
54 const content::NotificationSource& source, 61 const content::NotificationSource& source,
55 const content::NotificationDetails& details) override; 62 const content::NotificationDetails& details) override;
56 63
57 // SessionManagerClient::Observer: 64 // SessionManagerClient::Observer:
58 virtual void OwnerKeySet(bool success) override; 65 virtual void OwnerKeySet(bool success) override;
59 66
67 // DeviceSettingsService::Observer:
68 virtual void OwnershipStatusChanged() override;
69 virtual void DeviceSettingsUpdated() override;
70
60 // Checks if the user is the device owner, without the user profile having to 71 // 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. 72 // been initialized. Should be used only if login state is in safe mode.
62 static void IsOwnerForSafeModeAsync( 73 static void IsOwnerForSafeModeAsync(
63 const std::string& user_hash, 74 const std::string& user_hash,
64 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, 75 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util,
65 const IsOwnerCallback& callback); 76 const IsOwnerCallback& callback);
66 77
67 static void SetDeviceSettingsServiceForTesting( 78 void AddObserver(Observer* observer);
68 DeviceSettingsService* device_settings_service); 79
80 void RemoveObserver(Observer* observer);
69 81
70 private: 82 private:
83 // Scoped lock for DeviceSettingsService processing loop.
84 class ProcessingLoopAutoBlocker;
85
71 friend class OwnerSettingsServiceChromeOSFactory; 86 friend class OwnerSettingsServiceChromeOSFactory;
72 87
73 OwnerSettingsServiceChromeOS( 88 OwnerSettingsServiceChromeOS(
89 DeviceSettingsService* device_settings_service,
74 Profile* profile, 90 Profile* profile,
75 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); 91 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
76 92
77 // OwnerSettingsService protected interface overrides: 93 // OwnerSettingsService protected interface overrides:
78 94
79 // Reloads private key from profile's NSS slots, responds via |callback|. 95 // Reloads private key from profile's NSS slots, responds via |callback|.
80 virtual void ReloadKeypairImpl(const base::Callback< 96 virtual void ReloadKeypairImpl(const base::Callback<
81 void(const scoped_refptr<ownership::PublicKey>& public_key, 97 void(const scoped_refptr<ownership::PublicKey>& public_key,
82 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) 98 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback)
83 override; 99 override;
84 100
85 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. 101 // Possibly notifies DeviceSettingsService that owner's keypair is loaded.
86 virtual void OnPostKeypairLoadedActions() override; 102 virtual void OnPostKeypairLoadedActions() override;
87 103
88 // Performs next operation in the queue. 104 // Posts task on the current thread to process next set
89 void StartNextOperation(); 105 // request.
106 void ProcessNextSetRequestAsync();
90 107
91 // Called when sign-and-store operation completes it's work. 108 // Tries to process next set request when DeviceSettingsService is not busy
92 void HandleCompletedOperation(const base::Closure& callback, 109 // with session manager operations. If it's the case, temprorary stops
Mattias Nissler (ping if slow) 2014/10/20 12:41:30 *temporarily
ygorshenin1 2014/10/22 09:20:11 Acknowledged.
93 SessionManagerOperation* operation, 110 // DeviceSettingsService's processing loop to prevent changes in device
94 DeviceSettingsService::Status status); 111 // settings, modifies current device settings and sends them for signing.
112 // When device settings are correctly signed, OnPolicyAssembledAndSigned() is
113 // called, otherwise, HandleError() is called.
114 void ProcessNextSetRequest();
115
116 // Called when current device settings are successfully signed.
117 // Runs DeviceSettingsService's processing loop and sends signed
118 // settings for storage.
119 void OnPolicyAssembledAndSigned(
120 scoped_ptr<ProcessingLoopAutoBlocker> blocker,
121 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response);
122
123 // Called by DeviceSettingsService when modified and signed device settings
124 // are stored. Notifies observers and tries to process next set request.
125 void OnSignedPolicyStored();
126
127 // Called when modified device settings wasn't successfully signed. Notifies
128 // observers and tries to process next set request.
129 void HandleError();
130
131 DeviceSettingsService* device_settings_service_;
95 132
96 // Profile this service instance belongs to. 133 // Profile this service instance belongs to.
97 Profile* profile_; 134 Profile* profile_;
98 135
99 // User ID this service instance belongs to. 136 // User ID this service instance belongs to.
100 std::string user_id_; 137 std::string user_id_;
101 138
102 // Whether profile still needs to be initialized. 139 // Whether profile still needs to be initialized.
103 bool waiting_for_profile_creation_; 140 bool waiting_for_profile_creation_;
104 141
105 // Whether TPM token still needs to be initialized. 142 // Whether TPM token still needs to be initialized.
106 bool waiting_for_tpm_token_; 143 bool waiting_for_tpm_token_;
107 144
108 // The queue of pending sign-and-store operations. The first operation on the 145 // A structure used to represent set request for a particular device
109 // queue is currently active; it gets removed and destroyed once it completes. 146 // setting.
110 std::deque<SessionManagerOperation*> pending_operations_; 147 struct SetRequest {
148 SetRequest(const std::string& setting, linked_ptr<base::Value> value);
149 ~SetRequest();
150
151 const std::string setting;
152 const linked_ptr<base::Value> value;
153 };
154
155 // A queue of serialized set requests, which should be processed in FIFO
156 // order.
157 std::queue<SetRequest> set_requests_;
158
159 ObserverList<Observer> observers_;
111 160
112 content::NotificationRegistrar registrar_; 161 content::NotificationRegistrar registrar_;
113 162
114 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; 163 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_;
115 164
165 base::WeakPtrFactory<OwnerSettingsServiceChromeOS>
166 set_requests_callback_factory_;
167
116 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); 168 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS);
117 }; 169 };
118 170
119 } // namespace chromeos 171 } // namespace chromeos
120 172
121 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ 173 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698