cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / sandbox / linux / services / broker_process.h
blob901ae5077c0faead6e5c68abfbaf5d565a380ea9
1 // Copyright (c) 2012 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.
5 #ifndef SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_
6 #define SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/pickle.h"
13 #include "base/process/process.h"
15 namespace sandbox {
17 // Create a new "broker" process to which we can send requests via an IPC
18 // channel.
19 // This is a low level IPC mechanism that is suitable to be called from a
20 // signal handler.
21 // A process would typically create a broker process before entering
22 // sandboxing.
23 // 1. BrokerProcess open_broker(read_whitelist, write_whitelist);
24 // 2. CHECK(open_broker.Init(NULL));
25 // 3. Enable sandbox.
26 // 4. Use open_broker.Open() to open files.
27 class BrokerProcess {
28 public:
29 // |allowed_file_names| is a white list of files that can be opened later via
30 // the Open() API.
31 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for
32 // unit tests, don't use it.
33 explicit BrokerProcess(const std::vector<std::string>& allowed_r_files_,
34 const std::vector<std::string>& allowed_w_files_,
35 bool fast_check_in_client = true,
36 bool quiet_failures_for_tests = false);
37 ~BrokerProcess();
38 // Will initialize the broker process. There should be no threads at this
39 // point, since we need to fork().
40 // sandbox_callback is a function that should be called to enable the
41 // sandbox in the broker.
42 bool Init(bool (*sandbox_callback)(void));
44 // Can be used in place of access(). Will be async signal safe.
45 // X_OK will always EPERM in practice since the broker process doesn't support
46 // execute permissions.
47 // It's similar to the access() system call and will return -errno on errors.
48 int Access(const char* pathname, int mode) const;
49 // Can be used in place of open(). Will be async signal safe.
50 // The implementation only supports certain white listed flags and will
51 // return -EPERM on other flags.
52 // It's similar to the open() system call and will return -errno on errors.
53 int Open(const char* pathname, int flags) const;
55 int broker_pid() const { return broker_pid_; }
57 private:
58 enum IPCCommands {
59 kCommandInvalid = 0,
60 kCommandOpen,
61 kCommandAccess,
63 int PathAndFlagsSyscall(enum IPCCommands command_type,
64 const char* pathname, int flags) const;
65 bool HandleRequest() const;
66 bool HandleRemoteCommand(IPCCommands command_type, int reply_ipc,
67 const Pickle& read_pickle, PickleIterator iter) const;
69 void AccessFileForIPC(const std::string& requested_filename,
70 int mode, Pickle* write_pickle) const;
71 void OpenFileForIPC(const std::string& requested_filename,
72 int flags, Pickle* write_pickle,
73 std::vector<int>* opened_files) const;
74 bool GetFileNameIfAllowedToAccess(const char*, int, const char**) const;
75 bool GetFileNameIfAllowedToOpen(const char*, int, const char**) const;
76 bool initialized_; // Whether we've been through Init() yet.
77 bool is_child_; // Whether we're the child (broker process).
78 bool fast_check_in_client_; // Whether to forward a request that we know
79 // will be denied to the broker.
80 bool quiet_failures_for_tests_; // Disable certain error message when
81 // testing for failures.
82 pid_t broker_pid_; // The PID of the broker (child).
83 const std::vector<std::string> allowed_r_files_; // Files allowed for read.
84 const std::vector<std::string> allowed_w_files_; // Files allowed for write.
85 int ipc_socketpair_; // Our communication channel to parent or child.
86 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess);
89 } // namespace sandbox
91 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_