| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 16 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 17 | #include "update_engine/update_manager/state_factory.h" | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 18 |  | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 19 | #include <memory> | 
|  | 20 |  | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 21 | #include <base/logging.h> | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 22 | #if USE_DBUS | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 23 | #include <session_manager/dbus-proxies.h> | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 24 | #endif  // USE_DBUS | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 25 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 26 | #include "update_engine/common/clock_interface.h" | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 27 | #if USE_DBUS | 
|  | 28 | #include "update_engine/dbus_connection.h" | 
|  | 29 | #endif  // USE_DBUS | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 30 | #include "update_engine/update_manager/fake_shill_provider.h" | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 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" | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 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" | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 38 | #if USE_SHILL | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 39 | #include "update_engine/shill_proxy.h" | 
|  | 40 | #include "update_engine/update_manager/real_shill_provider.h" | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 41 | #endif  // USE_SHILL | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 42 |  | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 43 | using std::unique_ptr; | 
|  | 44 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 45 | namespace chromeos_update_manager { | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 46 |  | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 47 | State* DefaultStateFactory( | 
|  | 48 | policy::PolicyProvider* policy_provider, | 
| Daniel Erat | e5f6f25 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 49 | org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy, | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 50 | chromeos_update_engine::SystemState* system_state) { | 
| Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 51 | chromeos_update_engine::ClockInterface* const clock = system_state->clock(); | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 52 | unique_ptr<RealConfigProvider> config_provider( | 
| Gilad Arnold | 48e1361 | 2014-05-16 10:18:05 -0700 | [diff] [blame] | 53 | new RealConfigProvider(system_state->hardware())); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 54 | #if USE_DBUS | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 55 | scoped_refptr<dbus::Bus> bus = | 
|  | 56 | chromeos_update_engine::DBusConnection::Get()->GetDBus(); | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 57 | unique_ptr<RealDevicePolicyProvider> device_policy_provider( | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 58 | new RealDevicePolicyProvider( | 
| Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 59 | std::make_unique<org::chromium::SessionManagerInterfaceProxy>(bus), | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 60 | policy_provider)); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 61 | #else | 
|  | 62 | unique_ptr<RealDevicePolicyProvider> device_policy_provider( | 
|  | 63 | new RealDevicePolicyProvider(policy_provider)); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 64 | #endif  // USE_DBUS | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 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 | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 71 | unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider()); | 
| Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 72 | unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider( | 
|  | 73 | system_state->hardware(), system_state->boot_control(), libcros_proxy)); | 
| Amin Hassani | 4718629 | 2017-08-01 15:03:08 -0700 | [diff] [blame] | 74 |  | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 75 | unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock)); | 
|  | 76 | unique_ptr<RealUpdaterProvider> updater_provider( | 
| Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 77 | new RealUpdaterProvider(system_state)); | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 78 |  | 
| Alex Deymo | f9f1263 | 2014-04-17 13:51:26 -0700 | [diff] [blame] | 79 | if (!(config_provider->Init() && | 
|  | 80 | device_policy_provider->Init() && | 
| Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 81 | random_provider->Init() && | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 82 | #if USE_SHILL | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 83 | shill_provider->Init() && | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 84 | #endif  // USE_SHILL | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 85 | system_provider->Init() && | 
| Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 86 | time_provider->Init() && | 
|  | 87 | updater_provider->Init())) { | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 88 | LOG(ERROR) << "Error initializing providers"; | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 89 | return nullptr; | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
| David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 92 | return new RealState(config_provider.release(), | 
|  | 93 | device_policy_provider.release(), | 
|  | 94 | random_provider.release(), | 
|  | 95 | shill_provider.release(), | 
|  | 96 | system_provider.release(), | 
|  | 97 | time_provider.release(), | 
|  | 98 | updater_provider.release()); | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 101 | }  // namespace chromeos_update_manager |