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 // 16 17 #include "update_engine/update_manager/update_manager.h" 18 19 #ifdef __ANDROID__ 20 #include "update_engine/update_manager/android_things_policy.h" 21 #else 22 #include "update_engine/update_manager/chromeos_policy.h" 23 #endif // __ANDROID__ 24 #include "update_engine/update_manager/state.h" 25 26 namespace chromeos_update_manager { 27 28 UpdateManager::UpdateManager(chromeos_update_engine::ClockInterface* clock, 29 base::TimeDelta evaluation_timeout, 30 base::TimeDelta expiration_timeout, State* state) 31 : default_policy_(clock), state_(state), clock_(clock), 32 evaluation_timeout_(evaluation_timeout), 33 expiration_timeout_(expiration_timeout), 34 weak_ptr_factory_(this) { 35 #ifdef __ANDROID__ 36 policy_.reset(new AndroidThingsPolicy()); 37 #else 38 policy_.reset(new ChromeOSPolicy()); 39 #endif // __ANDROID__ 40 } 41 42 UpdateManager::~UpdateManager() { 43 // Remove pending main loop events associated with any of the outstanding 44 // evaluation contexts. This will prevent dangling pending events, causing 45 // these contexts to be destructed once the repo itself is destructed. 46 for (auto& ec : ec_repo_) 47 ec->RemoveObserversAndTimeout(); 48 } 49 50 void UpdateManager::UnregisterEvalContext(EvaluationContext* ec) { 51 if (!ec_repo_.erase(ec)) { 52 LOG(ERROR) << "Unregistering an unknown evaluation context, this is a bug."; 53 } 54 } 55 56 } // namespace chromeos_update_manager 57