state_factory.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/state_factory.h"
  17. #include <memory>
  18. #include <base/logging.h>
  19. #if USE_DBUS
  20. #include <session_manager/dbus-proxies.h>
  21. #endif // USE_DBUS
  22. #include "update_engine/common/clock_interface.h"
  23. #if USE_DBUS
  24. #include "update_engine/dbus_connection.h"
  25. #endif // USE_DBUS
  26. #include "update_engine/update_manager/fake_shill_provider.h"
  27. #include "update_engine/update_manager/real_config_provider.h"
  28. #include "update_engine/update_manager/real_device_policy_provider.h"
  29. #include "update_engine/update_manager/real_random_provider.h"
  30. #include "update_engine/update_manager/real_state.h"
  31. #include "update_engine/update_manager/real_system_provider.h"
  32. #include "update_engine/update_manager/real_time_provider.h"
  33. #include "update_engine/update_manager/real_updater_provider.h"
  34. #if USE_SHILL
  35. #include "update_engine/shill_proxy.h"
  36. #include "update_engine/update_manager/real_shill_provider.h"
  37. #endif // USE_SHILL
  38. using std::unique_ptr;
  39. namespace chromeos_update_manager {
  40. State* DefaultStateFactory(
  41. policy::PolicyProvider* policy_provider,
  42. org::chromium::KioskAppServiceInterfaceProxyInterface* kiosk_app_proxy,
  43. chromeos_update_engine::SystemState* system_state) {
  44. chromeos_update_engine::ClockInterface* const clock = system_state->clock();
  45. unique_ptr<RealConfigProvider> config_provider(
  46. new RealConfigProvider(system_state->hardware()));
  47. #if USE_DBUS
  48. scoped_refptr<dbus::Bus> bus =
  49. chromeos_update_engine::DBusConnection::Get()->GetDBus();
  50. unique_ptr<RealDevicePolicyProvider> device_policy_provider(
  51. new RealDevicePolicyProvider(
  52. std::make_unique<org::chromium::SessionManagerInterfaceProxy>(bus),
  53. policy_provider));
  54. #else
  55. unique_ptr<RealDevicePolicyProvider> device_policy_provider(
  56. new RealDevicePolicyProvider(policy_provider));
  57. #endif // USE_DBUS
  58. #if USE_SHILL
  59. unique_ptr<RealShillProvider> shill_provider(
  60. new RealShillProvider(new chromeos_update_engine::ShillProxy(), clock));
  61. #else
  62. unique_ptr<FakeShillProvider> shill_provider(new FakeShillProvider());
  63. #endif // USE_SHILL
  64. unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
  65. unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider(
  66. system_state->hardware(), system_state->boot_control(), kiosk_app_proxy));
  67. unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
  68. unique_ptr<RealUpdaterProvider> updater_provider(
  69. new RealUpdaterProvider(system_state));
  70. if (!(config_provider->Init() && device_policy_provider->Init() &&
  71. random_provider->Init() &&
  72. #if USE_SHILL
  73. shill_provider->Init() &&
  74. #endif // USE_SHILL
  75. system_provider->Init() && time_provider->Init() &&
  76. updater_provider->Init())) {
  77. LOG(ERROR) << "Error initializing providers";
  78. return nullptr;
  79. }
  80. return new RealState(config_provider.release(),
  81. device_policy_provider.release(),
  82. random_provider.release(),
  83. shill_provider.release(),
  84. system_provider.release(),
  85. time_provider.release(),
  86. updater_provider.release());
  87. }
  88. } // namespace chromeos_update_manager