OLD | NEW |
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 COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | 5 #ifndef COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
6 #define COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | 6 #define COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | |
17 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
19 #include "components/ownership/ownership_export.h" | 18 #include "components/ownership/ownership_export.h" |
20 #include "policy/proto/device_management_backend.pb.h" | 19 #include "policy/proto/device_management_backend.pb.h" |
21 | 20 |
22 namespace base { | 21 namespace base { |
23 class TaskRunner; | 22 class TaskRunner; |
24 class Value; | |
25 } | 23 } |
26 | 24 |
27 namespace ownership { | 25 namespace ownership { |
28 class OwnerKeyUtil; | 26 class OwnerKeyUtil; |
29 class PrivateKey; | 27 class PrivateKey; |
30 class PublicKey; | 28 class PublicKey; |
31 | 29 |
32 // This class is a common interface for platform-specific classes | 30 // This class is a common interface for platform-specific classes |
33 // which deal with ownership, keypairs and owner-related settings. | 31 // which deal with ownership, keypairs and owner-related settings. |
34 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService { | 32 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService { |
35 public: | 33 public: |
36 class Observer { | 34 typedef base::Callback<void(std::string policy_blob)> |
37 public: | |
38 virtual ~Observer() {} | |
39 | |
40 // Called when signed policy was stored, or when an error happed during | |
41 // policy storage.. | |
42 virtual void OnSignedPolicyStored(bool success) {} | |
43 | |
44 // Called when tentative changes were made to policy, but the policy still | |
45 // not signed and stored. | |
46 // | |
47 // TODO (ygorshenin@, crbug.com/230018): get rid of the method | |
48 // since it creates DeviceSettingsService's dependency on | |
49 // OwnerSettingsService. | |
50 virtual void OnTentativeChangesInPolicy( | |
51 const enterprise_management::PolicyData& policy_data) {} | |
52 }; | |
53 | |
54 typedef base::Callback<void( | |
55 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response)> | |
56 AssembleAndSignPolicyAsyncCallback; | 35 AssembleAndSignPolicyAsyncCallback; |
57 | 36 |
58 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; | 37 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; |
59 | 38 |
60 explicit OwnerSettingsService( | 39 explicit OwnerSettingsService( |
61 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 40 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
62 virtual ~OwnerSettingsService(); | 41 ~OwnerSettingsService() override; |
63 | 42 |
64 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { | 43 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { |
65 return weak_factory_.GetWeakPtr(); | 44 return weak_factory_.GetWeakPtr(); |
66 } | 45 } |
67 | 46 |
68 void AddObserver(Observer* observer); | |
69 | |
70 void RemoveObserver(Observer* observer); | |
71 | |
72 // Returns whether current user is owner or not. When this method | 47 // Returns whether current user is owner or not. When this method |
73 // is called too early, incorrect result can be returned because | 48 // is called too early, incorrect result can be returned because |
74 // private key loading may be in progress. | 49 // private key loading may be in progress. |
75 bool IsOwner(); | 50 bool IsOwner(); |
76 | 51 |
77 // Determines whether current user is owner or not, responds via | 52 // Determines whether current user is owner or not, responds via |
78 // |callback|. | 53 // |callback|. |
79 void IsOwnerAsync(const IsOwnerCallback& callback); | 54 void IsOwnerAsync(const IsOwnerCallback& callback); |
80 | 55 |
81 // Assembles and signs |policy| on the |task_runner|, responds on | 56 // Assembles and signs |policy| on the |task_runner|, responds on |
82 // the original thread via |callback|. | 57 // the original thread via |callback|. |
83 bool AssembleAndSignPolicyAsync( | 58 bool AssembleAndSignPolicyAsync( |
84 base::TaskRunner* task_runner, | 59 base::TaskRunner* task_runner, |
85 scoped_ptr<enterprise_management::PolicyData> policy, | 60 scoped_ptr<enterprise_management::PolicyData> policy, |
86 const AssembleAndSignPolicyAsyncCallback& callback); | 61 const AssembleAndSignPolicyAsyncCallback& callback); |
87 | 62 |
88 // Checks whether |setting| is handled by OwnerSettingsService. | 63 // Signs |settings| with the private half of the owner key and sends |
89 virtual bool HandlesSetting(const std::string& setting) = 0; | 64 // the resulting policy blob for storage. The |
90 | 65 // result of the operation is reported through |callback|. |
91 // Sets |setting| value to |value|. | 66 virtual void SignAndStorePolicyAsync( |
92 virtual bool Set(const std::string& setting, const base::Value& value) = 0; | 67 scoped_ptr<enterprise_management::PolicyData> policy, |
93 | 68 const base::Closure& callback) = 0; |
94 // Sets a bunch of device settings accumulated before ownership gets | |
95 // established. | |
96 // | |
97 // TODO (ygorshenin@, crbug.com/230018): that this is a temporary | |
98 // solution and should be removed. | |
99 virtual bool CommitTentativeDeviceSettings( | |
100 scoped_ptr<enterprise_management::PolicyData> policy) = 0; | |
101 | |
102 bool SetBoolean(const std::string& setting, bool value); | |
103 bool SetInteger(const std::string& setting, int value); | |
104 bool SetDouble(const std::string& setting, double value); | |
105 bool SetString(const std::string& setting, const std::string& value); | |
106 | 69 |
107 protected: | 70 protected: |
108 void ReloadKeypair(); | 71 void ReloadKeypair(); |
109 | 72 |
110 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, | 73 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, |
111 const scoped_refptr<PrivateKey>& private_key); | 74 const scoped_refptr<PrivateKey>& private_key); |
112 | 75 |
113 // Platform-specific keypair loading algorithm. | 76 // Platform-specific keypair loading algorithm. |
114 virtual void ReloadKeypairImpl(const base::Callback< | 77 virtual void ReloadKeypairImpl(const base::Callback< |
115 void(const scoped_refptr<PublicKey>& public_key, | 78 void(const scoped_refptr<PublicKey>& public_key, |
116 const scoped_refptr<PrivateKey>& private_key)>& callback) = 0; | 79 const scoped_refptr<PrivateKey>& private_key)>& callback) = 0; |
117 | 80 |
118 // Plafrom-specific actions which should be performed when keypair is loaded. | 81 // Plafrom-specific actions which should be performed when keypair is loaded. |
119 virtual void OnPostKeypairLoadedActions() = 0; | 82 virtual void OnPostKeypairLoadedActions() = 0; |
120 | 83 |
121 scoped_refptr<ownership::PublicKey> public_key_; | 84 scoped_refptr<ownership::PublicKey> public_key_; |
122 | 85 |
123 scoped_refptr<ownership::PrivateKey> private_key_; | 86 scoped_refptr<ownership::PrivateKey> private_key_; |
124 | 87 |
125 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 88 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
126 | 89 |
127 std::vector<IsOwnerCallback> pending_is_owner_callbacks_; | 90 std::vector<IsOwnerCallback> pending_is_owner_callbacks_; |
128 | 91 |
129 ObserverList<Observer> observers_; | |
130 | |
131 base::ThreadChecker thread_checker_; | 92 base::ThreadChecker thread_checker_; |
132 | 93 |
133 private: | 94 private: |
134 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | 95 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; |
135 | 96 |
136 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | 97 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); |
137 }; | 98 }; |
138 | 99 |
139 } // namespace ownership | 100 } // namespace ownership |
140 | 101 |
141 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | 102 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
OLD | NEW |