blob: d49591a00b57ad9ccedc275370dec43fb1c09bbb [file] [log] [blame]
Gilad Arnolda23e4082014-07-17 11:40:43 -07001// 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#include "update_engine/update_manager/default_policy.h"
6
7namespace {
8
9// A fixed minimum interval between consecutive allowed update checks. This
10// needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but
11// at the same time short enough to allow the machine to update itself
12// reasonably soon.
13const int kCheckIntervalInSeconds = 15 * 60;
14
15} // namespace
16
17namespace chromeos_update_manager {
18
19DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock)
20 : clock_(clock), aux_state_(new DefaultPolicyState()) {}
21
22EvalStatus DefaultPolicy::UpdateCheckAllowed(
23 EvaluationContext* ec, State* state, std::string* error,
24 UpdateCheckParams* result) const {
25 result->updates_enabled = true;
26 result->target_channel.clear();
Gilad Arnoldd4b30322014-07-21 15:35:27 -070027 result->target_version_prefix.clear();
Gilad Arnold44dc3bf2014-07-18 23:39:38 -070028 result->is_interactive = false;
Gilad Arnolda23e4082014-07-17 11:40:43 -070029
30 // Ensure that the minimum interval is set. If there's no clock, this defaults
31 // to always allowing the update.
32 if (!aux_state_->IsLastCheckAllowedTimeSet() ||
33 ec->IsMonotonicTimeGreaterThan(
34 aux_state_->last_check_allowed_time() +
35 base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
36 if (clock_)
37 aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
38 return EvalStatus::kSucceeded;
39 }
40
41 return EvalStatus::kAskMeAgainLater;
42}
43
Gilad Arnolddc4bb262014-07-23 10:45:19 -070044EvalStatus DefaultPolicy::UpdateCanStart(
45 EvaluationContext* ec,
46 State* state,
47 std::string* error,
48 UpdateDownloadParams* result,
Gilad Arnoldd78caf92014-09-24 09:28:14 -070049 const UpdateState update_state) const {
Gilad Arnolddc4bb262014-07-23 10:45:19 -070050 result->update_can_start = true;
51 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
52 result->download_url_idx = 0;
Gilad Arnold14a9e702014-10-08 08:09:09 -070053 result->download_url_allowed = true;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070054 result->download_url_num_errors = 0;
Gilad Arnoldb2f99192014-10-07 13:01:52 -070055 result->p2p_downloading_allowed = false;
56 result->p2p_sharing_allowed = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070057 result->do_increment_failures = false;
58 result->backoff_expiry = base::Time();
59 result->scatter_wait_period = base::TimeDelta();
60 result->scatter_check_threshold = 0;
61 return EvalStatus::kSucceeded;
62}
63
64EvalStatus DefaultPolicy::UpdateDownloadAllowed(
65 EvaluationContext* ec,
66 State* state,
67 std::string* error,
68 bool* result) const {
69 *result = true;
70 return EvalStatus::kSucceeded;
71}
72
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070073EvalStatus DefaultPolicy::P2PEnabled(
74 EvaluationContext* ec,
75 State* state,
76 std::string* error,
77 bool* result) const {
78 *result = false;
79 return EvalStatus::kSucceeded;
80}
81
82EvalStatus DefaultPolicy::P2PEnabledChanged(
83 EvaluationContext* ec,
84 State* state,
85 std::string* error,
86 bool* result,
87 bool prev_result) const {
88 // This policy will always prohibit P2P, so this is signaling to the caller
89 // that the decision is final (because the current value is the same as the
90 // previous one) and there's no need to issue another call.
91 *result = false;
92 return EvalStatus::kSucceeded;
93}
94
Gilad Arnolda23e4082014-07-17 11:40:43 -070095} // namespace chromeos_update_manager