OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_ | |
6 #define COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_ | |
7 | |
8 #include <signal.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/files/file_descriptor_watcher_posix.h" | |
13 #include "base/files/scoped_file.h" | |
14 | |
15 namespace arc { | |
16 | |
17 // Helper class to set up service-like processes. | |
18 class ServiceHelper { | |
19 public: | |
20 ServiceHelper(); | |
21 ~ServiceHelper(); | |
22 | |
23 // Must be called after message loop instantiation. | |
24 void Init(const base::Closure& closure); | |
25 | |
26 private: | |
27 void OnFileCanReadWithoutBlocking(); | |
28 | |
29 static void TerminationHandler(int /* signum */); | |
30 | |
31 // Static variable to guarantee instantiated only once per process. | |
32 static ServiceHelper* self_; | |
33 | |
34 base::Closure closure_; | |
35 base::ScopedFD read_fd_; | |
36 base::ScopedFD write_fd_; | |
37 std::unique_ptr<base::FileDescriptorWatcher::Controller> watch_controller_; | |
38 struct sigaction old_sigint_; | |
39 struct sigaction old_sigterm_; | |
40 | |
41 DISALLOW_COPY_AND_ASSIGN(ServiceHelper); | |
42 }; | |
43 | |
44 } // namespace arc | |
45 | |
46 #endif // COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_ | |
OLD | NEW |