Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / bootstrap_sandbox_mac.cc
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.
4
5 #include "content/browser/bootstrap_sandbox_mac.h"
6
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"
16
17 namespace content {
18
19 namespace {
20
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();
26
27   sandbox::BootstrapSandbox* sandbox() const {
28     return sandbox_.get();
29   }
30
31   // BrowserChildProcessObserver:
32   void BrowserChildProcessHostDisconnected(
33       const ChildProcessData& data) override;
34   void BrowserChildProcessCrashed(const ChildProcessData& data) override;
35
36  private:
37   friend struct DefaultSingletonTraits<BootstrapSandboxPolicy>;
38   BootstrapSandboxPolicy();
39   ~BootstrapSandboxPolicy() override;
40
41   void RegisterSandboxPolicies();
42
43   scoped_ptr<sandbox::BootstrapSandbox> sandbox_;
44 };
45
46 BootstrapSandboxPolicy* BootstrapSandboxPolicy::GetInstance() {
47   return Singleton<BootstrapSandboxPolicy>::get();
48 }
49
50 void BootstrapSandboxPolicy::BrowserChildProcessHostDisconnected(
51       const ChildProcessData& data) {
52   sandbox()->ChildDied(data.handle);
53 }
54
55 void BootstrapSandboxPolicy::BrowserChildProcessCrashed(
56       const ChildProcessData& data) {
57   sandbox()->ChildDied(data.handle);
58 }
59
60 BootstrapSandboxPolicy::BootstrapSandboxPolicy()
61     : sandbox_(sandbox::BootstrapSandbox::Create()) {
62   CHECK(sandbox_.get());
63   BrowserChildProcessObserver::Add(this);
64   RegisterSandboxPolicies();
65 }
66
67 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {
68   BrowserChildProcessObserver::Remove(this);
69 }
70
71 void BootstrapSandboxPolicy::RegisterSandboxPolicies() {
72 }
73
74 }  // namespace
75
76 bool ShouldEnableBootstrapSandbox() {
77   return base::mac::IsOSMountainLionOrEarlier() ||
78          base::mac::IsOSMavericks();
79 }
80
81 sandbox::BootstrapSandbox* GetBootstrapSandbox() {
82   return BootstrapSandboxPolicy::GetInstance()->sandbox();
83 }
84
85 }  // namespace content