| 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 |  | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 26 | #if USE_DBUS | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 27 | #include "update_engine/cros/dbus_connection.h" | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 28 | #endif  // USE_DBUS | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 29 | #include "update_engine/common/system_state.h" | 
| Amin Hassani | f368735 | 2020-11-10 10:41:40 -0800 | [diff] [blame] | 30 | #include "update_engine/cros/shill_proxy.h" | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 31 | #include "update_engine/update_manager/fake_shill_provider.h" | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 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" | 
| Amin Hassani | f368735 | 2020-11-10 10:41:40 -0800 | [diff] [blame] | 35 | #include "update_engine/update_manager/real_shill_provider.h" | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 36 | #include "update_engine/update_manager/real_state.h" | 
|  | 37 | #include "update_engine/update_manager/real_system_provider.h" | 
|  | 38 | #include "update_engine/update_manager/real_time_provider.h" | 
|  | 39 | #include "update_engine/update_manager/real_updater_provider.h" | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 40 |  | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 41 | using chromeos_update_engine::SystemState; | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 42 | using std::unique_ptr; | 
|  | 43 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 44 | namespace chromeos_update_manager { | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 45 |  | 
| Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 46 | State* DefaultStateFactory( | 
|  | 47 | policy::PolicyProvider* policy_provider, | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 48 | org::chromium::KioskAppServiceInterfaceProxyInterface* kiosk_app_proxy) { | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 49 | unique_ptr<RealConfigProvider> config_provider( | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 50 | new RealConfigProvider(SystemState::Get()->hardware())); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 51 | #if USE_DBUS | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 52 | scoped_refptr<dbus::Bus> bus = | 
|  | 53 | chromeos_update_engine::DBusConnection::Get()->GetDBus(); | 
| Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 54 | unique_ptr<RealDevicePolicyProvider> device_policy_provider( | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 55 | new RealDevicePolicyProvider( | 
| Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 56 | std::make_unique<org::chromium::SessionManagerInterfaceProxy>(bus), | 
| Sen Jiang | 9730679 | 2016-06-08 16:04:06 -0700 | [diff] [blame] | 57 | policy_provider)); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 58 | #else | 
|  | 59 | unique_ptr<RealDevicePolicyProvider> device_policy_provider( | 
|  | 60 | new RealDevicePolicyProvider(policy_provider)); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 61 | #endif  // USE_DBUS | 
| Sen Jiang | 2058a99 | 2016-08-23 14:30:51 -0700 | [diff] [blame] | 62 | unique_ptr<RealShillProvider> shill_provider( | 
| Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 63 | new RealShillProvider(new chromeos_update_engine::ShillProxy())); | 
| Sen Jiang | c92195c | 2016-06-13 15:48:44 -0700 | [diff] [blame] | 64 | unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider()); | 
| Miriam Polzer | 8db5249 | 2020-09-17 14:06:46 +0200 | [diff] [blame] | 65 | unique_ptr<RealSystemProvider> system_provider( | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 66 | new RealSystemProvider(kiosk_app_proxy)); | 
| Amin Hassani | 4718629 | 2017-08-01 15:03:08 -0700 | [diff] [blame] | 67 |  | 
| Amin Hassani | 0468a76 | 2020-11-17 23:53:48 -0800 | [diff] [blame] | 68 | unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider()); | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 69 | unique_ptr<RealUpdaterProvider> updater_provider(new RealUpdaterProvider()); | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 70 |  | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 71 | if (!(config_provider->Init() && device_policy_provider->Init() && | 
| Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 72 | random_provider->Init() && | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 73 | shill_provider->Init() && | 
| Amin Hassani | 4b71743 | 2019-01-14 16:24:20 -0800 | [diff] [blame] | 74 | system_provider->Init() && time_provider->Init() && | 
| Gilad Arnold | ae47a9a | 2014-03-26 12:16:47 -0700 | [diff] [blame] | 75 | updater_provider->Init())) { | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 76 | LOG(ERROR) << "Error initializing providers"; | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 77 | return nullptr; | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
| David Zeuthen | 4e89e2c | 2014-04-24 11:47:00 -0700 | [diff] [blame] | 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()); | 
| Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 87 | } | 
|  | 88 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 89 | }  // namespace chromeos_update_manager |