blob: 9bd028a35beda862a6e6ec39e78d1207ee01462a [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
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070023#include "update_engine/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,
41 chromeos_update_engine::SystemState* system_state) {
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070042 chromeos_update_engine::ClockInterface* const clock = system_state->clock();
Ben Chan02f7c1d2014-10-18 15:18:02 -070043 unique_ptr<RealConfigProvider> config_provider(
Gilad Arnold48e13612014-05-16 10:18:05 -070044 new RealConfigProvider(system_state->hardware()));
Ben Chan02f7c1d2014-10-18 15:18:02 -070045 unique_ptr<RealDevicePolicyProvider> device_policy_provider(
Alex Deymo30534502015-07-20 15:06:33 -070046 new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
Ben Chan02f7c1d2014-10-18 15:18:02 -070047 unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
48 unique_ptr<RealShillProvider> shill_provider(
Alex Deymo30534502015-07-20 15:06:33 -070049 new RealShillProvider(shill_proxy, clock));
Ben Chan02f7c1d2014-10-18 15:18:02 -070050 unique_ptr<RealSystemProvider> system_provider(
Gilad Arnold48e13612014-05-16 10:18:05 -070051 new RealSystemProvider(system_state->hardware()));
Ben Chan02f7c1d2014-10-18 15:18:02 -070052 unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
53 unique_ptr<RealUpdaterProvider> updater_provider(
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070054 new RealUpdaterProvider(system_state));
Alex Deymo94c06162014-03-21 20:34:46 -070055
Alex Deymof9f12632014-04-17 13:51:26 -070056 if (!(config_provider->Init() &&
57 device_policy_provider->Init() &&
Alex Deymoc83baf62014-04-02 17:43:35 -070058 random_provider->Init() &&
Alex Deymo94c06162014-03-21 20:34:46 -070059 shill_provider->Init() &&
60 system_provider->Init() &&
Gilad Arnoldae47a9a2014-03-26 12:16:47 -070061 time_provider->Init() &&
62 updater_provider->Init())) {
Alex Deymo94c06162014-03-21 20:34:46 -070063 LOG(ERROR) << "Error initializing providers";
Alex Vakulenko88b591f2014-08-28 16:48:57 -070064 return nullptr;
Alex Deymo94c06162014-03-21 20:34:46 -070065 }
66
David Zeuthen4e89e2c2014-04-24 11:47:00 -070067 return new RealState(config_provider.release(),
68 device_policy_provider.release(),
69 random_provider.release(),
70 shill_provider.release(),
71 system_provider.release(),
72 time_provider.release(),
73 updater_provider.release());
Alex Deymo94c06162014-03-21 20:34:46 -070074}
75
Alex Deymo63784a52014-05-28 10:46:14 -070076} // namespace chromeos_update_manager