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" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 18 | #include "update_engine/update_manager/state.h" |
| 19 | |
| 20 | namespace chromeos_update_manager { |
| 21 | |
| 22 | UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock, |
Gilad Arnold | fd45a73 | 2014-08-07 15:53:46 -0700 | [diff] [blame] | 23 | base::TimeDelta evaluation_timeout, |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 24 | base::TimeDelta expiration_timeout, |
| 25 | State* state) |
Amin Hassani | fbb600f | 2019-08-14 19:52:30 -0700 | [diff] [blame] | 26 | : policy_(GetSystemPolicy()), |
| 27 | default_policy_(clock), |
Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 28 | state_(state), |
| 29 | clock_(clock), |
| 30 | evaluation_timeout_(evaluation_timeout), |
| 31 | expiration_timeout_(expiration_timeout), |
Amin Hassani | fbb600f | 2019-08-14 19:52:30 -0700 | [diff] [blame] | 32 | weak_ptr_factory_(this) {} |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 33 | |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame] | 34 | UpdateManager::~UpdateManager() { |
| 35 | // Remove pending main loop events associated with any of the outstanding |
| 36 | // evaluation contexts. This will prevent dangling pending events, causing |
| 37 | // these contexts to be destructed once the repo itself is destructed. |
| 38 | for (auto& ec : ec_repo_) |
| 39 | ec->RemoveObserversAndTimeout(); |
| 40 | } |
| 41 | |
Jae Hoon Kim | 504c3cb | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 42 | void UpdateManager::AsyncPolicyRequestUpdateCheckAllowed( |
| 43 | base::Callback<void(EvalStatus, const UpdateCheckParams& result)> callback, |
| 44 | EvalStatus (Policy::*policy_method)( |
| 45 | EvaluationContext*, State*, std::string*, UpdateCheckParams*) const) { |
| 46 | AsyncPolicyRequest(callback, policy_method); |
| 47 | } |
| 48 | |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame] | 49 | void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) { |
Amin Hassani | a2c8b92 | 2019-08-14 19:41:03 -0700 | [diff] [blame^] | 50 | // Since |ec_repo_|'s compare function is based on the value of the raw |
| 51 | // pointer |ec|, we can just create a |shared_ptr| here and pass it along to |
| 52 | // be erased. |
| 53 | if (!ec_repo_.erase( |
| 54 | std::shared_ptr<EvaluationContext>(ec, [](EvaluationContext*) {}))) { |
Gilad Arnold | 83ffdda | 2014-08-08 13:30:31 -0700 | [diff] [blame] | 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 |