Alex Deymo | 8c49914 | 2014-01-02 19:33:34 -0800 | [diff] [blame] | 1 | // 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 Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 11 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Alex Deymo | 8c49914 | 2014-01-02 19:33:34 -0800 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_policy_manager { |
| 14 | |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 15 | // 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. |
| 17 | class BaseVariable { |
Alex Deymo | 8c49914 | 2014-01-02 19:33:34 -0800 | [diff] [blame] | 18 | public: |
Alex Deymo | 391ad9f | 2014-01-29 14:36:20 -0800 | [diff] [blame] | 19 | 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. |
| 35 | template<typename T> |
| 36 | class Variable : public BaseVariable { |
| 37 | public: |
| 38 | Variable(const std::string& name) : BaseVariable(name) {} |
Alex Deymo | 8c49914 | 2014-01-02 19:33:34 -0800 | [diff] [blame] | 39 | virtual ~Variable() {} |
| 40 | |
| 41 | protected: |
Alex Deymo | bb019fe | 2014-02-03 20:12:17 -0800 | [diff] [blame] | 42 | friend class PmRealRandomProviderTest; |
| 43 | FRIEND_TEST(PmRealRandomProviderTest, GetRandomValues); |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 44 | |
Alex Deymo | 8c49914 | 2014-01-02 19:33:34 -0800 | [diff] [blame] | 45 | // 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 |