blob: 9a5ce7e9e917f5d4cbb87a92e201eb88da6c3052 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Gilad Arnolda23e4082014-07-17 11:40:43 -070016
17#include "update_engine/update_manager/default_policy.h"
18
19namespace {
20
21// A fixed minimum interval between consecutive allowed update checks. This
22// needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but
23// at the same time short enough to allow the machine to update itself
24// reasonably soon.
25const int kCheckIntervalInSeconds = 15 * 60;
26
27} // namespace
28
29namespace chromeos_update_manager {
30
31DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock)
32 : clock_(clock), aux_state_(new DefaultPolicyState()) {}
33
34EvalStatus DefaultPolicy::UpdateCheckAllowed(
35 EvaluationContext* ec, State* state, std::string* error,
36 UpdateCheckParams* result) const {
37 result->updates_enabled = true;
38 result->target_channel.clear();
Gilad Arnoldd4b30322014-07-21 15:35:27 -070039 result->target_version_prefix.clear();
Gilad Arnold44dc3bf2014-07-18 23:39:38 -070040 result->is_interactive = false;
Gilad Arnolda23e4082014-07-17 11:40:43 -070041
42 // Ensure that the minimum interval is set. If there's no clock, this defaults
43 // to always allowing the update.
44 if (!aux_state_->IsLastCheckAllowedTimeSet() ||
45 ec->IsMonotonicTimeGreaterThan(
46 aux_state_->last_check_allowed_time() +
47 base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
48 if (clock_)
49 aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
50 return EvalStatus::kSucceeded;
51 }
52
53 return EvalStatus::kAskMeAgainLater;
54}
55
Gilad Arnolddc4bb262014-07-23 10:45:19 -070056EvalStatus DefaultPolicy::UpdateCanStart(
57 EvaluationContext* ec,
58 State* state,
59 std::string* error,
60 UpdateDownloadParams* result,
Gilad Arnoldd78caf92014-09-24 09:28:14 -070061 const UpdateState update_state) const {
Gilad Arnolddc4bb262014-07-23 10:45:19 -070062 result->update_can_start = true;
63 result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
64 result->download_url_idx = 0;
Gilad Arnold14a9e702014-10-08 08:09:09 -070065 result->download_url_allowed = true;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070066 result->download_url_num_errors = 0;
Gilad Arnoldb2f99192014-10-07 13:01:52 -070067 result->p2p_downloading_allowed = false;
68 result->p2p_sharing_allowed = false;
Gilad Arnolddc4bb262014-07-23 10:45:19 -070069 result->do_increment_failures = false;
70 result->backoff_expiry = base::Time();
71 result->scatter_wait_period = base::TimeDelta();
72 result->scatter_check_threshold = 0;
73 return EvalStatus::kSucceeded;
74}
75
76EvalStatus DefaultPolicy::UpdateDownloadAllowed(
77 EvaluationContext* ec,
78 State* state,
79 std::string* error,
80 bool* result) const {
81 *result = true;
82 return EvalStatus::kSucceeded;
83}
84
Gilad Arnold78ecbfc2014-10-22 14:38:25 -070085EvalStatus DefaultPolicy::P2PEnabled(
86 EvaluationContext* ec,
87 State* state,
88 std::string* error,
89 bool* result) const {
90 *result = false;
91 return EvalStatus::kSucceeded;
92}
93
94EvalStatus DefaultPolicy::P2PEnabledChanged(
95 EvaluationContext* ec,
96 State* state,
97 std::string* error,
98 bool* result,
99 bool prev_result) const {
100 // This policy will always prohibit P2P, so this is signaling to the caller
101 // that the decision is final (because the current value is the same as the
102 // previous one) and there's no need to issue another call.
103 *result = false;
104 return EvalStatus::kSucceeded;
105}
106
Gilad Arnolda23e4082014-07-17 11:40:43 -0700107} // namespace chromeos_update_manager