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