blob: 13de5bd50047f83067c0ce66ef84838ddedb812e [file] [log] [blame]
// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "update_engine/update_manager/default_policy.h"
namespace {
// A fixed minimum interval between consecutive allowed update checks. This
// needs to be long enough to prevent busywork and/or DDoS attacks on Omaha, but
// at the same time short enough to allow the machine to update itself
// reasonably soon.
const int kCheckIntervalInSeconds = 15 * 60;
} // namespace
namespace chromeos_update_manager {
DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock)
: clock_(clock), aux_state_(new DefaultPolicyState()) {}
EvalStatus DefaultPolicy::UpdateCheckAllowed(
EvaluationContext* ec, State* state, std::string* error,
UpdateCheckParams* result) const {
result->updates_enabled = true;
result->target_channel.clear();
result->target_version_prefix.clear();
result->is_interactive = false;
// Ensure that the minimum interval is set. If there's no clock, this defaults
// to always allowing the update.
if (!aux_state_->IsLastCheckAllowedTimeSet() ||
ec->IsMonotonicTimeGreaterThan(
aux_state_->last_check_allowed_time() +
base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) {
if (clock_)
aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime());
return EvalStatus::kSucceeded;
}
return EvalStatus::kAskMeAgainLater;
}
EvalStatus DefaultPolicy::UpdateCanStart(
EvaluationContext* ec,
State* state,
std::string* error,
UpdateDownloadParams* result,
const UpdateState update_state) const {
result->update_can_start = true;
result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
result->download_url_idx = 0;
result->download_url_num_errors = 0;
result->p2p_allowed = false;
result->do_increment_failures = false;
result->backoff_expiry = base::Time();
result->scatter_wait_period = base::TimeDelta();
result->scatter_check_threshold = 0;
return EvalStatus::kSucceeded;
}
EvalStatus DefaultPolicy::UpdateDownloadAllowed(
EvaluationContext* ec,
State* state,
std::string* error,
bool* result) const {
*result = true;
return EvalStatus::kSucceeded;
}
} // namespace chromeos_update_manager