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 //
16
17 #include "update_engine/update_manager/state_factory.h"
18
19 #include <memory>
20
21 #include <base/logging.h>
22 #if USE_DBUS
23 #include <session_manager/dbus-proxies.h>
24 #endif // USE_DBUS
25
26 #if USE_DBUS
27 #include "update_engine/cros/dbus_connection.h"
28 #endif // USE_DBUS
29 #include "update_engine/common/system_state.h"
30 #include "update_engine/cros/shill_proxy.h"
31 #include "update_engine/update_manager/fake_shill_provider.h"
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"
35 #include "update_engine/update_manager/real_shill_provider.h"
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"
40
41 using chromeos_update_engine::SystemState;
42 using std::unique_ptr;
43
44 namespace chromeos_update_manager {
45
DefaultStateFactory(policy::PolicyProvider * policy_provider,org::chromium::KioskAppServiceInterfaceProxyInterface * kiosk_app_proxy)46 State* DefaultStateFactory(
47 policy::PolicyProvider* policy_provider,
48 org::chromium::KioskAppServiceInterfaceProxyInterface* kiosk_app_proxy) {
49 unique_ptr<RealConfigProvider> config_provider(
50 new RealConfigProvider(SystemState::Get()->hardware()));
51 #if USE_DBUS
52 scoped_refptr<dbus::Bus> bus =
53 chromeos_update_engine::DBusConnection::Get()->GetDBus();
54 unique_ptr<RealDevicePolicyProvider> device_policy_provider(
55 new RealDevicePolicyProvider(
56 std::make_unique<org::chromium::SessionManagerInterfaceProxy>(bus),
57 policy_provider));
58 #else
59 unique_ptr<RealDevicePolicyProvider> device_policy_provider(
60 new RealDevicePolicyProvider(policy_provider));
61 #endif // USE_DBUS
62 unique_ptr<RealShillProvider> shill_provider(
63 new RealShillProvider(new chromeos_update_engine::ShillProxy()));
64 unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
65 unique_ptr<RealSystemProvider> system_provider(
66 new RealSystemProvider(kiosk_app_proxy));
67
68 unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider());
69 unique_ptr<RealUpdaterProvider> updater_provider(new RealUpdaterProvider());
70
71 if (!(config_provider->Init() && device_policy_provider->Init() &&
72 random_provider->Init() &&
73 shill_provider->Init() &&
74 system_provider->Init() && time_provider->Init() &&
75 updater_provider->Init())) {
76 LOG(ERROR) << "Error initializing providers";
77 return nullptr;
78 }
79
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());
87 }
88
89 } // namespace chromeos_update_manager
90