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

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 static void SetDeviceSettingsServiceForTesting(
68 DeviceSettingsService* device_settings_service); 79 DeviceSettingsService* device_settings_service);
69 80
81 void AddObserver(Observer* observer);
82
83 void RemoveObserver(Observer* observer);
84
70 private: 85 private:
86 // Scoped lock for DeviceSettingsService processing loop.
87 class DeviceSettingsServiceLock;
88
71 friend class OwnerSettingsServiceChromeOSFactory; 89 friend class OwnerSettingsServiceChromeOSFactory;
72 90
73 OwnerSettingsServiceChromeOS( 91 OwnerSettingsServiceChromeOS(
74 Profile* profile, 92 Profile* profile,
75 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); 93 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util);
76 94
77 // OwnerSettingsService protected interface overrides: 95 // OwnerSettingsService protected interface overrides:
78 96
79 // Reloads private key from profile's NSS slots, responds via |callback|. 97 // Reloads private key from profile's NSS slots, responds via |callback|.
80 virtual void ReloadKeypairImpl(const base::Callback< 98 virtual void ReloadKeypairImpl(const base::Callback<
81 void(const scoped_refptr<ownership::PublicKey>& public_key, 99 void(const scoped_refptr<ownership::PublicKey>& public_key,
82 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) 100 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback)
83 override; 101 override;
84 102
85 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. 103 // Possibly notifies DeviceSettingsService that owner's keypair is loaded.
86 virtual void OnPostKeypairLoadedActions() override; 104 virtual void OnPostKeypairLoadedActions() override;
87 105
88 // Performs next operation in the queue. 106 void ProcessNextSetRequestAsync();
Mattias Nissler (ping if slow) 2014/10/17 12:05:27 The functions here could use some documentation.
ygorshenin1 2014/10/20 11:36:10 Done.
89 void StartNextOperation();
90 107
91 // Called when sign-and-store operation completes it's work. 108 void ProcessNextSetRequest();
92 void HandleCompletedOperation(const base::Closure& callback, 109
93 SessionManagerOperation* operation, 110 void OnPolicyAssembledAndSigned(
94 DeviceSettingsService::Status status); 111 scoped_ptr<DeviceSettingsServiceLock> lock,
112 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response);
113
114 void OnSignedPolicyStored();
115
116 void HandleError();
95 117
96 // Profile this service instance belongs to. 118 // Profile this service instance belongs to.
97 Profile* profile_; 119 Profile* profile_;
98 120
99 // User ID this service instance belongs to. 121 // User ID this service instance belongs to.
100 std::string user_id_; 122 std::string user_id_;
101 123
102 // Whether profile still needs to be initialized. 124 // Whether profile still needs to be initialized.
103 bool waiting_for_profile_creation_; 125 bool waiting_for_profile_creation_;
104 126
105 // Whether TPM token still needs to be initialized. 127 // Whether TPM token still needs to be initialized.
106 bool waiting_for_tpm_token_; 128 bool waiting_for_tpm_token_;
107 129
108 // The queue of pending sign-and-store operations. The first operation on the 130 typedef std::pair<std::string, linked_ptr<base::Value>> SetRequest;
Mattias Nissler (ping if slow) 2014/10/17 12:05:27 Looking at this, I can only guess what the first c
ygorshenin1 2014/10/20 11:36:10 Done.
109 // queue is currently active; it gets removed and destroyed once it completes. 131 std::queue<SetRequest> set_requests_;
110 std::deque<SessionManagerOperation*> pending_operations_; 132
133 ObserverList<Observer> observers_;
111 134
112 content::NotificationRegistrar registrar_; 135 content::NotificationRegistrar registrar_;
113 136
114 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; 137 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_;
115 138
139 base::WeakPtrFactory<OwnerSettingsServiceChromeOS>
140 set_requests_callback_factory_;
141
116 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); 142 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS);
117 }; 143 };
118 144
119 } // namespace chromeos 145 } // namespace chromeos
120 146
121 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ 147 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698