Alex Deymo | 23949d4 | 2014-02-05 15:20:59 -0800 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS 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 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame^] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_ |
Alex Deymo | 23949d4 | 2014-02-05 15:20:59 -0800 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | |
Alex Deymo | 7b948f0 | 2014-03-10 17:01:10 -0700 | [diff] [blame] | 10 | #include <base/memory/ref_counted.h> |
| 11 | |
Alex Deymo | 23949d4 | 2014-02-05 15:20:59 -0800 | [diff] [blame] | 12 | #include "update_engine/policy_manager/variable.h" |
| 13 | #include "update_engine/policy_manager/boxed_value.h" |
| 14 | |
| 15 | namespace chromeos_policy_manager { |
| 16 | |
| 17 | // The EvaluationContext class is the interface between a policy implementation |
| 18 | // and the state. The EvaluationContext tracks the variables used by a policy |
| 19 | // request and caches the returned values, owning those cached values. |
Alex Deymo | 7b948f0 | 2014-03-10 17:01:10 -0700 | [diff] [blame] | 20 | class EvaluationContext : public base::RefCounted<EvaluationContext> { |
Alex Deymo | 23949d4 | 2014-02-05 15:20:59 -0800 | [diff] [blame] | 21 | public: |
| 22 | EvaluationContext() {} |
| 23 | |
| 24 | // Returns a pointer to the value returned by the passed variable |var|. The |
| 25 | // EvaluationContext instance keeps the ownership of the returned object. The |
| 26 | // returned object is valid during the life of the EvaluationContext, even if |
| 27 | // the passed Variable changes it. |
| 28 | // |
| 29 | // In case of error, a NULL value is returned. |
| 30 | template<typename T> |
| 31 | const T* GetValue(Variable<T>* var); |
| 32 | |
| 33 | private: |
| 34 | // The remaining time for the current evaluation. |
| 35 | base::TimeDelta RemainingTime() const; |
| 36 | |
| 37 | // A map to hold the cached values for every variable. |
| 38 | typedef std::map<BaseVariable*, BoxedValue> ValueCacheMap; |
| 39 | |
| 40 | // The cached values of the called Variables. |
| 41 | ValueCacheMap value_cache_; |
| 42 | |
| 43 | DISALLOW_COPY_AND_ASSIGN(EvaluationContext); |
| 44 | }; |
| 45 | |
| 46 | } // namespace chromeos_policy_manager |
| 47 | |
| 48 | // Include the implementation of the template methods. |
| 49 | #include "update_engine/policy_manager/evaluation_context-inl.h" |
| 50 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame^] | 51 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_ |