blob: ce239ce82ec2a5d28a55760af8ec228aa9f13a3c [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);
Gilad Arnold55f39b72014-01-28 12:51:45 -080048 friend class PmRealShillProviderTest;
49 FRIEND_TEST(PmRealShillProviderTest, DefaultValues);
Alex Deymoca0aaa62014-01-06 10:39:58 -080050
Alex Deymo8c499142014-01-02 19:33:34 -080051 // Gets the current value of the variable. The current value is copied to a
52 // new object and returned. The caller of this method owns the object and
53 // should delete it.
54 //
55 // In case of and error getting the current value or the |timeout| timeout is
56 // exceeded, a NULL value is returned and the |errmsg| is set.
57 //
58 // The caller can pass a NULL value for |errmsg|, in which case the error
59 // message won't be set.
60 virtual const T* GetValue(base::TimeDelta timeout, std::string* errmsg) = 0;
61};
62
63} // namespace chromeos_policy_manager
64
65#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_VARIABLE_H