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 | |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 7 | #include <base/files/file_util.h> |
Gilad Arnold | b227199 | 2014-06-19 12:35:24 -0700 | [diff] [blame] | 8 | #include <base/time/time.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 9 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 10 | #include "update_engine/constants.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 11 | #include "update_engine/update_manager/state_factory.h" |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 12 | #include "update_engine/utils.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 13 | |
| 14 | namespace chromeos_update_engine { |
| 15 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 16 | RealSystemState::RealSystemState() |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 17 | : device_policy_(nullptr), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 18 | connection_manager_(this), |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 19 | update_attempter_(this, &dbus_), |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 20 | request_params_(this), |
| 21 | system_rebooted_(false) {} |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 22 | |
Nam T. Nguyen | 7d623eb | 2014-05-13 16:06:28 -0700 | [diff] [blame] | 23 | bool RealSystemState::Initialize() { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 24 | metrics_lib_.Init(); |
| 25 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 26 | if (!prefs_.Init(base::FilePath(kPrefsDirectory))) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 27 | LOG(ERROR) << "Failed to initialize preferences."; |
| 28 | return false; |
| 29 | } |
| 30 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 31 | if (!powerwash_safe_prefs_.Init(base::FilePath(kPowerwashSafePrefsDir))) { |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 32 | LOG(ERROR) << "Failed to initialize powerwash preferences."; |
| 33 | return false; |
| 34 | } |
| 35 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 36 | if (!utils::FileExists(kSystemRebootedMarkerFile)) { |
| 37 | if (!utils::WriteFile(kSystemRebootedMarkerFile, "", 0)) { |
| 38 | LOG(ERROR) << "Could not create reboot marker file"; |
| 39 | return false; |
| 40 | } |
| 41 | system_rebooted_ = true; |
| 42 | } |
| 43 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 44 | // Initialize the Update Manager using the default state factory. |
| 45 | chromeos_update_manager::State* um_state = |
| 46 | chromeos_update_manager::DefaultStateFactory( |
Alex Deymo | 680d022 | 2014-04-24 21:00:08 -0700 | [diff] [blame] | 47 | &policy_provider_, &dbus_, this); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 48 | if (!um_state) { |
| 49 | LOG(ERROR) << "Failed to initialize the Update Manager."; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 50 | return false; |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 51 | } |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 52 | update_manager_.reset( |
Gilad Arnold | b227199 | 2014-06-19 12:35:24 -0700 | [diff] [blame] | 53 | new chromeos_update_manager::UpdateManager( |
Gilad Arnold | fd45a73 | 2014-08-07 15:53:46 -0700 | [diff] [blame] | 54 | &clock_, base::TimeDelta::FromSeconds(5), |
| 55 | base::TimeDelta::FromHours(12), um_state)); |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 56 | |
Gilad Arnold | 4a0321b | 2014-10-28 15:57:30 -0700 | [diff] [blame] | 57 | // The P2P Manager depends on the Update Manager for its initialization. |
| 58 | p2p_manager_.reset(P2PManager::Construct( |
| 59 | nullptr, &clock_, update_manager_.get(), "cros_au", |
| 60 | kMaxP2PFilesToKeep, base::TimeDelta::FromDays(kMaxP2PFileAgeDays))); |
| 61 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 62 | if (!payload_state_.Initialize(this)) { |
| 63 | LOG(ERROR) << "Failed to initialize the payload state object."; |
| 64 | return false; |
| 65 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 66 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 67 | // Initialize the update attempter. |
| 68 | update_attempter_.Init(); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 69 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 70 | // All is well. Initialization successful. |
| 71 | return true; |
| 72 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 73 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 74 | } // namespace chromeos_update_engine |