update_manager.cc 2.0 KB

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