| 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_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 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.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 "chrome/browser/chromeos/login/owner_manager.h" | 15 #include "chrome/browser/chromeos/login/owner_manager.h" |
| 16 | 16 |
| 17 // There are two categories of operations that can be performed on the | 17 // There are two operations that can be performed on the Chrome OS owner-signed |
| 18 // Chrome OS owner-signed settings store: | 18 // settings store: Storing and Retrieving the policy blob. |
| 19 // 1) doing stuff to the whitelist (adding/removing/checking) | |
| 20 // 2) Storing/Retrieving arbitrary name=value pairs | |
| 21 // | 19 // |
| 22 // Unfortunately, it is currently a limitation that only one of each | |
| 23 // category can be in-flight at a time. You can be doing exactly one thing | |
| 24 // to the whitelist, and exactly one thing to the property store at a time. | |
| 25 // I've filed an issue on me to remove that restriction. | |
| 26 // http://code.google.com/p/chromium-os/issues/detail?id=6415 | |
| 27 | |
| 28 // The pattern of use here is that the caller instantiates some | 20 // The pattern of use here is that the caller instantiates some |
| 29 // subclass of SignedSettings by calling one of the create | 21 // subclass of SignedSettings by calling one of the create |
| 30 // methods. Then, call Execute() on this object from the UI | 22 // methods. Then, call Execute() on this object from the UI |
| 31 // thread. It'll go off and do work (on the FILE thread and over DBus), | 23 // thread. It'll go off and do work (on the FILE thread and over DBus), |
| 32 // and then call the appropriate method of the Delegate you passed in | 24 // and then call the appropriate method of the Delegate you passed in |
| 33 // -- again, on the UI thread. | 25 // -- again, on the UI thread. |
| 34 | 26 |
| 35 namespace base { | 27 namespace base { |
| 36 class Value; | 28 class Value; |
| 37 } // namespace base | 29 } // namespace base |
| 38 | 30 |
| 39 namespace enterprise_management { | 31 namespace enterprise_management { |
| 40 class PolicyFetchResponse; | 32 class PolicyFetchResponse; |
| 41 class PolicyData; | 33 class PolicyData; |
| 42 } // namespace enterprise_management | 34 } // namespace enterprise_management |
| 43 namespace em = enterprise_management; | 35 namespace em = enterprise_management; |
| 44 | 36 |
| 45 namespace chromeos { | 37 namespace chromeos { |
| 46 class OwnershipService; | 38 class OwnershipService; |
| 47 | 39 |
| 40 extern const char kDevicePolicyType[]; |
| 41 |
| 48 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, | 42 class SignedSettings : public base::RefCountedThreadSafe<SignedSettings>, |
| 49 public OwnerManager::Delegate { | 43 public OwnerManager::Delegate { |
| 50 public: | 44 public: |
| 51 enum ReturnCode { | 45 enum ReturnCode { |
| 52 SUCCESS, | 46 SUCCESS, |
| 53 NOT_FOUND, // Email address or property name not found. | 47 NOT_FOUND, // Email address or property name not found. |
| 54 KEY_UNAVAILABLE, // Owner key not yet configured. | 48 KEY_UNAVAILABLE, // Owner key not yet configured. |
| 55 OPERATION_FAILED, // IPC to signed settings daemon failed. | 49 OPERATION_FAILED, // IPC to signed settings daemon failed. |
| 56 BAD_SIGNATURE // Signature verification failed. | 50 BAD_SIGNATURE // Signature verification failed. |
| 57 }; | 51 }; |
| 58 | 52 |
| 59 template <class T> | 53 template <class T> |
| 60 class Delegate { | 54 class Delegate { |
| 61 public: | 55 public: |
| 62 // This method will be called on the UI thread. | 56 // This method will be called on the UI thread. |
| 63 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {} | 57 virtual void OnSettingsOpCompleted(ReturnCode code, T value) {} |
| 64 }; | 58 }; |
| 65 | 59 |
| 66 SignedSettings(); | 60 SignedSettings(); |
| 67 virtual ~SignedSettings(); | 61 virtual ~SignedSettings(); |
| 68 | 62 |
| 69 // These are both "property" operations, and only one instance of | |
| 70 // one type can be in flight at a time. | |
| 71 static SignedSettings* CreateStorePropertyOp( | |
| 72 const std::string& name, | |
| 73 const base::Value& value, | |
| 74 SignedSettings::Delegate<bool>* d); | |
| 75 | |
| 76 static SignedSettings* CreateRetrievePropertyOp( | |
| 77 const std::string& name, | |
| 78 SignedSettings::Delegate<const base::Value*>* d); | |
| 79 | |
| 80 // These are both "policy" operations, and only one instance of | 63 // These are both "policy" operations, and only one instance of |
| 81 // one type can be in flight at a time. | 64 // one type can be in flight at a time. |
| 82 static SignedSettings* CreateStorePolicyOp( | 65 static SignedSettings* CreateStorePolicyOp( |
| 83 em::PolicyFetchResponse* policy, | 66 em::PolicyFetchResponse* policy, |
| 84 SignedSettings::Delegate<bool>* d); | 67 SignedSettings::Delegate<bool>* d); |
| 85 | 68 |
| 86 static SignedSettings* CreateRetrievePolicyOp( | 69 static SignedSettings* CreateRetrievePolicyOp( |
| 87 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d); | 70 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d); |
| 88 | 71 |
| 89 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code); | 72 static ReturnCode MapKeyOpCode(OwnerManager::KeyOpCode code); |
| 90 | 73 |
| 91 virtual void Execute() = 0; | 74 virtual void Execute() = 0; |
| 92 | 75 |
| 93 virtual void Fail(ReturnCode code) = 0; | 76 virtual void Fail(ReturnCode code) = 0; |
| 94 | 77 |
| 95 // Implementation of OwnerManager::Delegate | 78 // Implementation of OwnerManager::Delegate |
| 96 virtual void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 79 virtual void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| 97 const std::vector<uint8>& payload) = 0; | 80 const std::vector<uint8>& payload) = 0; |
| 98 | 81 |
| 99 protected: | 82 protected: |
| 100 static bool PolicyIsSane(const em::PolicyFetchResponse& value, | 83 static bool PolicyIsSane(const em::PolicyFetchResponse& value, |
| 101 em::PolicyData* poldata); | 84 em::PolicyData* poldata); |
| 102 | 85 |
| 103 void set_service(OwnershipService* service) { service_ = service; } | 86 void set_service(OwnershipService* service) { service_ = service; } |
| 104 | 87 |
| 105 void TryToFetchPolicyAndCallBack(); | |
| 106 | |
| 107 OwnershipService* service_; | 88 OwnershipService* service_; |
| 108 | 89 |
| 109 private: | 90 private: |
| 110 friend class SignedSettingsTest; | 91 friend class SignedSettingsTest; |
| 111 friend class SignedSettingsHelperTest; | 92 friend class SignedSettingsHelperTest; |
| 112 | 93 |
| 113 class Relay | |
| 114 : public SignedSettings::Delegate<const em::PolicyFetchResponse&> { | |
| 115 public: | |
| 116 // |s| must outlive your Relay instance. | |
| 117 explicit Relay(SignedSettings* s); | |
| 118 virtual ~Relay(); | |
| 119 // Implementation of SignedSettings::Delegate | |
| 120 virtual void OnSettingsOpCompleted( | |
| 121 SignedSettings::ReturnCode code, | |
| 122 const em::PolicyFetchResponse& value) OVERRIDE; | |
| 123 private: | |
| 124 SignedSettings* settings_; | |
| 125 DISALLOW_COPY_AND_ASSIGN(Relay); | |
| 126 }; | |
| 127 | |
| 128 // Format of this string is documented in device_management_backend.proto. | |
| 129 static const char kDevicePolicyType[]; | |
| 130 | |
| 131 scoped_ptr<Relay> relay_; | |
| 132 scoped_refptr<SignedSettings> polfetcher_; | |
| 133 DISALLOW_COPY_AND_ASSIGN(SignedSettings); | 94 DISALLOW_COPY_AND_ASSIGN(SignedSettings); |
| 134 }; | 95 }; |
| 135 | 96 |
| 136 } // namespace chromeos | 97 } // namespace chromeos |
| 137 | 98 |
| 138 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ | 99 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_H_ |
| OLD | NEW |