OLD | NEW |
1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef LOGIN_MANAGER_CHILD_JOB_H_ | 5 #ifndef LOGIN_MANAGER_CHILD_JOB_H_ |
6 #define LOGIN_MANAGER_CHILD_JOB_H_ | 6 #define LOGIN_MANAGER_CHILD_JOB_H_ |
7 | 7 |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
| 9 #include <time.h> |
9 #include <unistd.h> | 10 #include <unistd.h> |
10 | 11 |
11 #include <base/basictypes.h> | 12 #include <base/basictypes.h> |
12 #include <base/scoped_ptr.h> | 13 #include <base/scoped_ptr.h> |
13 | 14 |
14 #include "login_manager/file_checker.h" | 15 #include "login_manager/file_checker.h" |
15 | 16 |
16 class CommandLine; | 17 class CommandLine; |
17 | 18 |
18 namespace login_manager { | 19 namespace login_manager { |
19 // SessionManager takes a ChildJob object, forks and then calls the ChildJob's | 20 // SessionManager takes a ChildJob object, forks and then calls the ChildJob's |
20 // Run() method. I've created this interface so that I can create mocks for | 21 // Run() method. I've created this interface so that I can create mocks for |
21 // unittesting SessionManager. | 22 // unittesting SessionManager. |
22 class ChildJob { | 23 class ChildJob { |
23 public: | 24 public: |
24 ChildJob() {} | 25 ChildJob() {} |
25 virtual ~ChildJob() {} | 26 virtual ~ChildJob() {} |
26 | 27 |
27 virtual bool ShouldRun() = 0; | 28 virtual bool ShouldRun() = 0; |
28 | 29 |
| 30 // ShouldStop() is different from !ShouldRun(). If ShouldStop() returns |
| 31 // true, this means that the parent should tear everything down. |
| 32 virtual bool ShouldStop() = 0; |
| 33 |
| 34 virtual void RecordTime() = 0; |
| 35 |
29 // Wraps up all the logic of what the job is meant to do. Should NOT return. | 36 // Wraps up all the logic of what the job is meant to do. Should NOT return. |
30 virtual void Run() = 0; | 37 virtual void Run() = 0; |
31 | 38 |
32 // If the ChildJob contains a toggleable piece of state, toggle it. | 39 // If the ChildJob contains a toggleable piece of state, toggle it. |
33 virtual void Toggle() = 0; | 40 virtual void Toggle() = 0; |
34 }; | 41 }; |
35 | 42 |
36 class SetUidExecJob : public ChildJob { | 43 class SetUidExecJob : public ChildJob { |
37 public: | 44 public: |
38 SetUidExecJob(const CommandLine* command_line, | 45 SetUidExecJob(const CommandLine* command_line, |
39 FileChecker* checker, // Takes ownership. | 46 FileChecker* checker, // Takes ownership. |
40 const bool add_flag); | 47 const bool add_flag); |
41 virtual ~SetUidExecJob(); | 48 virtual ~SetUidExecJob(); |
42 | 49 |
43 // The flag to pass to chrome to tell it to behave as the login manager. | 50 // The flag to pass to chrome to tell it to behave as the login manager. |
44 static const char kLoginManagerFlag[]; | 51 static const char kLoginManagerFlag[]; |
45 | 52 |
46 // Potential exit codes for Run(). | 53 // Potential exit codes for Run(). |
47 static const int kCantSetuid; | 54 static const int kCantSetuid; |
48 static const int kCantSetgid; | 55 static const int kCantSetgid; |
49 static const int kCantSetgroups; | 56 static const int kCantSetgroups; |
50 static const int kCantExec; | 57 static const int kCantExec; |
51 | 58 |
52 bool ShouldRun(); | 59 bool ShouldRun(); |
| 60 bool ShouldStop(); |
| 61 void RecordTime(); |
53 void Run(); | 62 void Run(); |
54 void Toggle() { include_login_flag_ = !include_login_flag_; } | 63 void Toggle() { include_login_flag_ = !include_login_flag_; } |
55 | 64 |
56 void set_uid(uid_t uid) { | 65 void set_uid(uid_t uid) { |
57 desired_uid_ = uid; | 66 desired_uid_ = uid; |
58 set_uid_ = true; | 67 set_uid_ = true; |
59 } | 68 } |
60 | 69 |
61 protected: | 70 protected: |
62 std::vector<std::string> ExtractArgvForTest(); | 71 std::vector<std::string> ExtractArgvForTest(); |
(...skipping 15 matching lines...) Expand all Loading... |
78 int SetIDs(); | 87 int SetIDs(); |
79 | 88 |
80 private: | 89 private: |
81 scoped_ptr<FileChecker> checker_; | 90 scoped_ptr<FileChecker> checker_; |
82 char const* *argv_; | 91 char const* *argv_; |
83 uint32 num_args_passed_in_; | 92 uint32 num_args_passed_in_; |
84 | 93 |
85 uid_t desired_uid_; | 94 uid_t desired_uid_; |
86 bool include_login_flag_; // This class' piece of toggleable state. | 95 bool include_login_flag_; // This class' piece of toggleable state. |
87 bool set_uid_; | 96 bool set_uid_; |
| 97 time_t last_start_; |
88 | 98 |
89 FRIEND_TEST(SetUidExecJobTest, FlagAppendTest); | 99 FRIEND_TEST(SetUidExecJobTest, FlagAppendTest); |
90 FRIEND_TEST(SetUidExecJobTest, NoFlagAppendTest); | 100 FRIEND_TEST(SetUidExecJobTest, NoFlagAppendTest); |
91 FRIEND_TEST(SetUidExecJobTest, PopulateArgvTest); | 101 FRIEND_TEST(SetUidExecJobTest, PopulateArgvTest); |
92 DISALLOW_COPY_AND_ASSIGN(SetUidExecJob); | 102 DISALLOW_COPY_AND_ASSIGN(SetUidExecJob); |
93 | 103 |
94 }; | 104 }; |
95 } // namespace login_manager | 105 } // namespace login_manager |
96 | 106 |
97 #endif // LOGIN_MANAGER_CHILD_JOB_H_ | 107 #endif // LOGIN_MANAGER_CHILD_JOB_H_ |
OLD | NEW |