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