• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include "update_engine/common/clock_interface.h"
24 #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"
32 
33 using std::unique_ptr;
34 
35 namespace chromeos_update_manager {
36 
DefaultStateFactory(policy::PolicyProvider * policy_provider,chromeos_update_engine::ShillProxy * shill_proxy,org::chromium::SessionManagerInterfaceProxyInterface * session_manager_proxy,chromeos_update_engine::SystemState * system_state)37 State* 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) {
42   chromeos_update_engine::ClockInterface* const clock = system_state->clock();
43   unique_ptr<RealConfigProvider> config_provider(
44       new RealConfigProvider(system_state->hardware()));
45   unique_ptr<RealDevicePolicyProvider> device_policy_provider(
46       new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
47   unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
48   unique_ptr<RealShillProvider> shill_provider(
49       new RealShillProvider(shill_proxy, clock));
50   unique_ptr<RealSystemProvider> system_provider(
51       new RealSystemProvider(system_state->hardware(),
52                              system_state->boot_control()));
53   unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
54   unique_ptr<RealUpdaterProvider> updater_provider(
55       new RealUpdaterProvider(system_state));
56 
57   if (!(config_provider->Init() &&
58         device_policy_provider->Init() &&
59         random_provider->Init() &&
60         shill_provider->Init() &&
61         system_provider->Init() &&
62         time_provider->Init() &&
63         updater_provider->Init())) {
64     LOG(ERROR) << "Error initializing providers";
65     return nullptr;
66   }
67 
68   return new RealState(config_provider.release(),
69                        device_policy_provider.release(),
70                        random_provider.release(),
71                        shill_provider.release(),
72                        system_provider.release(),
73                        time_provider.release(),
74                        updater_provider.release());
75 }
76 
77 }  // namespace chromeos_update_manager
78