Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 5 | #include "update_engine/real_system_state.h" |
| 6 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 7 | #include <base/file_util.h> |
| 8 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 9 | #include "update_engine/constants.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 10 | #include "update_engine/update_manager/state_factory.h" |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 11 | #include "update_engine/utils.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 15 | RealSystemState::RealSystemState() |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 16 | : device_policy_(nullptr), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 17 | connection_manager_(this), |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 18 | update_attempter_(this, &dbus_), |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 19 | request_params_(this), |
| 20 | system_rebooted_(false) {} |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 21 | |
Nam T. Nguyen | 7d623eb | 2014-05-13 16:06:28 -0700 | [diff] [blame] | 22 | bool RealSystemState::Initialize() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 23 | metrics_lib_.Init(); |
| 24 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 25 | if (!prefs_.Init(base::FilePath(kPrefsDirectory))) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 26 | LOG(ERROR) << "Failed to initialize preferences."; |
| 27 | return false; |
| 28 | } |
| 29 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 30 | if (!powerwash_safe_prefs_.Init(base::FilePath(kPowerwashSafePrefsDir))) { |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 31 | LOG(ERROR) << "Failed to initialize powerwash preferences."; |
| 32 | return false; |
| 33 | } |
| 34 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 35 | if (!utils::FileExists(kSystemRebootedMarkerFile)) { |
| 36 | if (!utils::WriteFile(kSystemRebootedMarkerFile, "", 0)) { |
| 37 | LOG(ERROR) << "Could not create reboot marker file"; |
| 38 | return false; |
| 39 | } |
| 40 | system_rebooted_ = true; |
| 41 | } |
| 42 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 43 | p2p_manager_.reset(P2PManager::Construct(NULL, &prefs_, "cros_au", |
| 44 | kMaxP2PFilesToKeep)); |
| 45 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 46 | // Initialize the Update Manager using the default state factory. |
| 47 | chromeos_update_manager::State* um_state = |
| 48 | chromeos_update_manager::DefaultStateFactory( |
Alex Deymo | 680d022 | 2014-04-24 21:00:08 -0700 | [diff] [blame] | 49 | &policy_provider_, &dbus_, this); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 50 | if (!um_state) { |
| 51 | LOG(ERROR) << "Failed to initialize the Update Manager."; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 52 | return false; |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 53 | } |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 54 | update_manager_.reset( |
| 55 | new chromeos_update_manager::UpdateManager(&clock_, um_state)); |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 56 | |
| 57 | if (!payload_state_.Initialize(this)) { |
| 58 | LOG(ERROR) << "Failed to initialize the payload state object."; |
| 59 | return false; |
| 60 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 61 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 62 | // Initialize the update attempter. |
| 63 | update_attempter_.Init(); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 64 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 65 | // All is well. Initialization successful. |
| 66 | return true; |
| 67 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 68 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 69 | } // namespace chromeos_update_engine |