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