OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "chrome/browser/chromeos/login/signed_settings.h" | 11 #include "chrome/browser/chromeos/login/signed_settings.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class Value; | 14 class Value; |
15 } // namespace base | 15 } // namespace base |
16 | 16 |
17 namespace enterprise_management { | 17 namespace enterprise_management { |
18 class PolicyFetchResponse; | 18 class PolicyFetchResponse; |
19 } // namespace enterprise_management | 19 } // namespace enterprise_management |
20 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 class SignedSettings; | 23 class SignedSettings; |
24 | 24 |
25 // Helper to serialize signed settings ops, provide unified callback interface, | 25 // Helper to serialize signed settings ops, provide unified callback interface, |
26 // and handle callbacks destruction before ops completion. | 26 // and handle callbacks destruction before ops completion. |
27 class SignedSettingsHelper { | 27 class SignedSettingsHelper { |
28 public: | 28 public: |
29 class Callback { | 29 typedef base::Callback<void(SignedSettings::ReturnCode)> StorePolicyCallback; |
30 public: | 30 typedef base::Callback<void(SignedSettings::ReturnCode, |
31 // Callback of StorePropertyOp. | 31 const em::PolicyFetchResponse&)> RetrievePolicyCallback; |
32 virtual void OnStorePropertyCompleted( | |
33 SignedSettings::ReturnCode code, | |
34 const std::string& name, | |
35 const base::Value& value) {} | |
36 | |
37 // Callback of RetrievePropertyOp. | |
38 virtual void OnRetrievePropertyCompleted( | |
39 SignedSettings::ReturnCode code, | |
40 const std::string& name, | |
41 const base::Value* value) {} | |
42 | |
43 // Callback of StorePolicyOp. | |
44 virtual void OnStorePolicyCompleted( | |
45 SignedSettings::ReturnCode code) {} | |
46 | |
47 // Callback of RetrievePolicyOp. | |
48 virtual void OnRetrievePolicyCompleted( | |
49 SignedSettings::ReturnCode code, | |
50 const em::PolicyFetchResponse& policy) {} | |
51 }; | |
52 | 32 |
53 // Class factory | 33 // Class factory |
54 static SignedSettingsHelper* Get(); | 34 static SignedSettingsHelper* Get(); |
55 | 35 |
56 // Functions to start signed settings ops. | 36 // Functions to start signed settings ops. |
57 virtual void StartStorePropertyOp(const std::string& name, | 37 virtual void StartStorePolicyOp( |
58 const base::Value& value, | 38 const em::PolicyFetchResponse& policy, |
59 Callback* callback) = 0; | 39 StorePolicyCallback callback) = 0; |
60 virtual void StartRetrieveProperty(const std::string& name, | 40 virtual void StartRetrievePolicyOp( |
61 Callback* callback) = 0; | 41 RetrievePolicyCallback callback) = 0; |
62 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, | |
63 Callback* callback) = 0; | |
64 virtual void StartRetrievePolicyOp(Callback* callback) = 0; | |
65 | |
66 // Cancels all pending calls of given callback. | |
67 virtual void CancelCallback(Callback* callback) = 0; | |
68 | 42 |
69 class TestDelegate { | 43 class TestDelegate { |
70 public: | 44 public: |
71 virtual void OnOpCreated(SignedSettings* op) = 0; | 45 virtual void OnOpCreated(SignedSettings* op) = 0; |
72 virtual void OnOpStarted(SignedSettings* op) = 0; | 46 virtual void OnOpStarted(SignedSettings* op) = 0; |
73 virtual void OnOpCompleted(SignedSettings* op) = 0; | 47 virtual void OnOpCompleted(SignedSettings* op) = 0; |
74 }; | 48 }; |
75 | 49 |
76 #if defined(UNIT_TEST) | 50 #if defined(UNIT_TEST) |
77 void set_test_delegate(TestDelegate* test_delegate) { | 51 void set_test_delegate(TestDelegate* test_delegate) { |
78 test_delegate_ = test_delegate; | 52 test_delegate_ = test_delegate; |
79 } | 53 } |
80 #endif // defined(UNIT_TEST) | 54 #endif // defined(UNIT_TEST) |
81 | 55 |
82 protected: | 56 protected: |
83 SignedSettingsHelper() : test_delegate_(NULL) { | 57 SignedSettingsHelper() : test_delegate_(NULL) { |
84 } | 58 } |
85 | 59 |
86 TestDelegate* test_delegate_; | 60 TestDelegate* test_delegate_; |
87 }; | 61 }; |
88 | 62 |
89 } // namespace chromeos | 63 } // namespace chromeos |
90 | 64 |
91 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ | 65 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ |
OLD | NEW |