blob: 29fa546b9bc3d6376589cf82a2fff9130fb3a6b4 [file] [log] [blame]
Alex Deymo8c499142014-01-02 19:33:34 -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_VARIABLE_H
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_VARIABLE_H
7
8#include <string>
9
10#include <base/time.h>
Alex Deymoca0aaa62014-01-06 10:39:58 -080011#include <gtest/gtest_prod.h> // for FRIEND_TEST
Alex Deymo8c499142014-01-02 19:33:34 -080012
13namespace chromeos_policy_manager {
14
Alex Deymo391ad9f2014-01-29 14:36:20 -080015// This class is a base class with the common functionality that doesn't
16// deppend on the variable's type, implemented by all the variables.
17class BaseVariable {
Alex Deymo8c499142014-01-02 19:33:34 -080018 public:
Alex Deymo391ad9f2014-01-29 14:36:20 -080019 BaseVariable(const std::string& name) : name_(name) {}
20 virtual ~BaseVariable() {}
21
22 // Returns the variable name as a string.
23 virtual const std::string& GetName() {
24 return name_;
25 }
26
27 private:
28 // The variable's name as a string.
29 const std::string name_;
30};
31
32// Interface to a Policy Manager variable of a given type. Implementation
33// internals are hidden as protected members, since policies should not be
34// using them directly.
35template<typename T>
36class Variable : public BaseVariable {
37 public:
38 Variable(const std::string& name) : BaseVariable(name) {}
Alex Deymo8c499142014-01-02 19:33:34 -080039 virtual ~Variable() {}
40
41 protected:
Alex Deymo23949d42014-02-05 15:20:59 -080042 // Only allow to get values through the EvaluationContext class and not
43 // directly from the variable.
44 friend class EvaluationContext;
45
Alex Deymobb019fe2014-02-03 20:12:17 -080046 friend class PmRealRandomProviderTest;
47 FRIEND_TEST(PmRealRandomProviderTest, GetRandomValues);
Alex Deymoca0aaa62014-01-06 10:39:58 -080048
Alex Deymo8c499142014-01-02 19:33:34 -080049 // Gets the current value of the variable. The current value is copied to a
50 // new object and returned. The caller of this method owns the object and
51 // should delete it.
52 //
53 // In case of and error getting the current value or the |timeout| timeout is
54 // exceeded, a NULL value is returned and the |errmsg| is set.
55 //
56 // The caller can pass a NULL value for |errmsg|, in which case the error
57 // message won't be set.
58 virtual const T* GetValue(base::TimeDelta timeout, std::string* errmsg) = 0;
59};
60
61} // namespace chromeos_policy_manager
62
63#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_VARIABLE_H