blob: 822f9430426cb68f6a17845f0261e0ce03a998b4 [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"
Xiyuan Xia6e30bc52016-02-24 15:35:42 -080024#include "update_engine/libcros_proxy.h"
Sen Jiangf5bebae2016-06-03 15:36:54 -070025#include "update_engine/shill_proxy.h"
Alex Deymo63784a52014-05-28 10:46:14 -070026#include "update_engine/update_manager/real_config_provider.h"
27#include "update_engine/update_manager/real_device_policy_provider.h"
28#include "update_engine/update_manager/real_random_provider.h"
29#include "update_engine/update_manager/real_shill_provider.h"
30#include "update_engine/update_manager/real_state.h"
31#include "update_engine/update_manager/real_system_provider.h"
32#include "update_engine/update_manager/real_time_provider.h"
33#include "update_engine/update_manager/real_updater_provider.h"
Alex Deymo94c06162014-03-21 20:34:46 -070034
Ben Chan02f7c1d2014-10-18 15:18:02 -070035using std::unique_ptr;
36
Alex Deymo63784a52014-05-28 10:46:14 -070037namespace chromeos_update_manager {
Alex Deymo94c06162014-03-21 20:34:46 -070038
Alex Deymo30534502015-07-20 15:06:33 -070039State* DefaultStateFactory(
40 policy::PolicyProvider* policy_provider,
Alex Deymo30534502015-07-20 15:06:33 -070041 org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
Xiyuan Xia6e30bc52016-02-24 15:35:42 -080042 chromeos_update_engine::LibCrosProxy* libcros_proxy,
Alex Deymo30534502015-07-20 15:06:33 -070043 chromeos_update_engine::SystemState* system_state) {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070044 chromeos_update_engine::ClockInterface* const clock = system_state->clock();
Ben Chan02f7c1d2014-10-18 15:18:02 -070045 unique_ptr<RealConfigProvider> config_provider(
Gilad Arnold48e13612014-05-16 10:18:05 -070046 new RealConfigProvider(system_state->hardware()));
Ben Chan02f7c1d2014-10-18 15:18:02 -070047 unique_ptr<RealDevicePolicyProvider> device_policy_provider(
Alex Deymo30534502015-07-20 15:06:33 -070048 new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
Ben Chan02f7c1d2014-10-18 15:18:02 -070049 unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
50 unique_ptr<RealShillProvider> shill_provider(
Sen Jiangf5bebae2016-06-03 15:36:54 -070051 new RealShillProvider(new chromeos_update_engine::ShillProxy(), clock));
52 unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider(
53 system_state->hardware(), system_state->boot_control(), libcros_proxy));
Ben Chan02f7c1d2014-10-18 15:18:02 -070054 unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
55 unique_ptr<RealUpdaterProvider> updater_provider(
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070056 new RealUpdaterProvider(system_state));
Alex Deymo94c06162014-03-21 20:34:46 -070057
Alex Deymof9f12632014-04-17 13:51:26 -070058 if (!(config_provider->Init() &&
59 device_policy_provider->Init() &&
Alex Deymoc83baf62014-04-02 17:43:35 -070060 random_provider->Init() &&
Alex Deymo94c06162014-03-21 20:34:46 -070061 shill_provider->Init() &&
62 system_provider->Init() &&
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070063 time_provider->Init() &&
64 updater_provider->Init())) {
Alex Deymo94c06162014-03-21 20:34:46 -070065 LOG(ERROR) << "Error initializing providers";
Alex Vakulenko88b591f2014-08-28 16:48:57 -070066 return nullptr;
Alex Deymo94c06162014-03-21 20:34:46 -070067 }
68
David Zeuthen4e89e2c2014-04-24 11:47:00 -070069 return new RealState(config_provider.release(),
70 device_policy_provider.release(),
71 random_provider.release(),
72 shill_provider.release(),
73 system_provider.release(),
74 time_provider.release(),
75 updater_provider.release());
Alex Deymo94c06162014-03-21 20:34:46 -070076}
77
Alex Deymo63784a52014-05-28 10:46:14 -070078} // namespace chromeos_update_manager