blob: 1da3fb99ffd2ed2706b35388e82c16e52e9ca1b0 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Deymo94c06162014-03-21 20:34:46 -070016
Alex Deymo63784a52014-05-28 10:46:14 -070017#include "update_engine/update_manager/state_factory.h"
Alex Deymo94c06162014-03-21 20:34:46 -070018
Ben Chan02f7c1d2014-10-18 15:18:02 -070019#include <memory>
20
Alex Deymo94c06162014-03-21 20:34:46 -070021#include <base/logging.h>
22
Alex Deymo39910dc2015-11-09 17:04:30 -080023#include "update_engine/common/clock_interface.h"
Alex Deymo63784a52014-05-28 10:46:14 -070024#include "update_engine/update_manager/real_config_provider.h"
25#include "update_engine/update_manager/real_device_policy_provider.h"
26#include "update_engine/update_manager/real_random_provider.h"
27#include "update_engine/update_manager/real_shill_provider.h"
28#include "update_engine/update_manager/real_state.h"
29#include "update_engine/update_manager/real_system_provider.h"
30#include "update_engine/update_manager/real_time_provider.h"
31#include "update_engine/update_manager/real_updater_provider.h"
Alex Deymo94c06162014-03-21 20:34:46 -070032
Ben Chan02f7c1d2014-10-18 15:18:02 -070033using std::unique_ptr;
34
Alex Deymo63784a52014-05-28 10:46:14 -070035namespace chromeos_update_manager {
Alex Deymo94c06162014-03-21 20:34:46 -070036
Alex Deymo30534502015-07-20 15:06:33 -070037State* DefaultStateFactory(
38 policy::PolicyProvider* policy_provider,
39 chromeos_update_engine::ShillProxy* shill_proxy,
40 org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
Daniel Erat941cf232017-04-20 12:09:58 -060041 org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy,
Alex Deymo30534502015-07-20 15:06:33 -070042 chromeos_update_engine::SystemState* system_state) {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070043 chromeos_update_engine::ClockInterface* const clock = system_state->clock();
Ben Chan02f7c1d2014-10-18 15:18:02 -070044 unique_ptr<RealConfigProvider> config_provider(
Gilad Arnold48e13612014-05-16 10:18:05 -070045 new RealConfigProvider(system_state->hardware()));
Ben Chan02f7c1d2014-10-18 15:18:02 -070046 unique_ptr<RealDevicePolicyProvider> device_policy_provider(
Alex Deymo30534502015-07-20 15:06:33 -070047 new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
Ben Chan02f7c1d2014-10-18 15:18:02 -070048 unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
49 unique_ptr<RealShillProvider> shill_provider(
Alex Deymo30534502015-07-20 15:06:33 -070050 new RealShillProvider(shill_proxy, clock));
Ben Chan02f7c1d2014-10-18 15:18:02 -070051 unique_ptr<RealSystemProvider> system_provider(
Alex Deymo763e7db2015-08-27 21:08:08 -070052 new RealSystemProvider(system_state->hardware(),
Xiyuan Xia6e30bc52016-02-24 15:35:42 -080053 system_state->boot_control(),
54 libcros_proxy));
Ben Chan02f7c1d2014-10-18 15:18:02 -070055 unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
56 unique_ptr<RealUpdaterProvider> updater_provider(
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070057 new RealUpdaterProvider(system_state));
Alex Deymo94c06162014-03-21 20:34:46 -070058
Alex Deymof9f12632014-04-17 13:51:26 -070059 if (!(config_provider->Init() &&
60 device_policy_provider->Init() &&
Alex Deymoc83baf62014-04-02 17:43:35 -070061 random_provider->Init() &&
Alex Deymo94c06162014-03-21 20:34:46 -070062 shill_provider->Init() &&
63 system_provider->Init() &&
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070064 time_provider->Init() &&
65 updater_provider->Init())) {
Alex Deymo94c06162014-03-21 20:34:46 -070066 LOG(ERROR) << "Error initializing providers";
Alex Vakulenko88b591f2014-08-28 16:48:57 -070067 return nullptr;
Alex Deymo94c06162014-03-21 20:34:46 -070068 }
69
David Zeuthen4e89e2c2014-04-24 11:47:00 -070070 return new RealState(config_provider.release(),
71 device_policy_provider.release(),
72 random_provider.release(),
73 shill_provider.release(),
74 system_provider.release(),
75 time_provider.release(),
76 updater_provider.release());
Alex Deymo94c06162014-03-21 20:34:46 -070077}
78
Alex Deymo63784a52014-05-28 10:46:14 -070079} // namespace chromeos_update_manager