blob: 9b933d71d441a0a2b60aaf46250db6129220c0da [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:
Gilad Arnoldb33e1982014-01-27 14:46:27 -080042 friend class PmRandomProviderTest;
43 FRIEND_TEST(PmRandomProviderTest, GetRandomValues);
Alex Deymoca0aaa62014-01-06 10:39:58 -080044
Alex Deymo8c499142014-01-02 19:33:34 -080045 // Gets the current value of the variable. The current value is copied to a
46 // new object and returned. The caller of this method owns the object and
47 // should delete it.
48 //
49 // In case of and error getting the current value or the |timeout| timeout is
50 // exceeded, a NULL value is returned and the |errmsg| is set.
51 //
52 // The caller can pass a NULL value for |errmsg|, in which case the error
53 // message won't be set.
54 virtual const T* GetValue(base::TimeDelta timeout, std::string* errmsg) = 0;
55};
56
57} // namespace chromeos_policy_manager
58
59#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_VARIABLE_H