blob: d95289949cc2c9ede1b39f74859c077ee6ef747e [file] [log] [blame]
Alex Deymoc705cc82014-02-19 11:15:00 -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_POLICY_MANAGER_H
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_MANAGER_H
7
8#include <base/memory/scoped_ptr.h>
9
10#include "update_engine/policy_manager/default_policy.h"
11#include "update_engine/policy_manager/policy.h"
12#include "update_engine/policy_manager/random_provider.h"
13
14namespace chromeos_policy_manager {
15
16// The main Policy Manager singleton class.
17class PolicyManager {
18 public:
19 PolicyManager() {}
20
21 // Initializes the PolicyManager instance. Returns whether the initialization
22 // succeeded.
23 bool Init();
24
25 // PolicyRequest() evaluates the given policy with the provided arguments and
26 // returns the result. The |policy_method| is the pointer-to-method of the
27 // Policy class for the policy request to call. The PolicyManager will call
28 // this method on the right policy. The pointer |result| must not be NULL and
29 // the remaining |args| depend on the arguments required by the passed
30 // |policy_method|.
31 //
32 // When the policy request succeeds, the |result| is set and the method
33 // returns EvalStatusSucceeded, otherwise, the |result| may not be set. Also,
34 // if the policy implementation should block, this method returns immediately
35 // with EvalStatusAskMeAgainLater. In case of failure EvalStatusFailed is
36 // returned and the |error| message is set, which must not be NULL.
37 //
38 // An example call to this method is:
39 // pm.PolicyRequest(&Policy::SomePolicyMethod, &bool_result, arg1, arg2);
40 template<typename T, typename R, typename... Args>
41 EvalStatus PolicyRequest(T policy_method , R* result, Args... args);
42
43 private:
44 friend class PmPolicyManagerTest;
45 FRIEND_TEST(PmPolicyManagerTest, PolicyRequestCallsPolicy);
46 FRIEND_TEST(PmPolicyManagerTest, PolicyRequestCallsDefaultOnError);
47 FRIEND_TEST(PmPolicyManagerTest, PolicyRequestDoesntBlock);
48
49 // The policy used by the PolicyManager. Note that since it is a const Policy,
50 // policy implementations are not allowed to persist state on this class.
51 scoped_ptr<const Policy> policy_;
52
53 // A safe default value to the current policy. This policy is used whenever
54 // a policy implementation fails with EvalStatusFailed.
55 const DefaultPolicy default_policy_;
56
57 // Providers.
58 scoped_ptr<RandomProvider> random_;
59
60 DISALLOW_COPY_AND_ASSIGN(PolicyManager);
61};
62
63} // namespace chromeos_policy_manager
64
65// Include the implementation of the template methods.
66#include "update_engine/policy_manager/policy_manager-inl.h"
67
68#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_MANAGER_H