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