Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -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 | |
Gilad Arnold | 2d2ee5f | 2014-02-02 20:49:12 -0800 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 7 | |
Alex Deymo | bb019fe | 2014-02-03 20:12:17 -0800 | [diff] [blame^] | 8 | #include <base/memory/scoped_ptr.h> |
| 9 | |
Gilad Arnold | b33e198 | 2014-01-27 14:46:27 -0800 | [diff] [blame] | 10 | #include "policy_manager/provider.h" |
Alex Deymo | bb019fe | 2014-02-03 20:12:17 -0800 | [diff] [blame^] | 11 | #include "policy_manager/variable.h" |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_policy_manager { |
| 14 | |
| 15 | // Provider of random values. |
Gilad Arnold | b33e198 | 2014-01-27 14:46:27 -0800 | [diff] [blame] | 16 | class RandomProvider : public Provider { |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 17 | public: |
Alex Deymo | bb019fe | 2014-02-03 20:12:17 -0800 | [diff] [blame^] | 18 | // Return a random number every time it is requested. Note that values |
| 19 | // returned by the variables are cached by the EvaluationContext, so the |
| 20 | // returned value will be the same during the same policy request. If more |
| 21 | // random values are needed use a PRNG seeded with this value. |
| 22 | Variable<uint64_t>* seed() const { return seed_.get(); } |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 23 | |
Gilad Arnold | b33e198 | 2014-01-27 14:46:27 -0800 | [diff] [blame] | 24 | protected: |
Alex Deymo | bb019fe | 2014-02-03 20:12:17 -0800 | [diff] [blame^] | 25 | RandomProvider() {} |
| 26 | |
| 27 | // The seed() scoped variable. |
| 28 | scoped_ptr<Variable<uint64_t> > seed_; |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 29 | |
| 30 | private: |
Alex Deymo | ca0aaa6 | 2014-01-06 10:39:58 -0800 | [diff] [blame] | 31 | DISALLOW_COPY_AND_ASSIGN(RandomProvider); |
| 32 | }; |
| 33 | |
| 34 | } // namespace chromeos_policy_manager |
| 35 | |
Gilad Arnold | 2d2ee5f | 2014-02-02 20:49:12 -0800 | [diff] [blame] | 36 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H |