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 <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.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/observer_list.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
19 #include "components/ownership/ownership_export.h" | 19 #include "components/ownership/ownership_export.h" |
20 #include "policy/proto/device_management_backend.pb.h" | 20 #include "policy/proto/device_management_backend.pb.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class TaskRunner; | 23 class TaskRunner; |
24 class Value; | 24 class Value; |
(...skipping 20 matching lines...) Expand all Loading... |
45 // policy is not signed and stored yet. | 45 // policy is not signed and stored yet. |
46 // | 46 // |
47 // TODO (ygorshenin@, crbug.com/230018): get rid of the method | 47 // TODO (ygorshenin@, crbug.com/230018): get rid of the method |
48 // since it creates DeviceSettingsService's dependency on | 48 // since it creates DeviceSettingsService's dependency on |
49 // OwnerSettingsService. | 49 // OwnerSettingsService. |
50 virtual void OnTentativeChangesInPolicy( | 50 virtual void OnTentativeChangesInPolicy( |
51 const enterprise_management::PolicyData& policy_data) {} | 51 const enterprise_management::PolicyData& policy_data) {} |
52 }; | 52 }; |
53 | 53 |
54 typedef base::Callback<void( | 54 typedef base::Callback<void( |
55 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response)> | 55 std::unique_ptr<enterprise_management::PolicyFetchResponse> |
| 56 policy_response)> |
56 AssembleAndSignPolicyAsyncCallback; | 57 AssembleAndSignPolicyAsyncCallback; |
57 | 58 |
58 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; | 59 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; |
59 | 60 |
60 explicit OwnerSettingsService( | 61 explicit OwnerSettingsService( |
61 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 62 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
62 ~OwnerSettingsService() override; | 63 ~OwnerSettingsService() override; |
63 | 64 |
64 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { | 65 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { |
65 return weak_factory_.GetWeakPtr(); | 66 return weak_factory_.GetWeakPtr(); |
66 } | 67 } |
67 | 68 |
68 void AddObserver(Observer* observer); | 69 void AddObserver(Observer* observer); |
69 | 70 |
70 void RemoveObserver(Observer* observer); | 71 void RemoveObserver(Observer* observer); |
71 | 72 |
72 // Returns whether current user is owner or not. When this method | 73 // Returns whether current user is owner or not. When this method |
73 // is called too early, incorrect result can be returned because | 74 // is called too early, incorrect result can be returned because |
74 // private key loading may be in progress. | 75 // private key loading may be in progress. |
75 bool IsOwner(); | 76 bool IsOwner(); |
76 | 77 |
77 // Determines whether current user is owner or not, responds via | 78 // Determines whether current user is owner or not, responds via |
78 // |callback|. | 79 // |callback|. |
79 void IsOwnerAsync(const IsOwnerCallback& callback); | 80 void IsOwnerAsync(const IsOwnerCallback& callback); |
80 | 81 |
81 // Assembles and signs |policy| on the |task_runner|, responds on | 82 // Assembles and signs |policy| on the |task_runner|, responds on |
82 // the original thread via |callback|. | 83 // the original thread via |callback|. |
83 bool AssembleAndSignPolicyAsync( | 84 bool AssembleAndSignPolicyAsync( |
84 base::TaskRunner* task_runner, | 85 base::TaskRunner* task_runner, |
85 scoped_ptr<enterprise_management::PolicyData> policy, | 86 std::unique_ptr<enterprise_management::PolicyData> policy, |
86 const AssembleAndSignPolicyAsyncCallback& callback); | 87 const AssembleAndSignPolicyAsyncCallback& callback); |
87 | 88 |
88 // Checks whether |setting| is handled by OwnerSettingsService. | 89 // Checks whether |setting| is handled by OwnerSettingsService. |
89 virtual bool HandlesSetting(const std::string& setting) = 0; | 90 virtual bool HandlesSetting(const std::string& setting) = 0; |
90 | 91 |
91 // Sets |setting| value to |value|. | 92 // Sets |setting| value to |value|. |
92 virtual bool Set(const std::string& setting, const base::Value& value) = 0; | 93 virtual bool Set(const std::string& setting, const base::Value& value) = 0; |
93 | 94 |
94 // Convenience functions for manipulating lists. Note that the following | 95 // Convenience functions for manipulating lists. Note that the following |
95 // functions employs a read, modify and write pattern. If there're | 96 // functions employs a read, modify and write pattern. If there're |
96 // pending updates to |setting|, value cache they read from might not | 97 // pending updates to |setting|, value cache they read from might not |
97 // be fresh and multiple calls to those function would lose data. | 98 // be fresh and multiple calls to those function would lose data. |
98 virtual bool AppendToList(const std::string& setting, | 99 virtual bool AppendToList(const std::string& setting, |
99 const base::Value& value) = 0; | 100 const base::Value& value) = 0; |
100 virtual bool RemoveFromList(const std::string& setting, | 101 virtual bool RemoveFromList(const std::string& setting, |
101 const base::Value& value) = 0; | 102 const base::Value& value) = 0; |
102 | 103 |
103 // Sets a bunch of device settings accumulated before ownership gets | 104 // Sets a bunch of device settings accumulated before ownership gets |
104 // established. | 105 // established. |
105 // | 106 // |
106 // TODO (ygorshenin@, crbug.com/230018): that this is a temporary | 107 // TODO (ygorshenin@, crbug.com/230018): that this is a temporary |
107 // solution and should be removed. | 108 // solution and should be removed. |
108 virtual bool CommitTentativeDeviceSettings( | 109 virtual bool CommitTentativeDeviceSettings( |
109 scoped_ptr<enterprise_management::PolicyData> policy) = 0; | 110 std::unique_ptr<enterprise_management::PolicyData> policy) = 0; |
110 | 111 |
111 bool SetBoolean(const std::string& setting, bool value); | 112 bool SetBoolean(const std::string& setting, bool value); |
112 bool SetInteger(const std::string& setting, int value); | 113 bool SetInteger(const std::string& setting, int value); |
113 bool SetDouble(const std::string& setting, double value); | 114 bool SetDouble(const std::string& setting, double value); |
114 bool SetString(const std::string& setting, const std::string& value); | 115 bool SetString(const std::string& setting, const std::string& value); |
115 | 116 |
116 protected: | 117 protected: |
117 void ReloadKeypair(); | 118 void ReloadKeypair(); |
118 | 119 |
119 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, | 120 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, |
(...skipping 21 matching lines...) Expand all Loading... |
141 | 142 |
142 private: | 143 private: |
143 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | 144 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; |
144 | 145 |
145 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | 146 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); |
146 }; | 147 }; |
147 | 148 |
148 } // namespace ownership | 149 } // namespace ownership |
149 | 150 |
150 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | 151 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
OLD | NEW |