blob: b184cf593d132e2e5b1c321a38eabbf309c0ec71 [file] [log] [blame]
Alex Deymoca0aaa62014-01-06 10:39:58 -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
Gilad Arnold2cbb3852014-03-07 12:40:50 -08005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H_
Alex Deymoca0aaa62014-01-06 10:39:58 -08007
Alex Deymobb019fe2014-02-03 20:12:17 -08008#include <base/memory/scoped_ptr.h>
9
Alex Deymo6e97bb22014-02-05 16:46:16 -080010#include "update_engine/policy_manager/provider.h"
11#include "update_engine/policy_manager/variable.h"
Alex Deymoca0aaa62014-01-06 10:39:58 -080012
13namespace chromeos_policy_manager {
14
15// Provider of random values.
Gilad Arnoldb33e1982014-01-27 14:46:27 -080016class RandomProvider : public Provider {
Alex Deymoca0aaa62014-01-06 10:39:58 -080017 public:
Alex Deymobb019fe2014-02-03 20:12:17 -080018 // 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.
Alex Deymo540d9422014-02-27 11:17:31 -080022 Variable<uint64_t>* var_seed() const { return var_seed_.get(); }
Alex Deymoca0aaa62014-01-06 10:39:58 -080023
Gilad Arnoldb33e1982014-01-27 14:46:27 -080024 protected:
Alex Deymobb019fe2014-02-03 20:12:17 -080025 RandomProvider() {}
26
Alex Deymo540d9422014-02-27 11:17:31 -080027 void set_var_seed(Variable<uint64_t>* var_seed) {
28 var_seed_.reset(var_seed);
29 }
Alex Deymoca0aaa62014-01-06 10:39:58 -080030
31 private:
Alex Deymo540d9422014-02-27 11:17:31 -080032 // The seed() scoped variable.
33 scoped_ptr<Variable<uint64_t>> var_seed_;
34
Alex Deymoca0aaa62014-01-06 10:39:58 -080035 DISALLOW_COPY_AND_ASSIGN(RandomProvider);
36};
37
38} // namespace chromeos_policy_manager
39
Gilad Arnold2cbb3852014-03-07 12:40:50 -080040#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_RANDOM_PROVIDER_H_