Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / bootstrap_sandbox_mac.cc
blobc4662ada4f48b2bb01735e9db116e68a5fb0b236
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(
35 const ChildProcessData& data,
36 int exit_code) override;
38 private:
39 friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>;
40 BootstrapSandboxPolicy();
41 ~BootstrapSandboxPolicy() override;
43 void RegisterSandboxPolicies();
45 scoped_ptr<sandbox::BootstrapSandbox> sandbox_;
48 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() {
49 return Singleton<BootstrapSandboxPolicy>::get();
52 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected(
53 const ChildProcessData& data) {
54 sandbox()->ChildDied(data.handle);
57 void BootstrapSandboxPolicy::BrowserChildProcessCrashed(
58 const ChildProcessData& data,
59 int exit_code) {
60 sandbox()->ChildDied(data.handle);
63 BootstrapSandboxPolicy::BootstrapSandboxPolicy()
64 : sandbox_(sandbox::BootstrapSandbox::Create()) {
65 CHECK(sandbox_.get());
66 BrowserChildProcessObserver::Add(this);
67 RegisterSandboxPolicies();
70 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {
71 BrowserChildProcessObserver::Remove(this);
74 void BootstrapSandboxPolicy::RegisterSandboxPolicies() {
77 } // namespace
79 bool ShouldEnableBootstrapSandbox() {
80 return base::mac::IsOSMountainLionOrEarlier() ||
81 base::mac::IsOSMavericks();
84 sandbox::BootstrapSandbox* GetBootstrapSandbox() {
85 return BootstrapSandboxPolicy::GetInstance()->sandbox();
88 } // namespace content