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/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 #include "components/ownership/ownership_export.h" | 18 #include "components/ownership/ownership_export.h" |
19 #include "policy/proto/device_management_backend.pb.h" | 19 #include "policy/proto/device_management_backend.pb.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class TaskRunner; | 22 class TaskRunner; |
| 23 class Value; |
23 } | 24 } |
24 | 25 |
25 namespace ownership { | 26 namespace ownership { |
26 class OwnerKeyUtil; | 27 class OwnerKeyUtil; |
27 class PrivateKey; | 28 class PrivateKey; |
28 class PublicKey; | 29 class PublicKey; |
29 | 30 |
30 // This class is a common interface for platform-specific classes | 31 // This class is a common interface for platform-specific classes |
31 // which deal with ownership, keypairs and owner-related settings. | 32 // which deal with ownership, keypairs and owner-related settings. |
32 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService { | 33 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService { |
33 public: | 34 public: |
34 typedef base::Callback<void(std::string policy_blob)> | 35 typedef base::Callback<void( |
| 36 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response)> |
35 AssembleAndSignPolicyAsyncCallback; | 37 AssembleAndSignPolicyAsyncCallback; |
36 | 38 |
37 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; | 39 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; |
38 | 40 |
39 explicit OwnerSettingsService( | 41 explicit OwnerSettingsService( |
40 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 42 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
41 virtual ~OwnerSettingsService(); | 43 virtual ~OwnerSettingsService(); |
42 | 44 |
43 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { | 45 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { |
44 return weak_factory_.GetWeakPtr(); | 46 return weak_factory_.GetWeakPtr(); |
45 } | 47 } |
46 | 48 |
47 // Returns whether current user is owner or not. When this method | 49 // Returns whether current user is owner or not. When this method |
48 // is called too early, incorrect result can be returned because | 50 // is called too early, incorrect result can be returned because |
49 // private key loading may be in progress. | 51 // private key loading may be in progress. |
50 bool IsOwner(); | 52 bool IsOwner(); |
51 | 53 |
52 // Determines whether current user is owner or not, responds via | 54 // Determines whether current user is owner or not, responds via |
53 // |callback|. | 55 // |callback|. |
54 void IsOwnerAsync(const IsOwnerCallback& callback); | 56 void IsOwnerAsync(const IsOwnerCallback& callback); |
55 | 57 |
56 // Assembles and signs |policy| on the |task_runner|, responds on | 58 // Assembles and signs |policy| on the |task_runner|, responds on |
57 // the original thread via |callback|. | 59 // the original thread via |callback|. |
58 bool AssembleAndSignPolicyAsync( | 60 bool AssembleAndSignPolicyAsync( |
59 base::TaskRunner* task_runner, | 61 base::TaskRunner* task_runner, |
60 scoped_ptr<enterprise_management::PolicyData> policy, | 62 scoped_ptr<enterprise_management::PolicyData> policy, |
61 const AssembleAndSignPolicyAsyncCallback& callback); | 63 const AssembleAndSignPolicyAsyncCallback& callback); |
62 | 64 |
63 // Signs |settings| with the private half of the owner key and sends | 65 // Checks whether |setting| is handled by OwnerSettingsService. |
64 // the resulting policy blob for storage. The | 66 virtual bool HandlesSetting(const std::string& setting) = 0; |
65 // result of the operation is reported through |callback|. | 67 |
66 virtual void SignAndStorePolicyAsync( | 68 // Sets |setting| value to |value|. |
67 scoped_ptr<enterprise_management::PolicyData> policy, | 69 virtual void Set(const std::string& setting, const base::Value& value) = 0; |
68 const base::Closure& callback) = 0; | 70 |
| 71 void SetBoolean(const std::string& setting, bool value); |
| 72 void SetInteger(const std::string& setting, int value); |
| 73 void SetDouble(const std::string& setting, double value); |
| 74 void SetString(const std::string& setting, const std::string& value); |
69 | 75 |
70 protected: | 76 protected: |
71 void ReloadKeypair(); | 77 void ReloadKeypair(); |
72 | 78 |
73 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, | 79 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, |
74 const scoped_refptr<PrivateKey>& private_key); | 80 const scoped_refptr<PrivateKey>& private_key); |
75 | 81 |
76 // Platform-specific keypair loading algorithm. | 82 // Platform-specific keypair loading algorithm. |
77 virtual void ReloadKeypairImpl(const base::Callback< | 83 virtual void ReloadKeypairImpl(const base::Callback< |
78 void(const scoped_refptr<PublicKey>& public_key, | 84 void(const scoped_refptr<PublicKey>& public_key, |
(...skipping 14 matching lines...) Expand all Loading... |
93 | 99 |
94 private: | 100 private: |
95 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | 101 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; |
96 | 102 |
97 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | 103 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); |
98 }; | 104 }; |
99 | 105 |
100 } // namespace ownership | 106 } // namespace ownership |
101 | 107 |
102 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | 108 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
OLD | NEW |