WebUI: Update some more uses of the old-style i18ntemplate/LocalStrings.
[chromium-blink-merge.git] / content / browser / bootstrap_sandbox_mac.cc
blob347114a4b7d1e32b2a829bdd7354304e673bc1a8
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 virtual void BrowserChildProcessHostDisconnected(
33 const ChildProcessData& data) OVERRIDE;
34 virtual void BrowserChildProcessCrashed(
35 const ChildProcessData& data) OVERRIDE;
37 private:
38 friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>;
39 BootstrapSandboxPolicy();
40 virtual ~BootstrapSandboxPolicy();
42 void RegisterSandboxPolicies();
44 scoped_ptr<sandbox::BootstrapSandbox> sandbox_;
47 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() {
48 return Singleton<BootstrapSandboxPolicy>::get();
51 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected(
52 const ChildProcessData& data) {
53 sandbox()->ChildDied(data.handle);
56 void BootstrapSandboxPolicy::BrowserChildProcessCrashed(
57 const ChildProcessData& data) {
58 sandbox()->ChildDied(data.handle);
61 BootstrapSandboxPolicy::BootstrapSandboxPolicy()
62 : sandbox_(sandbox::BootstrapSandbox::Create()) {
63 CHECK(sandbox_.get());
64 BrowserChildProcessObserver::Add(this);
65 RegisterSandboxPolicies();
68 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {
69 BrowserChildProcessObserver::Remove(this);
72 void BootstrapSandboxPolicy::RegisterSandboxPolicies() {
75 } // namespace
77 bool ShouldEnableBootstrapSandbox() {
78 return base::mac::IsOSMountainLionOrEarlier() ||
79 base::mac::IsOSMavericks();
82 sandbox::BootstrapSandbox* GetBootstrapSandbox() {
83 return BootstrapSandboxPolicy::GetInstance()->sandbox();
86 } // namespace content