Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -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/update_manager.h" |
| 6 | |
| 7 | #include "update_engine/update_manager/chromeos_policy.h" |
| 8 | #include "update_engine/update_manager/state.h" |
| 9 | |
| 10 | namespace chromeos_update_manager { |
| 11 | |
| 12 | UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock, |
Gilad Arnold | fd45a73 | 2014-08-07 15:53:46 -0700 | [diff] [blame] | 13 | base::TimeDelta evaluation_timeout, |
| 14 | base::TimeDelta expiration_timeout, State* state) |
Gilad Arnold | a23e408 | 2014-07-17 11:40:43 -0700 | [diff] [blame] | 15 | : default_policy_(clock), state_(state), clock_(clock), |
Gilad Arnold | fd45a73 | 2014-08-07 15:53:46 -0700 | [diff] [blame] | 16 | evaluation_timeout_(evaluation_timeout), |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame^] | 17 | expiration_timeout_(expiration_timeout), |
| 18 | weak_ptr_factory_(this) { |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 19 | // TODO(deymo): Make it possible to replace this policy with a different |
| 20 | // implementation with a build-time flag. |
| 21 | policy_.reset(new ChromeOSPolicy()); |
| 22 | } |
| 23 | |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame^] | 24 | UpdateManager::~UpdateManager() { |
| 25 | // Remove pending main loop events associated with any of the outstanding |
| 26 | // evaluation contexts. This will prevent dangling pending events, causing |
| 27 | // these contexts to be destructed once the repo itself is destructed. |
| 28 | for (auto& ec : ec_repo_) |
| 29 | ec->RemoveObserversAndTimeout(); |
| 30 | } |
| 31 | |
| 32 | void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) { |
| 33 | if (!ec_repo_.erase(ec)) { |
| 34 | LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug."; |
| 35 | } |
| 36 | } |
| 37 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 38 | } // namespace chromeos_update_manager |