| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "chrome/browser/chromeos/login/owner_manager.h" | |
| 13 | |
| 14 // There are two operations that can be performed on the Chrome OS owner-signed | |
| 15 // settings store: Storing and Retrieving the policy blob. | |
| 16 // | |
| 17 // The pattern of use here is that the caller instantiates some | |
| 18 // subclass of SignedSettings by calling one of the create | |
| 19 // methods. Then, call Execute() on this object from the UI | |
| 20 // thread. It'll go off and do work (on the FILE thread and over DBus), | |
| 21 // and then call the appropriate method of the Delegate you passed in | |
| 22 // -- again, on the UI thread. | |
| 23 | |
| 24 namespace enterprise_management { | |
| 25 class PolicyData; | |
| 26 class PolicyFetchResponse; | |
| 27 } // namespace enterprise_management | |
| 28 | |
| 29 namespace chromeos { | |
| 30 class OwnershipService; | |
| 31 | |
| 32 extern const char kDevicePolicyType[]; | |
| 33 | |
| 34 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, | |
| 35 public OwnerManager::Delegate { | |
| 36 public: | |
| 37 enum ReturnCode { | |
| 38 SUCCESS, | |
| 39 NOT_FOUND, // Email address or property name not found. | |
| 40 KEY_UNAVAILABLE, // Owner key not yet configured. | |
| 41 OPERATION_FAILED, // IPC to signed settings daemon failed. | |
| 42 BAD_SIGNATURE // Signature verification failed. | |
| 43 }; | |
| 44 | |
| 45 template <class T> | |
| 46 class Delegate { | |
| 47 public: | |
| 48 // This method will be called on the UI thread. | |
| 49 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {} | |
| 50 }; | |
| 51 | |
| 52 SignedSettings(); | |
| 53 | |
| 54 // These are both "policy" operations, and only one instance of | |
| 55 // one type can be in flight at a time. | |
| 56 static SignedSettings* CreateStorePolicyOp( | |
| 57 enterprise_management::PolicyFetchResponse* policy, | |
| 58 SignedSettings::Delegate<bool>* d); | |
| 59 | |
| 60 static SignedSettings* CreateRetrievePolicyOp( | |
| 61 SignedSettings::Delegate< | |
| 62 const enterprise_management::PolicyFetchResponse&>* d); | |
| 63 | |
| 64 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code); | |
| 65 | |
| 66 virtual void Execute() = 0; | |
| 67 | |
| 68 virtual void Fail(ReturnCode code) = 0; | |
| 69 | |
| 70 // Implementation of OwnerManager::Delegate | |
| 71 virtual void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | |
| 72 const std::vector<uint8>& payload) = 0; | |
| 73 | |
| 74 protected: | |
| 75 virtual ~SignedSettings(); | |
| 76 | |
| 77 static bool PolicyIsSane( | |
| 78 const enterprise_management::PolicyFetchResponse& value, | |
| 79 enterprise_management::PolicyData* poldata); | |
| 80 | |
| 81 void set_service(OwnershipService* service) { service_ = service; } | |
| 82 | |
| 83 OwnershipService* service_; | |
| 84 | |
| 85 private: | |
| 86 friend class base::RefCountedThreadSafe<SignedSettings>; | |
| 87 friend class SignedSettingsTest; | |
| 88 friend class SignedSettingsHelperTest; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(SignedSettings); | |
| 91 }; | |
| 92 | |
| 93 } // namespace chromeos | |
| 94 | |
| 95 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | |
| OLD | NEW |