blob: dbb6b3369021d94281baeb02f68bcfa6833bad05 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Deymo63784a52014-05-28 10:46:14 -070016
17#include "update_engine/update_manager/update_manager.h"
Alex Deymo63784a52014-05-28 10:46:14 -070018#include "update_engine/update_manager/state.h"
19
20namespace chromeos_update_manager {
21
Amin Hassani0468a762020-11-17 23:53:48 -080022UpdateManager::UpdateManager(base::TimeDelta evaluation_timeout,
Amin Hassani4b717432019-01-14 16:24:20 -080023 base::TimeDelta expiration_timeout,
24 State* state)
Amin Hassanifbb600f2019-08-14 19:52:30 -070025 : policy_(GetSystemPolicy()),
Amin Hassani4b717432019-01-14 16:24:20 -080026 state_(state),
Amin Hassani4b717432019-01-14 16:24:20 -080027 evaluation_timeout_(evaluation_timeout),
28 expiration_timeout_(expiration_timeout),
Amin Hassanifbb600f2019-08-14 19:52:30 -070029 weak_ptr_factory_(this) {}
Alex Deymo63784a52014-05-28 10:46:14 -070030
Gilad Arnold83ffdda2014-08-08 13:30:31 -070031UpdateManager::~UpdateManager() {
32 // Remove pending main loop events associated with any of the outstanding
33 // evaluation contexts. This will prevent dangling pending events, causing
34 // these contexts to be destructed once the repo itself is destructed.
35 for (auto& ec : ec_repo_)
36 ec->RemoveObserversAndTimeout();
37}
38
Jae Hoon Kim504c3cb2019-07-02 11:17:24 -070039void UpdateManager::AsyncPolicyRequestUpdateCheckAllowed(
40 base::Callback<void(EvalStatus, const UpdateCheckParams& result)> callback,
41 EvalStatus (Policy::*policy_method)(
42 EvaluationContext*, State*, std::string*, UpdateCheckParams*) const) {
43 AsyncPolicyRequest(callback, policy_method);
44}
45
Gilad Arnold83ffdda2014-08-08 13:30:31 -070046void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) {
Amin Hassania2c8b922019-08-14 19:41:03 -070047 // Since |ec_repo_|'s compare function is based on the value of the raw
48 // pointer |ec|, we can just create a |shared_ptr| here and pass it along to
49 // be erased.
50 if (!ec_repo_.erase(
51 std::shared_ptr<EvaluationContext>(ec, [](EvaluationContext*) {}))) {
Gilad Arnold83ffdda2014-08-08 13:30:31 -070052 LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug.";
53 }
54}
55
Alex Deymo63784a52014-05-28 10:46:14 -070056} // namespace chromeos_update_manager