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