blob: 8e9b221166c0fef421480631da2197d4bb39fbb4 [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
19#include "update_engine/update_manager/chromeos_policy.h"
20#include "update_engine/update_manager/state.h"
21
22namespace chromeos_update_manager {
23
24UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock,
Gilad Arnoldfd45a732014-08-07 15:53:46 -070025 base::TimeDelta evaluation_timeout,
26 base::TimeDelta expiration_timeout, State* state)
Gilad Arnolda23e4082014-07-17 11:40:43 -070027 : default_policy_(clock), state_(state), clock_(clock),
Gilad Arnoldfd45a732014-08-07 15:53:46 -070028 evaluation_timeout_(evaluation_timeout),
Gilad Arnold83ffdda2014-08-08 13:30:31 -070029 expiration_timeout_(expiration_timeout),
30 weak_ptr_factory_(this) {
Alex Deymo63784a52014-05-28 10:46:14 -070031 // TODO(deymo): Make it possible to replace this policy with a different
32 // implementation with a build-time flag.
33 policy_.reset(new ChromeOSPolicy());
34}
35
Gilad Arnold83ffdda2014-08-08 13:30:31 -070036UpdateManager::~UpdateManager() {
37 // Remove pending main loop events associated with any of the outstanding
38 // evaluation contexts. This will prevent dangling pending events, causing
39 // these contexts to be destructed once the repo itself is destructed.
40 for (auto& ec : ec_repo_)
41 ec->RemoveObserversAndTimeout();
42}
43
44void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) {
45 if (!ec_repo_.erase(ec)) {
46 LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug.";
47 }
48}
49
Alex Deymo63784a52014-05-28 10:46:14 -070050} // namespace chromeos_update_manager