OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 // thread. It'll go off and do work (on the FILE thread and over DBus), | 28 // thread. It'll go off and do work (on the FILE thread and over DBus), |
29 // and then call the appropriate method of the Delegate you passed in | 29 // and then call the appropriate method of the Delegate you passed in |
30 // -- again, on the UI thread. | 30 // -- again, on the UI thread. |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 class OwnershipService; | 33 class OwnershipService; |
34 | 34 |
35 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, | 35 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, |
36 public OwnerManager::Delegate { | 36 public OwnerManager::Delegate { |
37 public: | 37 public: |
38 enum FailureCode { | 38 enum ReturnCode { |
| 39 SUCCESS, |
39 NOT_FOUND, // Email address or property name not found. | 40 NOT_FOUND, // Email address or property name not found. |
40 KEY_UNAVAILABLE, // Owner key not yet configured. | 41 KEY_UNAVAILABLE, // Owner key not yet configured. |
41 OPERATION_FAILED // Signature op or IPC to signed settings daemon failed. | 42 OPERATION_FAILED // Signature op or IPC to signed settings daemon failed. |
42 }; | 43 }; |
43 | 44 |
44 template <class T> | 45 template <class T> |
45 class Delegate { | 46 class Delegate { |
46 public: | 47 public: |
47 // These methods will be called on the UI thread. | 48 // This method will be called on the UI thread. |
48 virtual void OnSettingsOpSucceeded(T value) {} | 49 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {} |
49 virtual void OnSettingsOpFailed(FailureCode code) {} | |
50 }; | 50 }; |
51 | 51 |
52 SignedSettings(); | 52 SignedSettings(); |
53 virtual ~SignedSettings(); | 53 virtual ~SignedSettings(); |
54 | 54 |
55 // These are both "whitelist" operations, and only one instance of | 55 // These are both "whitelist" operations, and only one instance of |
56 // one type can be in flight at a time. | 56 // one type can be in flight at a time. |
57 static SignedSettings* CreateCheckWhitelistOp( | 57 static SignedSettings* CreateCheckWhitelistOp( |
58 const std::string& email, | 58 const std::string& email, |
59 SignedSettings::Delegate<bool>* d); | 59 SignedSettings::Delegate<bool>* d); |
60 | 60 |
61 static SignedSettings* CreateWhitelistOp(const std::string& email, | 61 static SignedSettings* CreateWhitelistOp(const std::string& email, |
62 bool add_to_whitelist, | 62 bool add_to_whitelist, |
63 SignedSettings::Delegate<bool>* d); | 63 SignedSettings::Delegate<bool>* d); |
64 | 64 |
65 // These are both "property" operations, and only one instance of | 65 // These are both "property" operations, and only one instance of |
66 // one type can be in flight at a time. | 66 // one type can be in flight at a time. |
67 static SignedSettings* CreateStorePropertyOp( | 67 static SignedSettings* CreateStorePropertyOp( |
68 const std::string& name, | 68 const std::string& name, |
69 const std::string& value, | 69 const std::string& value, |
70 SignedSettings::Delegate<bool>* d); | 70 SignedSettings::Delegate<bool>* d); |
71 | 71 |
72 static SignedSettings* CreateRetrievePropertyOp( | 72 static SignedSettings* CreateRetrievePropertyOp( |
73 const std::string& name, | 73 const std::string& name, |
74 SignedSettings::Delegate<std::string>* d); | 74 SignedSettings::Delegate<std::string>* d); |
75 | 75 |
76 static FailureCode MapKeyOpCode(OwnerManager::KeyOpCode code); | 76 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code); |
77 | 77 |
78 virtual void Execute() = 0; | 78 virtual void Execute() = 0; |
79 | 79 |
80 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() | 80 // Implementation of OwnerManager::Delegate::OnKeyOpComplete() |
81 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 81 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
82 const std::vector<uint8>& payload) = 0; | 82 const std::vector<uint8>& payload) = 0; |
83 | 83 |
84 protected: | 84 protected: |
85 OwnershipService* service_; | 85 OwnershipService* service_; |
86 | 86 |
87 private: | 87 private: |
88 friend class SignedSettingsTest; | 88 friend class SignedSettingsTest; |
89 friend class SignedSettingsHelperTest; | 89 friend class SignedSettingsHelperTest; |
90 | 90 |
91 void set_service(OwnershipService* service) { service_ = service; } | 91 void set_service(OwnershipService* service) { service_ = service; } |
92 }; | 92 }; |
93 | 93 |
94 } // namespace chromeos | 94 } // namespace chromeos |
95 | 95 |
96 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | 96 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ |
OLD | NEW |