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 | |
| 5 | #include <base/file_util.h> |
| 6 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 7 | #include "update_engine/real_system_state.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 8 | |
| 9 | namespace chromeos_update_engine { |
| 10 | |
| 11 | static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 12 | static const char kPrefsDirectory[] = "/var/lib/update_engine/prefs"; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 13 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 14 | RealSystemState::RealSystemState() |
| 15 | : device_policy_(NULL), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 16 | connection_manager_(this), |
| 17 | request_params_(this) {} |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 18 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 19 | bool RealSystemState::Initialize(bool enable_gpio) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 20 | metrics_lib_.Init(); |
| 21 | |
| 22 | if (!prefs_.Init(FilePath(kPrefsDirectory))) { |
| 23 | LOG(ERROR) << "Failed to initialize preferences."; |
| 24 | return false; |
| 25 | } |
| 26 | |
Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 27 | if (!payload_state_.Initialize(this)) |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 28 | return false; |
| 29 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 30 | // Initialize the GPIO handler as instructed. |
| 31 | if (enable_gpio) { |
| 32 | // A real GPIO handler. Defer GPIO discovery to ensure the udev has ample |
| 33 | // time to export the devices. Also require that test mode is physically |
| 34 | // queried at most once and the result cached, for a more consistent update |
| 35 | // behavior. |
| 36 | udev_iface_.reset(new StandardUdevInterface()); |
| 37 | file_descriptor_.reset(new EintrSafeFileDescriptor()); |
| 38 | gpio_handler_.reset(new StandardGpioHandler(udev_iface_.get(), |
| 39 | file_descriptor_.get(), |
| 40 | true, true)); |
| 41 | } else { |
| 42 | // A no-op GPIO handler, always indicating a non-test mode. |
| 43 | gpio_handler_.reset(new NoopGpioHandler(false)); |
| 44 | } |
| 45 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 46 | // Create the update attempter. |
| 47 | update_attempter_.reset(new UpdateAttempter(this, &dbus_)); |
| 48 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 49 | // All is well. Initialization successful. |
| 50 | return true; |
| 51 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 52 | |
| 53 | bool RealSystemState::IsOOBEComplete() { |
| 54 | return file_util::PathExists(FilePath(kOOBECompletedMarker)); |
| 55 | } |
| 56 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 57 | } // namespace chromeos_update_engine |