blob: 27998d60d9b8935b8849bdf40f78c7f4d16cee6b [file] [log] [blame]
Alex Deymo23949d42014-02-05 15:20:59 -08001// 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 Arnold2cbb3852014-03-07 12:40:50 -08005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_
Alex Deymo23949d42014-02-05 15:20:59 -08007
8#include <map>
9
Alex Deymo7b948f02014-03-10 17:01:10 -070010#include <base/memory/ref_counted.h>
11
Alex Deymo23949d42014-02-05 15:20:59 -080012#include "update_engine/policy_manager/variable.h"
13#include "update_engine/policy_manager/boxed_value.h"
14
15namespace 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 Deymo7b948f02014-03-10 17:01:10 -070020class EvaluationContext : public base::RefCounted<EvaluationContext> {
Alex Deymo23949d42014-02-05 15:20:59 -080021 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 Arnold2cbb3852014-03-07 12:40:50 -080051#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_EVALUATION_CONTEXT_H_