Revert of Add DumpAccessibilityEvents test framework. (patchset #7 id:120001 of https...
[chromium-blink-merge.git] / content / browser / bootstrap_sandbox_mac.cc
blob2361563b1972647ea422e7350856d14a9e5e7035
1 // Copyright 2014 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 #include "content/browser/bootstrap_sandbox_mac.h"
7 #include "base/logging.h"
8 #include "base/mac/mac_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/singleton.h"
11 #include "content/common/sandbox_init_mac.h"
12 #include "content/public/browser/browser_child_process_observer.h"
13 #include "content/public/browser/child_process_data.h"
14 #include "content/public/common/sandbox_type_mac.h"
15 #include "sandbox/mac/bootstrap_sandbox.h"
17 namespace content {
19 namespace {
21 // This class is responsible for creating the BootstrapSandbox global
22 // singleton, as well as registering all associated policies with it.
23 class BootstrapSandboxPolicy : public BrowserChildProcessObserver {
24 public:
25 static BootstrapSandboxPolicy* GetInstance();
27 sandbox::BootstrapSandbox* sandbox() const {
28 return sandbox_.get();
31 // BrowserChildProcessObserver:
32 void BrowserChildProcessHostDisconnected(
33 const ChildProcessData& data) override;
34 void BrowserChildProcessCrashed(const ChildProcessData& data) override;
36 private:
37 friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>;
38 BootstrapSandboxPolicy();
39 ~BootstrapSandboxPolicy() override;
41 void RegisterSandboxPolicies();
43 scoped_ptr<sandbox::BootstrapSandbox> sandbox_;
46 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() {
47 return Singleton<BootstrapSandboxPolicy>::get();
50 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected(
51 const ChildProcessData& data) {
52 sandbox()->ChildDied(data.handle);
55 void BootstrapSandboxPolicy::BrowserChildProcessCrashed(
56 const ChildProcessData& data) {
57 sandbox()->ChildDied(data.handle);
60 BootstrapSandboxPolicy::BootstrapSandboxPolicy()
61 : sandbox_(sandbox::BootstrapSandbox::Create()) {
62 CHECK(sandbox_.get());
63 BrowserChildProcessObserver::Add(this);
64 RegisterSandboxPolicies();
67 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {
68 BrowserChildProcessObserver::Remove(this);
71 void BootstrapSandboxPolicy::RegisterSandboxPolicies() {
74 } // namespace
76 bool ShouldEnableBootstrapSandbox() {
77 return base::mac::IsOSMountainLionOrEarlier() ||
78 base::mac::IsOSMavericks();
81 sandbox::BootstrapSandbox* GetBootstrapSandbox() {
82 return BootstrapSandboxPolicy::GetInstance()->sandbox();
85 } // namespace content