OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
6 #define COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/callback_forward.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "base/threading/thread_checker.h" | |
17 #include "components/keyed_service/core/keyed_service.h" | |
18 #include "components/ownership/ownership_export.h" | |
19 #include "policy/proto/device_management_backend.pb.h" | |
20 | |
21 namespace base { | |
22 class TaskRunner; | |
23 } | |
24 | |
25 namespace ownership { | |
26 class PublicKey; | |
27 class PrivateKey; | |
Nikita (slow)
2014/09/10 18:05:12
nit: sort
ygorshenin1
2014/09/11 14:06:20
Done.
| |
28 class OwnerKeyUtil; | |
29 | |
30 class OWNERSHIP_EXPORT OwnerSettingsService : public KeyedService { | |
Nikita (slow)
2014/09/10 18:05:12
nit: Add comment.
ygorshenin1
2014/09/11 14:06:20
Done.
| |
31 public: | |
32 typedef base::Callback<void(std::string policy_blob)> | |
33 AssembleAndSignPolicyAsyncCallback; | |
34 | |
35 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; | |
36 | |
37 explicit OwnerSettingsService( | |
38 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | |
39 virtual ~OwnerSettingsService(); | |
40 | |
41 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { | |
42 return weak_factory_.GetWeakPtr(); | |
43 } | |
44 | |
45 // Returns whether current user is owner or not. When this method | |
46 // is called too early, incorrect result can be returned because | |
47 // private key loading may be in progress. | |
48 bool IsOwner(); | |
49 | |
50 // Determines whether current user is owner or not, responds via | |
51 // |callback|. | |
52 void IsOwnerAsync(const IsOwnerCallback& callback); | |
53 | |
54 // Assembles and signs |policy| on the |task_runner|, responds on | |
55 // the original thread via |callback|. | |
56 bool AssembleAndSignPolicyAsync( | |
57 base::TaskRunner* task_runner, | |
58 scoped_ptr<enterprise_management::PolicyData> policy, | |
59 const AssembleAndSignPolicyAsyncCallback& callback); | |
60 | |
61 // Signs |settings| with the private half of the owner key and sends | |
62 // the resulting policy blob for storage. The | |
63 // result of the operation is reported through |callback|. | |
64 virtual void SignAndStorePolicyAsync( | |
65 scoped_ptr<enterprise_management::PolicyData> policy, | |
66 const base::Closure& callback) = 0; | |
67 | |
68 protected: | |
69 void ReloadKeypair(); | |
70 | |
71 void OnKeypairLoaded(const scoped_refptr<PublicKey>& public_key, | |
72 const scoped_refptr<PrivateKey>& private_key); | |
73 | |
74 // Platform-specific keypair loading algorithm. | |
75 virtual void ReloadKeypairImpl(const base::Callback< | |
76 void(const scoped_refptr<PublicKey>& public_key, | |
77 const scoped_refptr<PrivateKey>& private_key)>& callback) = 0; | |
78 | |
79 // Plafrom-specific actions which should be performed when keypair is loaded. | |
80 virtual void OnPostKeypairLoadedActions() = 0; | |
81 | |
82 scoped_refptr<ownership::PublicKey> public_key_; | |
83 | |
84 scoped_refptr<ownership::PrivateKey> private_key_; | |
85 | |
86 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | |
87 | |
88 std::vector<IsOwnerCallback> pending_is_owner_callbacks_; | |
89 | |
90 base::ThreadChecker thread_checker_; | |
91 | |
92 private: | |
93 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | |
96 }; | |
97 | |
98 } // namespace ownership | |
99 | |
100 #endif // COMPONENTS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
OLD | NEW |