Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 1 | // 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 | |
| 7 | namespace { |
| 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. |
| 13 | const int kCheckIntervalInSeconds = 15 * 60; |
| 14 | |
| 15 | } // namespace |
| 16 | |
| 17 | namespace chromeos_update_manager { |
| 18 | |
| 19 | DefaultPolicy::DefaultPolicy(chromeos_update_engine::ClockInterface* clock) |
| 20 | : clock_(clock), aux_state_(new DefaultPolicyState()) {} |
| 21 | |
| 22 | EvalStatus 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 Arnold | 44dc3bf | 2014-07-18 23:39:38 -0700 | [diff] [blame^] | 27 | result->is_interactive = false; |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 28 | |
| 29 | // Ensure that the minimum interval is set. If there's no clock, this defaults |
| 30 | // to always allowing the update. |
| 31 | if (!aux_state_->IsLastCheckAllowedTimeSet() || |
| 32 | ec->IsMonotonicTimeGreaterThan( |
| 33 | aux_state_->last_check_allowed_time() + |
| 34 | base::TimeDelta::FromSeconds(kCheckIntervalInSeconds))) { |
| 35 | if (clock_) |
| 36 | aux_state_->set_last_check_allowed_time(clock_->GetMonotonicTime()); |
| 37 | return EvalStatus::kSucceeded; |
| 38 | } |
| 39 | |
| 40 | return EvalStatus::kAskMeAgainLater; |
| 41 | } |
| 42 | |
| 43 | } // namespace chromeos_update_manager |