1 //
2 // Copyright (C) 2018 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 //
16 
17 #include <string>
18 
19 #include "update_engine/common/action.h"
20 #include "update_engine/common/boot_control_interface.h"
21 
22 #include <gtest/gtest_prod.h>
23 
24 namespace chromeos_update_engine {
25 
26 class UpdateBootFlagsAction : public AbstractAction {
27  public:
28   explicit UpdateBootFlagsAction(BootControlInterface* boot_control)
29       : boot_control_(boot_control) {}
30 
31   void PerformAction() override;
32 
33   void TerminateProcessing() override;
34 
35   static std::string StaticType() { return "UpdateBootFlagsAction"; }
36   std::string Type() const override { return StaticType(); }
37 
38   void CompleteUpdateBootFlags(bool successful);
39 
40  private:
41   FRIEND_TEST(UpdateBootFlagsActionTest, SimpleTest);
42   FRIEND_TEST(UpdateBootFlagsActionTest, DoubleActionTest);
43 
44   // Originally, both of these flags are false. Once UpdateBootFlags is called,
45   // |is_running_| is set to true. As soon as UpdateBootFlags completes its
46   // asynchronous run, |is_running_| is reset to false and |updated_boot_flags_|
47   // is set to true. From that point on there will be no more changes to these
48   // flags.
49   //
50   // True if have updated the boot flags.
51   static bool updated_boot_flags_;
52   // True if we are still updating the boot flags.
53   static bool is_running_;
54 
55   // Used for setting the boot flag.
56   BootControlInterface* boot_control_;
57 
58   DISALLOW_COPY_AND_ASSIGN(UpdateBootFlagsAction);
59 };
60 
61 }  // namespace chromeos_update_engine
62