1 // Copyright 2020 The Chromium 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 #ifndef CHROMECAST_SYSTEM_REBOOT_FUCHSIA_COMPONENT_RESTART_REASON_H_ 6 #define CHROMECAST_SYSTEM_REBOOT_FUCHSIA_COMPONENT_RESTART_REASON_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/strings/string_piece.h" 10 #include "chromecast/public/reboot_shlib.h" 11 12 namespace chromecast { 13 14 // This class tracks the restart reason of the Cast component using temp files 15 // to indicate whether it restarts gracefully or ungracefully. On Fuchsia, the 16 // Cast component can restart according to plan, or by platform request, 17 // without the need for the device to reboot. 18 // No more than one instance of this class variable should be used per component 19 // to guarantee the correctness of the restart reason. 20 // 21 // The caller/user of this class must provide isolated-temp feature in sandbox. 22 class FuchsiaComponentRestartReason { 23 public: 24 FuchsiaComponentRestartReason(); 25 26 // Whether the component restarted and if so, for which reason (graceful or 27 // ungraceful). 28 bool GetRestartReason(RebootShlib::RebootSource* restart_reason); 29 30 // Registers a graceful teardown of the component so we can distinguish 31 // between the first start of a boot cycle and a restart during the same 32 // boot cycle. 33 void RegisterTeardown(); 34 35 // This can be called once during initialization (not necessary). 36 // But is necessary during testing if SetUp is shared. 37 void ResetRestartCheck(); 38 39 // Change tmp folder path for testing purpose. 40 // Not necessary for production use. 41 const base::FilePath& SetFlagFileDirForTesting(const base::FilePath& sub); 42 43 private: 44 // To change tmp directory for testing purpose when run in parallel. 45 base::FilePath tmp_dir_; 46 47 bool restart_checked_ = false; 48 bool was_restart_ = true; 49 RebootShlib::RebootSource restart_reason_{RebootShlib::RebootSource::UNKNOWN}; 50 }; 51 52 } // namespace chromecast 53 54 #endif // CHROMECAST_SYSTEM_REBOOT_FUCHSIA_COMPONENT_RESTART_REASON_H_ 55