blob: 00694969b2064acc7355327d800a1cc6babe8c07 [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"
18
Aaron Wood56d8ab32017-09-22 15:56:18 -070019#ifdef __ANDROID__
20#include "update_engine/update_manager/android_things_policy.h"
21#else
Alex Deymo63784a52014-05-28 10:46:14 -070022#include "update_engine/update_manager/chromeos_policy.h"
Aaron Wood56d8ab32017-09-22 15:56:18 -070023#endif // __ANDROID__
Alex Deymo63784a52014-05-28 10:46:14 -070024#include "update_engine/update_manager/state.h"
25
26namespace chromeos_update_manager {
27
28UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock,
Gilad Arnoldfd45a732014-08-07 15:53:46 -070029 base::TimeDelta evaluation_timeout,
Amin Hassani4b717432019-01-14 16:24:20 -080030 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 Wood56d8ab32017-09-22 15:56:18 -070038#ifdef __ANDROID__
39 policy_.reset(new AndroidThingsPolicy());
40#else
Alex Deymo63784a52014-05-28 10:46:14 -070041 policy_.reset(new ChromeOSPolicy());
Aaron Wood56d8ab32017-09-22 15:56:18 -070042#endif // __ANDROID__
Alex Deymo63784a52014-05-28 10:46:14 -070043}
44
Gilad Arnold83ffdda2014-08-08 13:30:31 -070045UpdateManager::~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
Jae Hoon Kim504c3cb2019-07-02 11:17:24 -070053void UpdateManager::AsyncPolicyRequestUpdateCheckAllowed(
54 base::Callback<void(EvalStatus, const UpdateCheckParams& result)> callback,
55 EvalStatus (Policy::*policy_method)(
56 EvaluationContext*, State*, std::string*, UpdateCheckParams*) const) {
57 AsyncPolicyRequest(callback, policy_method);
58}
59
Gilad Arnold83ffdda2014-08-08 13:30:31 -070060void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) {
61 if (!ec_repo_.erase(ec)) {
62 LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug.";
63 }
64}
65
Alex Deymo63784a52014-05-28 10:46:14 -070066} // namespace chromeos_update_manager