Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 | // |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 16 | |
| 17 | #include "update_engine/update_manager/update_manager.h" |
| 18 | |
Aaron Wood | 56d8ab3 | 2017-09-22 15:56:18 -0700 | [diff] [blame] | 19 | #ifdef __ANDROID__ |
| 20 | #include "update_engine/update_manager/android_things_policy.h" |
| 21 | #else |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 22 | #include "update_engine/update_manager/chromeos_policy.h" |
Aaron Wood | 56d8ab3 | 2017-09-22 15:56:18 -0700 | [diff] [blame] | 23 | #endif // __ANDROID__ |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 24 | #include "update_engine/update_manager/state.h" |
| 25 | |
| 26 | namespace chromeos_update_manager { |
| 27 | |
| 28 | UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock, |
Gilad Arnold | fd45a73 | 2014-08-07 15:53:46 -0700 | [diff] [blame] | 29 | base::TimeDelta evaluation_timeout, |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame^] | 30 | base::TimeDelta expiration_timeout, |
| 31 | State* state) |
| 32 | : default_policy_(clock), |
| 33 | state_(state), |
| 34 | clock_(clock), |
| 35 | evaluation_timeout_(evaluation_timeout), |
| 36 | expiration_timeout_(expiration_timeout), |
| 37 | weak_ptr_factory_(this) { |
Aaron Wood | 56d8ab3 | 2017-09-22 15:56:18 -0700 | [diff] [blame] | 38 | #ifdef __ANDROID__ |
| 39 | policy_.reset(new AndroidThingsPolicy()); |
| 40 | #else |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 41 | policy_.reset(new ChromeOSPolicy()); |
Aaron Wood | 56d8ab3 | 2017-09-22 15:56:18 -0700 | [diff] [blame] | 42 | #endif // __ANDROID__ |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame] | 45 | UpdateManager::~UpdateManager() { |
| 46 | // Remove pending main loop events associated with any of the outstanding |
| 47 | // evaluation contexts. This will prevent dangling pending events, causing |
| 48 | // these contexts to be destructed once the repo itself is destructed. |
| 49 | for (auto& ec : ec_repo_) |
| 50 | ec->RemoveObserversAndTimeout(); |
| 51 | } |
| 52 | |
| 53 | void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) { |
| 54 | if (!ec_repo_.erase(ec)) { |
| 55 | LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug."; |
| 56 | } |
| 57 | } |
| 58 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 59 | } // namespace chromeos_update_manager |