blob: 54bbe3eb889795d6e466979293baa285a8bdf06f [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
Gilad Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_DEFAULT_POLICY_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_DEFAULT_POLICY_H_
7
8#include <string>
Alex Deymoc705cc82014-02-19 11:15:00 -08009
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070010#include <base/time/time.h>
11
Alex Deymo63784a52014-05-28 10:46:14 -070012#include "update_engine/update_manager/policy.h"
Alex Deymoc705cc82014-02-19 11:15:00 -080013
Alex Deymo63784a52014-05-28 10:46:14 -070014namespace chromeos_update_manager {
Alex Deymoc705cc82014-02-19 11:15:00 -080015
16// The DefaultPolicy is a safe Policy implementation that doesn't fail. The
17// values returned by this policy are safe default in case of failure of the
Alex Deymo63784a52014-05-28 10:46:14 -070018// actual policy being used by the UpdateManager.
Alex Deymoc705cc82014-02-19 11:15:00 -080019class DefaultPolicy : public Policy {
20 public:
21 DefaultPolicy() {}
22 virtual ~DefaultPolicy() {}
23
24 // Policy overrides.
Alex Deymo0d11c602014-04-23 20:12:20 -070025 virtual EvalStatus UpdateCheckAllowed(
26 EvaluationContext* ec, State* state, std::string* error,
27 UpdateCheckParams* result) const override {
28 result->updates_enabled = true;
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -070029 return EvalStatus::kSucceeded;
30 }
31
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070032 virtual EvalStatus UpdateCanStart(
33 EvaluationContext* ec,
34 State* state,
35 std::string* error,
36 UpdateCanStartResult* result,
37 const bool interactive,
38 const UpdateState& update_state) const override {
39 result->update_can_start = true;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070040 result->p2p_allowed = false;
41 result->target_channel.clear();
Gilad Arnoldb3b05442014-05-30 14:25:05 -070042 result->download_url_idx = 0;
43 result->download_url_num_failures = 0;
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070044 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
45 result->scatter_wait_period = base::TimeDelta();
46 result->scatter_check_threshold = 0;
Alex Deymoe636c3c2014-03-11 19:02:08 -070047 return EvalStatus::kSucceeded;
Alex Deymoc705cc82014-02-19 11:15:00 -080048 }
49
Gilad Arnold684219d2014-07-07 14:54:57 -070050 virtual EvalStatus UpdateDownloadAllowed(
Gilad Arnold0adbc942014-05-12 10:35:43 -070051 EvaluationContext* ec,
52 State* state,
53 std::string* error,
54 bool* result) const override {
55 *result = true;
56 return EvalStatus::kSucceeded;
57 }
58
Gilad Arnoldb3b05442014-05-30 14:25:05 -070059 protected:
60 // Policy override.
61 virtual std::string PolicyName() const override {
62 return "DefaultPolicy";
63 }
64
Alex Deymoc705cc82014-02-19 11:15:00 -080065 private:
66 DISALLOW_COPY_AND_ASSIGN(DefaultPolicy);
67};
68
Alex Deymo63784a52014-05-28 10:46:14 -070069} // namespace chromeos_update_manager
Alex Deymoc705cc82014-02-19 11:15:00 -080070
Gilad Arnold48415f12014-06-27 07:10:58 -070071#endif // UPDATE_ENGINE_UPDATE_MANAGER_DEFAULT_POLICY_H_