summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-29 03:44:44 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-29 03:44:44 +0000
commitbadf5cf5f14c65f6c799ef1fec77cde8351339c2 (patch)
tree83690887c035e4b457f00404f126f95ad1a90c06
parent8cc9738eff9c169487e8356947d88640659fc497 (diff)
downloadchromium_src-badf5cf5f14c65f6c799ef1fec77cde8351339c2.zip
chromium_src-badf5cf5f14c65f6c799ef1fec77cde8351339c2.tar.gz
chromium_src-badf5cf5f14c65f6c799ef1fec77cde8351339c2.tar.bz2
Expose the sandbox related code through the content API. I did a bit of cleanup while I was doing this.
-got rid of SandboxInitWrapper, since I didn't see a need to expose given that we can just expose sandbox::SandboxInterfaceInfo -got rid of the duplicated code to initialize the broker -since I made MainFunctionParams only have the sandbox struct on Windows, I also made the mac specific auto release pool behind an ifdef as well. It seemed odd to make something so mac specific compile on all platforms to save some #ifdefs. BUG=98716 Review URL: http://codereview.chromium.org/8414020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107863 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mac/scoped_nsautorelease_pool.h20
-rw-r--r--base/message_pump_default.cc5
-rw-r--r--base/message_pump_libevent.cc7
-rw-r--r--base/shared_memory_unittest.cc13
-rw-r--r--base/test/test_suite.cc6
-rw-r--r--chrome/app/chrome_exe_main_win.cc2
-rw-r--r--chrome/browser/chrome_browser_main.cc15
-rw-r--r--chrome/browser/chrome_browser_main_unittest.cc16
-rw-r--r--chrome/browser/ui/panels/base_panel_browser_test.cc4
-rw-r--r--chrome/browser/ui/panels/panel_app_browsertest.cc7
-rw-r--r--chrome/chrome_exe.gypi2
-rw-r--r--chrome/common/service_process_util.cc1
-rw-r--r--chrome/nacl/DEPS2
-rw-r--r--chrome/nacl/nacl_exe_win_64.cc36
-rw-r--r--chrome/nacl/nacl_main.cc2
-rw-r--r--chrome/nacl/nacl_main_platform_delegate_mac.mm12
-rw-r--r--chrome/nacl/nacl_main_platform_delegate_win.cc6
-rw-r--r--chrome/service/DEPS1
-rw-r--r--chrome/service/service_main.cc9
-rw-r--r--chrome/test/base/chrome_test_launcher.cc2
-rw-r--r--chrome/test/base/chrome_test_suite.cc5
-rw-r--r--chrome/test/base/in_process_browser_test.cc17
-rw-r--r--chrome/test/pyautolib/pyautolib.cc2
-rw-r--r--chrome/test/pyautolib/pyautolib.h7
-rw-r--r--chrome/test/webdriver/commands/command.h6
-rw-r--r--content/app/content_main.cc42
-rw-r--r--content/app/startup_helper_win.cc2
-rw-r--r--content/browser/browser_main.cc28
-rw-r--r--content/browser/browser_main_loop.cc4
-rw-r--r--content/common/main_function_params.h28
-rw-r--r--content/common/sandbox_init_mac.cc (renamed from content/common/sandbox_init_wrapper_mac.cc)12
-rw-r--r--content/common/sandbox_init_win.cc63
-rw-r--r--content/common/sandbox_init_wrapper.h72
-rw-r--r--content/common/sandbox_init_wrapper_linux.cc13
-rw-r--r--content/common/sandbox_init_wrapper_win.cc50
-rw-r--r--content/content_app.gypi2
-rw-r--r--content/content_common.gypi7
-rw-r--r--content/gpu/gpu_main.cc4
-rw-r--r--content/plugin/plugin_main.cc4
-rw-r--r--content/ppapi_plugin/ppapi_broker_main.cc2
-rw-r--r--content/ppapi_plugin/ppapi_plugin_main.cc4
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc8
-rw-r--r--content/public/app/startup_helper_win.h (renamed from content/app/startup_helper_win.h)6
-rw-r--r--content/public/common/sandbox_init.h36
-rw-r--r--content/renderer/renderer_main.cc8
-rw-r--r--content/renderer/renderer_main_platform_delegate.h7
-rw-r--r--content/renderer/renderer_main_platform_delegate_mac.mm8
-rw-r--r--content/renderer/renderer_main_platform_delegate_win.cc8
-rw-r--r--content/shell/shell_main.cc2
-rw-r--r--content/test/browser_test_base.cc5
-rw-r--r--content/test/content_browser_test.cc14
-rw-r--r--content/test/content_test_launcher.cc2
-rw-r--r--content/test/render_view_test.cc5
-rw-r--r--content/test/render_view_test.h2
-rw-r--r--content/test/test_launcher.cc5
-rw-r--r--content/utility/utility_main.cc4
-rw-r--r--content/worker/worker_main.cc6
-rw-r--r--gpu/command_buffer/client/cmd_buffer_helper_test.cc7
-rw-r--r--gpu/command_buffer/client/fenced_allocator_test.cc7
-rw-r--r--gpu/command_buffer/client/mapped_memory_unittest.cc7
-rw-r--r--gpu/command_buffer/client/ring_buffer_test.cc7
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_unittest.cc7
-rw-r--r--remoting/host/simple_host_process.cc16
-rw-r--r--sandbox/src/sandbox_types.h9
-rw-r--r--webkit/tools/test_shell/run_all_tests.cc4
65 files changed, 363 insertions, 369 deletions
diff --git a/base/mac/scoped_nsautorelease_pool.h b/base/mac/scoped_nsautorelease_pool.h
index 3f73017..06122b6 100644
--- a/base/mac/scoped_nsautorelease_pool.h
+++ b/base/mac/scoped_nsautorelease_pool.h
@@ -9,31 +9,22 @@
#include "base/base_export.h"
#include "base/basictypes.h"
-#if defined(OS_MACOSX)
#if defined(__OBJC__)
@class NSAutoreleasePool;
#else // __OBJC__
class NSAutoreleasePool;
#endif // __OBJC__
-#endif // OS_MACOSX
namespace base {
namespace mac {
-// On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when
-// instantiated and sends it a -drain message when destroyed. This allows an
-// autorelease pool to be maintained in ordinary C++ code without bringing in
-// any direct Objective-C dependency.
-//
-// On other platforms, ScopedNSAutoreleasePool is an empty object with no
-// effects. This allows it to be used directly in cross-platform code without
-// ugly #ifdefs.
+// ScopedNSAutoreleasePool allocates an NSAutoreleasePool when instantiated and
+// sends it a -drain message when destroyed. This allows an autorelease pool to
+// be maintained in ordinary C++ code without bringing in any direct Objective-C
+// dependency.
+
class BASE_EXPORT ScopedNSAutoreleasePool {
public:
-#if !defined(OS_MACOSX)
- ScopedNSAutoreleasePool() {}
- void Recycle() { }
-#else // OS_MACOSX
ScopedNSAutoreleasePool();
~ScopedNSAutoreleasePool();
@@ -44,7 +35,6 @@ class BASE_EXPORT ScopedNSAutoreleasePool {
void Recycle();
private:
NSAutoreleasePool* autorelease_pool_;
-#endif // OS_MACOSX
private:
DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool);
diff --git a/base/message_pump_default.cc b/base/message_pump_default.cc
index d9eddc4..9a98064 100644
--- a/base/message_pump_default.cc
+++ b/base/message_pump_default.cc
@@ -5,7 +5,10 @@
#include "base/message_pump_default.h"
#include "base/logging.h"
+
+#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
namespace base {
@@ -18,7 +21,9 @@ void MessagePumpDefault::Run(Delegate* delegate) {
DCHECK(keep_running_) << "Quit must have been called outside of Run!";
for (;;) {
+#if defined(OS_MACOSX)
mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
bool did_work = delegate->DoWork();
if (!keep_running_)
diff --git a/base/message_pump_libevent.cc b/base/message_pump_libevent.cc
index 9bef229..23b707e 100644
--- a/base/message_pump_libevent.cc
+++ b/base/message_pump_libevent.cc
@@ -11,7 +11,6 @@
#include "base/compiler_specific.h"
#include "base/eintr_wrapper.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/time.h"
@@ -21,6 +20,10 @@
#include "third_party/libevent/event.h"
#endif
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
// Lifecycle of struct event
// Libevent uses two main data structures:
// struct event_base (of which there is one per message pump), and
@@ -228,7 +231,9 @@ void MessagePumpLibevent::Run(Delegate* delegate) {
scoped_ptr<event> timer_event(new event);
for (;;) {
+#if defined(OS_MACOSX)
mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
bool did_work = delegate->DoWork();
if (!keep_running_)
diff --git a/base/shared_memory_unittest.cc b/base/shared_memory_unittest.cc
index 330add4..9f69a5d 100644
--- a/base/shared_memory_unittest.cc
+++ b/base/shared_memory_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "base/basictypes.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "base/shared_memory.h"
#include "base/test/multiprocess_test.h"
@@ -12,6 +11,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
static const int kNumThreads = 5;
static const int kNumTasks = 5;
@@ -34,7 +37,9 @@ class MultipleThreadMain : public PlatformThread::Delegate {
// PlatformThread::Delegate interface.
void ThreadMain() {
- mac::ScopedNSAutoreleasePool pool; // noop if not OSX
+#if defined(OS_MACOSX)
+ mac::ScopedNSAutoreleasePool pool;
+#endif
const uint32 kDataSize = 1024;
SharedMemory memory;
bool rv = memory.CreateNamed(s_test_name_, true, kDataSize);
@@ -339,7 +344,9 @@ class SharedMemoryProcessTest : public MultiProcessTest {
static int TaskTestMain() {
int errors = 0;
- mac::ScopedNSAutoreleasePool pool; // noop if not OSX
+#if defined(OS_MACOSX)
+ mac::ScopedNSAutoreleasePool pool;
+#endif
const uint32 kDataSize = 1024;
SharedMemory memory;
bool rv = memory.CreateNamed(s_test_name_, true, kDataSize);
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index 912a6f9..05dfa31 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -13,7 +13,6 @@
#include "base/file_path.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/process_util.h"
@@ -24,6 +23,7 @@
#include "testing/multiprocess_func_list.h"
#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/test/mock_chrome_application_mac.h"
#endif
@@ -123,7 +123,9 @@ void TestSuite::CatchMaybeTests() {
// Don't add additional code to this method. Instead add it to
// Initialize(). See bug 6436.
int TestSuite::Run() {
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool scoped_pool;
+#endif
Initialize();
std::string client_func =
@@ -152,10 +154,12 @@ int TestSuite::Run() {
failing_count, failing_count == 1 ? "test" : "tests");
}
+#if defined(OS_MACOSX)
// This MUST happen before Shutdown() since Shutdown() tears down
// objects (such as NotificationService::current()) that Cocoa
// objects use to remove themselves as observers.
scoped_pool.Recycle();
+#endif
Shutdown();
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc
index 93b4871..0d7ca72 100644
--- a/chrome/app/chrome_exe_main_win.cc
+++ b/chrome/app/chrome_exe_main_win.cc
@@ -9,7 +9,7 @@
#include "base/command_line.h"
#include "chrome/app/breakpad_win.h"
#include "chrome/app/client_util.h"
-#include "content/app/startup_helper_win.h"
+#include "content/public/app/startup_helper_win.h"
#include "content/public/common/result_codes.h"
#include "sandbox/src/sandbox_factory.h"
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 36e5f0f..e74b7ba 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -14,7 +14,6 @@
#include "base/debug/trace_event.h"
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
@@ -175,6 +174,7 @@
#if defined(OS_MACOSX)
#include <Security/Security.h>
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/browser/mac/install_from_dmg.h"
#include "chrome/browser/mac/keystone_glue.h"
#endif
@@ -451,7 +451,7 @@ Profile* CreateProfile(const MainFunctionParams& parameters,
// --user-data-dir switch. The last flag of the same name wins.
// TODO(tc): It would be nice to remove the flag we don't want, but that
// sounds risky if we parse differently than CommandLineToArgvW.
- CommandLine new_command_line = parameters.command_line_;
+ CommandLine new_command_line = parameters.command_line;
new_command_line.AppendSwitchPath(switches::kUserDataDir,
new_user_data_dir);
base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
@@ -682,7 +682,7 @@ const char kMissingLocaleDataMessage[] =
ChromeBrowserMainParts::ChromeBrowserMainParts(
const MainFunctionParams& parameters)
: parameters_(parameters),
- parsed_command_line_(parameters.command_line_),
+ parsed_command_line_(parameters.command_line),
result_code_(content::RESULT_CODE_NORMAL_EXIT),
shutdown_watcher_(new ShutdownWatcherHelper()),
record_search_engine_(false),
@@ -1662,6 +1662,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
return content::RESULT_CODE_NORMAL_EXIT;
}
}
+ base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool;
#endif
// Show the First Run UI if this is the first time Chrome has been run on
@@ -1885,11 +1886,12 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
ThreadWatcherList::StartWatchingAll(parsed_command_line());
int result_code = content::RESULT_CODE_NORMAL_EXIT;
- base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_;
if (parameters().ui_task) {
// We are in test mode. Run one task and enter the main message loop.
+#if defined(OS_MACOSX)
if (pool)
pool->Recycle();
+#endif
parameters().ui_task->Run();
delete parameters().ui_task;
} else {
@@ -1919,10 +1921,13 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// Record now as the last successful chrome start.
GoogleUpdateSettings::SetLastRunTime();
+
+#if defined(OS_MACOSX)
// Call Recycle() here as late as possible, before going into the loop
// because Start() will add things to it while creating the main window.
if (pool)
pool->Recycle();
+#endif
RecordPreReadExperimentTime("Startup.BrowserOpenTabs",
base::TimeTicks::Now() - browser_open_start);
@@ -2084,7 +2089,7 @@ void ChromeBrowserMainParts::ToolkitInitialized() {
views::ViewsDelegate::views_delegate = new ChromeViewsDelegate;
// TODO(beng): Move to WidgetImpl and implement on Windows too!
- if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint))
+ if (parameters().command_line.HasSwitch(switches::kDebugViewsPaint))
views::Widget::SetDebugPaintEnabled(true);
#endif
diff --git a/chrome/browser/chrome_browser_main_unittest.cc b/chrome/browser/chrome_browser_main_unittest.cc
index 9bcd07f..e682c9c 100644
--- a/chrome/browser/chrome_browser_main_unittest.cc
+++ b/chrome/browser/chrome_browser_main_unittest.cc
@@ -12,7 +12,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_pref_service.h"
#include "content/common/main_function_params.h"
-#include "content/common/sandbox_init_wrapper.h"
#include "content/public/browser/content_browser_client.h"
#include "net/socket/client_socket_pool_base.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,12 +19,8 @@
class BrowserMainTest : public testing::Test {
public:
BrowserMainTest() : command_line_(CommandLine::NO_PROGRAM) {}
- protected:
- virtual void SetUp() {
- sandbox_init_wrapper_.reset(new SandboxInitWrapper());
- }
- scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_;
+ protected:
TestingPrefService pref_service_;
CommandLine command_line_;
};
@@ -33,8 +28,7 @@ class BrowserMainTest : public testing::Test {
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) {
command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "0");
- scoped_ptr<MainFunctionParams> params(
- new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
+ scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_));
ScopedVector<content::BrowserMainParts> bwv;
content::GetContentClient()->browser()->CreateBrowserMainParts(
*params, &(bwv.get()));
@@ -49,8 +43,7 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) {
}
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) {
- scoped_ptr<MainFunctionParams> params(
- new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
+ scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_));
ScopedVector<content::BrowserMainParts> bwv;
content::GetContentClient()->browser()->CreateBrowserMainParts(
*params, &(bwv.get()));
@@ -72,8 +65,7 @@ TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) {
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) {
command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "100");
- scoped_ptr<MainFunctionParams> params(
- new MainFunctionParams(command_line_, *sandbox_init_wrapper_, NULL));
+ scoped_ptr<MainFunctionParams> params(new MainFunctionParams(command_line_));
// This test ends up launching a new process, and that doesn't initialize the
// ContentClient interfaces.
ScopedVector<content::BrowserMainParts> bwv;
diff --git a/chrome/browser/ui/panels/base_panel_browser_test.cc b/chrome/browser/ui/panels/base_panel_browser_test.cc
index 8d41f37..99e26e0 100644
--- a/chrome/browser/ui/panels/base_panel_browser_test.cc
+++ b/chrome/browser/ui/panels/base_panel_browser_test.cc
@@ -7,7 +7,6 @@
#include "chrome/browser/ui/browser_list.h"
#include "base/command_line.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -22,6 +21,7 @@
#include "content/public/common/url_constants.h"
#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#endif
@@ -225,6 +225,7 @@ void BasePanelBrowserTest::WaitForBoundsAnimationFinished(Panel* panel) {
Panel* BasePanelBrowserTest::CreatePanelWithParams(
const CreatePanelParams& params) {
+#if defined(OS_MACOSX)
// Opening panels on a Mac causes NSWindowController of the Panel window
// to be autoreleased. We need a pool drained after it's done so the test
// can close correctly. The NSWindowController of the Panel window controls
@@ -232,6 +233,7 @@ Panel* BasePanelBrowserTest::CreatePanelWithParams(
// possible. In real Chrome, this is done by message pump.
// On non-Mac platform, this is an empty class.
base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
params.name,
diff --git a/chrome/browser/ui/panels/panel_app_browsertest.cc b/chrome/browser/ui/panels/panel_app_browsertest.cc
index 25e17c0..0f6fdde 100644
--- a/chrome/browser/ui/panels/panel_app_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_app_browsertest.cc
@@ -5,7 +5,6 @@
#include "base/command_line.h"
#include "base/file_path.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -19,6 +18,10 @@
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
class PanelAppBrowserTest : public ExtensionBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) {
@@ -26,6 +29,7 @@ class PanelAppBrowserTest : public ExtensionBrowserTest {
}
void LoadAndLaunchExtension(const char* name) {
+#if defined(OS_MACOSX)
// Opening panels on a Mac causes NSWindowController of the Panel window
// to be autoreleased. We need a pool drained after it's done so the test
// can close correctly. The NSWindowController of the Panel window controls
@@ -33,6 +37,7 @@ class PanelAppBrowserTest : public ExtensionBrowserTest {
// possible. In real Chrome, this is done by message pump.
// On non-Mac platform, this is an empty class.
base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII(name)));
diff --git a/chrome/chrome_exe.gypi b/chrome/chrome_exe.gypi
index e148e55..9fa9d59 100644
--- a/chrome/chrome_exe.gypi
+++ b/chrome/chrome_exe.gypi
@@ -512,8 +512,8 @@
'../content/app/startup_helper_win.cc',
'../content/common/debug_flags.cc', # Needed for sandbox_policy.cc
'../content/common/hi_res_timer_manager_win.cc',
+ '../content/common/sandbox_init_win.cc',
'../content/common/sandbox_policy.cc',
- '../content/common/sandbox_init_wrapper_win.cc',
'../content/public/common/content_switches.cc',
'<(SHARED_INTERMEDIATE_DIR)/chrome_version/nacl64_exe_version.rc',
],
diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc
index 3f21f24..768c618 100644
--- a/chrome/common/service_process_util.cc
+++ b/chrome/common/service_process_util.cc
@@ -7,7 +7,6 @@
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/singleton.h"
#include "base/path_service.h"
#include "base/process_util.h"
diff --git a/chrome/nacl/DEPS b/chrome/nacl/DEPS
index 93d77e9..9700f06 100644
--- a/chrome/nacl/DEPS
+++ b/chrome/nacl/DEPS
@@ -1,6 +1,6 @@
include_rules = [
"+chrome/app/breakpad_win.h",
- "+content/app/startup_helper_win.h",
+ "+content/public/app/startup_helper_win.h",
"+sandbox/src",
"+native_client/src",
]
diff --git a/chrome/nacl/nacl_exe_win_64.cc b/chrome/nacl/nacl_exe_win_64.cc
index 834fc37..c347c7b 100644
--- a/chrome/nacl/nacl_exe_win_64.cc
+++ b/chrome/nacl/nacl_exe_win_64.cc
@@ -16,12 +16,10 @@
#include "chrome/nacl/nacl_broker_listener.h"
#include "chrome/nacl/nacl_listener.h"
#include "chrome/nacl/nacl_main_platform_delegate.h"
-#include "content/app/startup_helper_win.h"
#include "content/common/hi_res_timer_manager.h"
#include "content/common/main_function_params.h"
-#include "content/common/sandbox_init_wrapper.h"
-#include "content/common/sandbox_policy.h"
-#include "sandbox/src/sandbox.h"
+#include "content/public/app/startup_helper_win.h"
+#include "content/public/common/sandbox_init.h"
#include "sandbox/src/sandbox_types.h"
extern int NaClMain(const MainFunctionParams&);
@@ -29,7 +27,7 @@ extern int NaClMain(const MainFunctionParams&);
// main() routine for the NaCl broker process.
// This is necessary for supporting NaCl in Chrome on Win64.
int NaClBrokerMain(const MainFunctionParams& parameters) {
- const CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line;
MessageLoopForIO main_message_loop;
base::PlatformThread::SetName("CrNaClBrokerMain");
@@ -37,26 +35,6 @@ int NaClBrokerMain(const MainFunctionParams& parameters) {
base::SystemMonitor system_monitor;
HighResolutionTimerManager hi_res_timer_manager;
- // NOTE: this code is duplicated from browser_main.cc
- // IMPORTANT: This piece of code needs to run as early as possible in the
- // process because it will initialize the sandbox broker, which requires the
- // process to swap its window station. During this time all the UI will be
- // broken. This has to run before threads and windows are created.
- sandbox::BrokerServices* broker_services =
- parameters.sandbox_info_.BrokerServices();
- if (broker_services) {
- sandbox::InitBrokerServices(broker_services);
- if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) {
- bool use_winsta = !parsed_command_line.HasSwitch(
- switches::kDisableAltWinstation);
- // Precreate the desktop and window station used by the renderers.
- sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
- sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
- CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
- policy->Release();
- }
- }
-
NaClBrokerListener listener;
listener.Listen();
@@ -85,14 +63,12 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
content::SetupCRT(command_line);
// Initialize the sandbox for this process.
- SandboxInitWrapper sandbox_wrapper;
- sandbox_wrapper.SetServices(&sandbox_info);
- bool sandbox_initialized_ok =
- sandbox_wrapper.InitializeSandbox(command_line, process_type);
+ bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info);
// Die if the sandbox can't be enabled.
CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
<< process_type;
- MainFunctionParams main_params(command_line, sandbox_wrapper, NULL);
+ MainFunctionParams main_params(command_line);
+ main_params.sandbox_info = &sandbox_info;
if (process_type == switches::kNaClLoaderProcess)
return NaClMain(main_params);
diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc
index 4b3caae..87e37eb 100644
--- a/chrome/nacl/nacl_main.cc
+++ b/chrome/nacl/nacl_main.cc
@@ -30,7 +30,7 @@ static void HandleNaClTestParameters(const CommandLine& command_line) {
// main() routine for the NaCl loader process.
int NaClMain(const MainFunctionParams& parameters) {
- const CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line;
// This function allows pausing execution using the --nacl-startup-dialog
// flag allowing us to attach a debugger.
diff --git a/chrome/nacl/nacl_main_platform_delegate_mac.mm b/chrome/nacl/nacl_main_platform_delegate_mac.mm
index 006ee25..c5eb65a 100644
--- a/chrome/nacl/nacl_main_platform_delegate_mac.mm
+++ b/chrome/nacl/nacl_main_platform_delegate_mac.mm
@@ -11,6 +11,7 @@
#include "base/native_library.h"
#include "chrome/common/chrome_switches.h"
#include "content/common/sandbox_mac.h"
+#include "content/public/common/sandbox_init.h"
NaClMainPlatformDelegate::NaClMainPlatformDelegate(
const MainFunctionParams& parameters)
@@ -32,7 +33,7 @@ void NaClMainPlatformDelegate::PlatformUninitialize() {
}
void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
- const CommandLine& command_line = parameters_.command_line_;
+ const CommandLine& command_line = parameters_.command_line;
DVLOG(1) << "Started NaClLdr with ";
const std::vector<std::string>& argstrings = command_line.argv();
@@ -54,13 +55,8 @@ void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
}
void NaClMainPlatformDelegate::EnableSandbox() {
- CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
- SandboxInitWrapper sandbox_wrapper;
- bool sandbox_initialized_ok =
- sandbox_wrapper.InitializeSandbox(*parsed_command_line,
- switches::kNaClLoaderProcess);
- CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
- << switches::kNaClLoaderProcess;
+ CHECK(content::InitializeSandbox()) << "Error initializing sandbox for "
+ << switches::kNaClLoaderProcess;
}
bool NaClMainPlatformDelegate::RunSandboxTests() {
diff --git a/chrome/nacl/nacl_main_platform_delegate_win.cc b/chrome/nacl/nacl_main_platform_delegate_win.cc
index 97ba3af..1ce923e 100644
--- a/chrome/nacl/nacl_main_platform_delegate_win.cc
+++ b/chrome/nacl/nacl_main_platform_delegate_win.cc
@@ -28,12 +28,12 @@ void NaClMainPlatformDelegate::PlatformUninitialize() {
}
void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
- const CommandLine& command_line = parameters_.command_line_;
+ const CommandLine& command_line = parameters_.command_line;
DVLOG(1) << "Started NaClLdr with " << command_line.GetCommandLineString();
sandbox::TargetServices* target_services =
- parameters_.sandbox_info_.TargetServices();
+ parameters_.sandbox_info->target_services;
if (target_services && !no_sandbox) {
FilePath test_dll_name =
@@ -59,7 +59,7 @@ void NaClMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
void NaClMainPlatformDelegate::EnableSandbox() {
sandbox::TargetServices* target_services =
- parameters_.sandbox_info_.TargetServices();
+ parameters_.sandbox_info->target_services;
CHECK(target_services) << "NaCl-Win EnableSandbox: No Target Services!";
// Cause advapi32 to load before the sandbox is turned on.
diff --git a/chrome/service/DEPS b/chrome/service/DEPS
index be16d49..3f31d56 100644
--- a/chrome/service/DEPS
+++ b/chrome/service/DEPS
@@ -1,4 +1,5 @@
include_rules = [
# For generated headers.
"+grit",
+ "+sandbox/src/sandbox_types.h",
]
diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc
index bd5e66f..14f1362 100644
--- a/chrome/service/service_main.cc
+++ b/chrome/service/service_main.cc
@@ -11,6 +11,7 @@
#if defined(OS_WIN)
#include "content/common/sandbox_policy.h"
+#include "sandbox/src/sandbox_types.h"
#elif defined(OS_MACOSX)
#include "chrome/service/chrome_service_application_mac.h"
#endif // defined(OS_WIN)
@@ -19,12 +20,12 @@
int ServiceProcessMain(const MainFunctionParams& parameters) {
MessageLoopForUI main_message_loop;
main_message_loop.set_thread_name("MainThread");
- if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) {
+ if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) {
base::debug::WaitForDebugger(60, true);
}
VLOG(1) << "Service process launched: "
- << parameters.command_line_.GetCommandLineString();
+ << parameters.command_line.GetCommandLineString();
#if defined(OS_MACOSX)
chrome_service_application_mac::RegisterServiceCrApp();
@@ -39,14 +40,14 @@ int ServiceProcessMain(const MainFunctionParams& parameters) {
#if defined(OS_WIN)
sandbox::BrokerServices* broker_services =
- parameters.sandbox_info_.BrokerServices();
+ parameters.sandbox_info->broker_services;
if (broker_services)
sandbox::InitBrokerServices(broker_services);
#endif // defined(OS_WIN)
ServiceProcess service_process;
if (service_process.Initialize(&main_message_loop,
- parameters.command_line_,
+ parameters.command_line,
state.release())) {
MessageLoop::current()->Run();
} else {
diff --git a/chrome/test/base/chrome_test_launcher.cc b/chrome/test/base/chrome_test_launcher.cc
index 3209f7d..8e6fab4 100644
--- a/chrome/test/base/chrome_test_launcher.cc
+++ b/chrome/test/base/chrome_test_launcher.cc
@@ -18,7 +18,7 @@
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
-#include "content/app/startup_helper_win.h"
+#include "content/public/app/startup_helper_win.h"
#include "sandbox/src/sandbox_types.h"
#endif // defined(OS_WIN)
diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc
index 6bba2b2..fd4e26d 100644
--- a/chrome/test/base/chrome_test_suite.cc
+++ b/chrome/test/base/chrome_test_suite.cc
@@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/file_util.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/stats_table.h"
#include "base/path_service.h"
@@ -31,6 +30,7 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "content/common/chrome_application_mac.h"
#endif
@@ -159,9 +159,8 @@ ChromeTestSuite::~ChromeTestSuite() {
void ChromeTestSuite::Initialize() {
#if defined(OS_MACOSX)
chrome_application_mac::RegisterCrApp();
-#endif
-
base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
base::TestSuite::Initialize();
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 92df821..e9a0909 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -8,7 +8,6 @@
#include "base/debug/stack_trace.h"
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/path_service.h"
#include "base/string_number_conversions.h"
#include "base/test/test_file_util.h"
@@ -40,6 +39,8 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/audio_handler.h"
+#elif defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
#endif
// Passed as value of kTestType.
@@ -255,6 +256,7 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
signal(SIGTERM, DumpStackTraceSignalHandler);
#endif // defined(OS_POSIX)
+#if defined(OS_MACOSX)
// On Mac, without the following autorelease pool, code which is directly
// executed (as opposed to executed inside a message loop) would autorelease
// objects into a higher-level pool. This pool is not recycled in-sync with
@@ -263,29 +265,42 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
// browser shutdown). To avoid this, the following pool is recycled after each
// time code is directly executed.
base::mac::ScopedNSAutoreleasePool pool;
+#endif
// Pump startup related events.
MessageLoopForUI::current()->RunAllPending();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
browser_ = CreateBrowser(ProfileManager::GetDefaultProfile());
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
// Pump any pending events that were created as a result of creating a
// browser.
MessageLoopForUI::current()->RunAllPending();
SetUpOnMainThread();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
RunTestOnMainThread();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
CleanUpOnMainThread();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
QuitBrowsers();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
}
void InProcessBrowserTest::QuitBrowsers() {
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index c178995..ed90fc1 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -26,7 +26,9 @@ PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv)
}
PyUITestSuiteBase::~PyUITestSuiteBase() {
+#if defined(OS_MACOSX)
pool_.Recycle();
+#endif
Shutdown();
}
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 4b0958e..72c3fbe 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -10,11 +10,14 @@
#pragma once
#include "base/message_loop.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/test/test_timeouts.h"
#include "chrome/test/ui/ui_test.h"
#include "chrome/test/ui/ui_test_suite.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
// The C++ style guide forbids using default arguments but I'm taking the
// liberty of allowing it in this file. The sole purpose of this (and the
// .cc) is to support the python interface, and default args are allowed in
@@ -33,7 +36,9 @@ class PyUITestSuiteBase : public UITestSuite {
void SetCrSourceRoot(const FilePath& path);
private:
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool pool_;
+#endif
};
// The primary class that interfaces with Automation Proxy.
diff --git a/chrome/test/webdriver/commands/command.h b/chrome/test/webdriver/commands/command.h
index 8f735f8..dc4177f 100644
--- a/chrome/test/webdriver/commands/command.h
+++ b/chrome/test/webdriver/commands/command.h
@@ -11,7 +11,11 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
+#include "build/build_config.h"
+
+#if defined(OS_MACOX)
#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
namespace webdriver {
@@ -101,12 +105,14 @@ class Command {
const std::vector<std::string> path_segments_;
const scoped_ptr<const DictionaryValue> parameters_;
+#if defined(OS_MACOX)
// An autorelease pool must exist on any thread where Objective C is used,
// even implicitly. Otherwise the warning:
// "Objects autoreleased with no pool in place."
// is printed for every object deallocted. Since every incomming command to
// chrome driver is allocated a new thread, the release pool is declared here.
base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
DISALLOW_COPY_AND_ASSIGN(Command);
};
diff --git a/content/app/content_main.cc b/content/app/content_main.cc
index 2494dc4..3cbf07f 100644
--- a/content/app/content_main.cc
+++ b/content/app/content_main.cc
@@ -9,22 +9,21 @@
#include "base/debug/debugger.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/stats_table.h"
#include "base/process_util.h"
#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
-#include "content/app/startup_helper_win.h"
#include "content/browser/browser_main.h"
#include "content/common/main_function_params.h"
-#include "content/common/sandbox_init_wrapper.h"
#include "content/common/set_process_title.h"
#include "content/public/app/content_main_delegate.h"
+#include "content/public/app/startup_helper_win.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/sandbox_init.h"
#include "crypto/nss_util.h"
#include "ipc/ipc_switches.h"
#include "ui/base/ui_base_switches.h"
@@ -36,6 +35,7 @@
#include <atlapp.h>
#include <malloc.h>
#elif defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/mach_ipc_mac.h"
#include "base/system_monitor/system_monitor.h"
#include "content/browser/mach_broker_mac.h"
@@ -219,9 +219,8 @@ int RunZygote(const MainFunctionParams& main_function_params,
base::GetParentProcessId(base::GetCurrentProcId()));
InitializeStatsTable(browser_pid, command_line);
- MainFunctionParams main_params(command_line,
- main_function_params.sandbox_info_,
- main_function_params.autorelease_pool_);
+ MainFunctionParams main_params(command_line);
+
// Get the new process type from the new command line.
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
@@ -327,11 +326,13 @@ int ContentMain(int argc,
// The exit manager is in charge of calling the dtors of singleton objects.
base::AtExitManager exit_manager;
+#if defined(OS_MACOSX)
// We need this pool for all the objects created before we get to the
// event loop, but we don't want to leave them hanging around until the
// app quits. Each "main" needs to flush this pool right before it goes into
// its main event loop to get rid of the cruft.
base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
CommandLine::Init(argc, argv);
@@ -415,38 +416,31 @@ int ContentMain(int argc,
if (!process_type.empty())
CommonSubprocessInit(process_type);
- // Initialize the sandbox for this process.
- SandboxInitWrapper sandbox_wrapper;
- bool initialize_sandbox = true;
-
#if defined(OS_WIN)
- sandbox_wrapper.SetServices(sandbox_info);
+ CHECK(content::InitializeSandbox(sandbox_info));
#elif defined(OS_MACOSX)
- // On OS X the renderer sandbox needs to be initialized later in the startup
- // sequence in RendererMainPlatformDelegate::EnableSandbox().
if (process_type == switches::kRendererProcess ||
process_type == switches::kPpapiPluginProcess ||
(delegate && delegate->DelaySandboxInitialization(process_type))) {
- initialize_sandbox = false;
+ // On OS X the renderer sandbox needs to be initialized later in the startup
+ // sequence in RendererMainPlatformDelegate::EnableSandbox().
+ } else {
+ CHECK(content::InitializeSandbox());
}
#endif
- if (initialize_sandbox) {
- bool sandbox_initialized_ok =
- sandbox_wrapper.InitializeSandbox(command_line, process_type);
- // Die if the sandbox can't be enabled.
- CHECK(sandbox_initialized_ok) << "Error initializing sandbox for "
- << process_type;
- }
-
if (delegate) delegate->SandboxInitialized(process_type);
#if defined(OS_POSIX)
SetProcessTitleFromCommandLine(argv);
#endif
- MainFunctionParams main_params(command_line, sandbox_wrapper,
- &autorelease_pool);
+ MainFunctionParams main_params(command_line);
+#if defined(OS_WIN)
+ main_params.sandbox_info = sandbox_info;
+#elif defined(OS_MACOSX)
+ main_params.autorelease_pool = &autorelease_pool;
+#endif
exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate);
diff --git a/content/app/startup_helper_win.cc b/content/app/startup_helper_win.cc
index 8e1a32b..aaba83c 100644
--- a/content/app/startup_helper_win.cc
+++ b/content/app/startup_helper_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/app/startup_helper_win.h"
+#include "content/public/app/startup_helper_win.h"
#include <crtdbg.h>
#include <new.h>
diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc
index 3609290..c358f49 100644
--- a/content/browser/browser_main.cc
+++ b/content/browser/browser_main.cc
@@ -16,33 +16,10 @@
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
-#include "content/common/sandbox_policy.h"
-#include "sandbox/src/sandbox.h"
#endif
namespace {
-#if defined(OS_WIN)
-// Windows-specific initialization code for the sandbox broker services.
-void InitializeBrokerServices(const MainFunctionParams& parameters,
- const CommandLine& parsed_command_line) {
- sandbox::BrokerServices* broker_services =
- parameters.sandbox_info_.BrokerServices();
- if (broker_services) {
- sandbox::InitBrokerServices(broker_services);
- if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) {
- bool use_winsta = !parsed_command_line.HasSwitch(
- switches::kDisableAltWinstation);
- // Precreate the desktop and window station used by the renderers.
- sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
- sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
- CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
- policy->Release();
- }
- }
-}
-#endif
-
bool g_exited_main_message_loop = false;
} // namespace
@@ -106,11 +83,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Make this call before going multithreaded, or spawning any subprocesses.
base::allocator::SetupSubprocessAllocator();
#endif
- // The broker service initialization needs to run early because it will
- // initialize the sandbox broker, which requires the process to swap its
- // window station. During this time all the UI will be broken. This has to
- // run before threads and windows are created.
- InitializeBrokerServices(parameters, parameters.command_line_);
base::win::ScopedCOMInitializer com_initializer;
#endif // OS_WIN
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index f9b1102..ff12449 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -149,7 +149,7 @@ namespace content {
BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters)
: parameters_(parameters),
- parsed_command_line_(parameters.command_line_),
+ parsed_command_line_(parameters.command_line),
result_code_(content::RESULT_CODE_NORMAL_EXIT) {
#if defined(OS_WIN)
OleInitialize(NULL);
@@ -332,7 +332,7 @@ void BrowserMainLoop::InitializeToolkit() {
#endif
#if !defined(USE_AURA)
- gfx::GtkInitFromCommandLine(parameters_.command_line_);
+ gfx::GtkInitFromCommandLine(parameters_.command_line);
#endif
SetUpGLibLogHandler();
diff --git a/content/common/main_function_params.h b/content/common/main_function_params.h
index 1c53c5f..1b6323f 100644
--- a/content/common/main_function_params.h
+++ b/content/common/main_function_params.h
@@ -11,24 +11,36 @@
#pragma once
#include "base/command_line.h"
-#include "content/common/sandbox_init_wrapper.h"
+#if defined(OS_WIN)
+namespace sandbox {
+struct SandboxInterfaceInfo;
+}
+#elif defined(OS_MACOSX)
namespace base {
namespace mac {
class ScopedNSAutoreleasePool;
}
}
+#endif
class Task;
struct MainFunctionParams {
- MainFunctionParams(const CommandLine& cl, const SandboxInitWrapper& sb,
- base::mac::ScopedNSAutoreleasePool* pool)
- : command_line_(cl), sandbox_info_(sb), autorelease_pool_(pool),
- ui_task(NULL) { }
- const CommandLine& command_line_;
- const SandboxInitWrapper& sandbox_info_;
- base::mac::ScopedNSAutoreleasePool* autorelease_pool_;
+ explicit MainFunctionParams(const CommandLine& cl)
+ : command_line(cl),
+#if defined(OS_WIN)
+ sandbox_info(NULL),
+#elif defined(OS_MACOSX)
+ autorelease_pool(NULL),
+#endif
+ ui_task(NULL) {}
+ const CommandLine& command_line;
+#if defined(OS_WIN)
+ sandbox::SandboxInterfaceInfo* sandbox_info;
+#elif defined(OS_MACOSX)
+ base::mac::ScopedNSAutoreleasePool* autorelease_pool;
+#endif
// Used by InProcessBrowserTest. If non-null BrowserMain schedules this
// task to run on the MessageLoop and BrowserInit is not invoked.
Task* ui_task;
diff --git a/content/common/sandbox_init_wrapper_mac.cc b/content/common/sandbox_init_mac.cc
index 7054a6e8..e39667b 100644
--- a/content/common/sandbox_init_wrapper_mac.cc
+++ b/content/common/sandbox_init_mac.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/common/sandbox_init_wrapper.h"
+#include "content/public/common/sandbox_init.h"
#include "base/command_line.h"
#include "base/file_path.h"
@@ -10,16 +10,20 @@
#include "content/common/sandbox_mac.h"
#include "content/public/common/content_switches.h"
-bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
- const std::string& process_type) {
+namespace content {
+
+bool InitializeSandbox() {
using sandbox::Sandbox;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kNoSandbox))
return true;
Sandbox::SandboxProcessType sandbox_process_type;
FilePath allowed_dir; // Empty by default.
+ std::string process_type =
+ command_line.GetSwitchValueASCII(switches::kProcessType);
if (process_type.empty()) {
// Browser process isn't sandboxed.
return true;
@@ -65,3 +69,5 @@ bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
// Actually sandbox the process.
return Sandbox::EnableSandbox(sandbox_process_type, allowed_dir);
}
+
+} // namespace content
diff --git a/content/common/sandbox_init_win.cc b/content/common/sandbox_init_win.cc
new file mode 100644
index 0000000..3a58ca2
--- /dev/null
+++ b/content/common/sandbox_init_win.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/common/sandbox_init.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "content/common/sandbox_policy.h"
+#include "content/public/common/content_switches.h"
+#include "sandbox/src/sandbox.h"
+#include "sandbox/src/sandbox_types.h"
+
+namespace content {
+
+bool InitializeSandbox(
+ sandbox::SandboxInterfaceInfo* sandbox_info) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ std::string process_type =
+ command_line.GetSwitchValueASCII(switches::kProcessType);
+ if (process_type.empty() || process_type == switches::kNaClBrokerProcess) {
+ // IMPORTANT: This piece of code needs to run as early as possible in the
+ // process because it will initialize the sandbox broker, which requires the
+ // process to swap its window station. During this time all the UI will be
+ // broken. This has to run before threads and windows are created.
+ sandbox::BrokerServices* broker_services = sandbox_info->broker_services;
+ if (broker_services) {
+ sandbox::InitBrokerServices(broker_services);
+ if (!command_line.HasSwitch(switches::kNoSandbox)) {
+ bool use_winsta = !command_line.HasSwitch(
+ switches::kDisableAltWinstation);
+ // Precreate the desktop and window station used by the renderers.
+ sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
+ sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
+ CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
+ policy->Release();
+ }
+ }
+ return true;
+ }
+
+ if (command_line.HasSwitch(switches::kNoSandbox))
+ return true;
+
+ sandbox::TargetServices* target_services = sandbox_info->target_services;
+ if ((process_type == switches::kRendererProcess) ||
+ (process_type == switches::kWorkerProcess) ||
+ (process_type == switches::kNaClLoaderProcess) ||
+ (process_type == switches::kUtilityProcess)) {
+ // The above five process types must be sandboxed unless --no-sandbox
+ // is present in the command line.
+ if (!target_services)
+ return false;
+ } else {
+ // Other process types might or might not be sandboxed.
+ // TODO(cpu): clean this mess.
+ if (!target_services)
+ return true;
+ }
+ return (sandbox::SBOX_ALL_OK == target_services->Init());
+}
+
+} // namespace content
diff --git a/content/common/sandbox_init_wrapper.h b/content/common/sandbox_init_wrapper.h
deleted file mode 100644
index fcc096a..0000000
--- a/content/common/sandbox_init_wrapper.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_COMMON_SANDBOX_INIT_WRAPPER_H_
-#define CONTENT_COMMON_SANDBOX_INIT_WRAPPER_H_
-#pragma once
-
-// Wraps the sandbox initialization and platform variables to consolodate
-// the code and reduce the number of platform ifdefs elsewhere. The POSIX
-// version of this wrapper is basically empty.
-
-#include "build/build_config.h"
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "content/common/content_export.h"
-
-#if defined(OS_WIN)
-#include "sandbox/src/sandbox.h"
-#endif
-
-class CommandLine;
-
-#if defined(OS_WIN)
-
-class CONTENT_EXPORT SandboxInitWrapper {
- public:
- SandboxInitWrapper() : broker_services_(), target_services_() { }
- // SetServices() needs to be called before InitializeSandbox() on Win32 with
- // the info received from the chrome exe main.
- void SetServices(sandbox::SandboxInterfaceInfo* sandbox_info);
- sandbox::BrokerServices* BrokerServices() const { return broker_services_; }
- sandbox::TargetServices* TargetServices() const { return target_services_; }
-
- // Initialize the sandbox for renderer, gpu, utility, worker, nacl, and
- // plug-in processes, depending on the command line flags. The browser
- // process is not sandboxed.
- // Returns true if the sandbox was initialized succesfully, false if an error
- // occurred. If process_type isn't one that needs sandboxing true is always
- // returned.
- bool InitializeSandbox(const CommandLine& parsed_command_line,
- const std::string& process_type);
- private:
- sandbox::BrokerServices* broker_services_;
- sandbox::TargetServices* target_services_;
-
- DISALLOW_COPY_AND_ASSIGN(SandboxInitWrapper);
-};
-
-#elif defined(OS_POSIX)
-
-class SandboxInitWrapper {
- public:
- SandboxInitWrapper() { }
-
- // Initialize the sandbox for renderer and plug-in processes, depending on
- // the command line flags. The browser process is not sandboxed.
- // Returns true if the sandbox was initialized succesfully, false if an error
- // occurred. If process_type isn't one that needs sandboxing true is always
- // returned.
- bool InitializeSandbox(const CommandLine& parsed_command_line,
- const std::string& process_type);
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SandboxInitWrapper);
-};
-
-#endif
-
-#endif // CONTENT_COMMON_SANDBOX_INIT_WRAPPER_H_
diff --git a/content/common/sandbox_init_wrapper_linux.cc b/content/common/sandbox_init_wrapper_linux.cc
deleted file mode 100644
index 450bd2d..0000000
--- a/content/common/sandbox_init_wrapper_linux.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/common/sandbox_init_wrapper.h"
-
-#include "base/command_line.h"
-
-bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
- const std::string& process_type) {
- // TODO(port): Does Linux need to do anything here?
- return true;
-}
diff --git a/content/common/sandbox_init_wrapper_win.cc b/content/common/sandbox_init_wrapper_win.cc
deleted file mode 100644
index e430c8c..0000000
--- a/content/common/sandbox_init_wrapper_win.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/common/sandbox_init_wrapper.h"
-
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "content/public/common/content_switches.h"
-
-void SandboxInitWrapper::SetServices(sandbox::SandboxInterfaceInfo* info) {
- if (!info)
- return;
- if (info->legacy) {
- // Looks like we are in the case when the new chrome.dll is being launched
- // by the old chrome.exe, the old chrome exe has SandboxInterfaceInfo as a
- // union, while now we have a struct.
- // TODO(cpu): Remove this nasty hack after M10 release.
- broker_services_ = reinterpret_cast<sandbox::BrokerServices*>(info->legacy);
- target_services_ = reinterpret_cast<sandbox::TargetServices*>(info->legacy);
- } else {
- // Normal case, both the exe and the dll are the same version. Both
- // interface pointers cannot be non-zero. A process can either be a target
- // or a broker but not both.
- broker_services_ = info->broker_services;
- target_services_ = info->target_services;
- DCHECK(!(target_services_ && broker_services_));
- }
-}
-
-bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
- const std::string& process_type) {
- if (command_line.HasSwitch(switches::kNoSandbox))
- return true;
- if ((process_type == switches::kRendererProcess) ||
- (process_type == switches::kWorkerProcess) ||
- (process_type == switches::kNaClLoaderProcess) ||
- (process_type == switches::kUtilityProcess)) {
- // The above five process types must be sandboxed unless --no-sandbox
- // is present in the command line.
- if (!target_services_)
- return false;
- } else {
- // Other process types might or might not be sandboxed.
- // TODO(cpu): clean this mess.
- if (!target_services_)
- return true;
- }
- return (sandbox::SBOX_ALL_OK == target_services_->Init());
-}
diff --git a/content/content_app.gypi b/content/content_app.gypi
index 545080f..baa5207 100644
--- a/content/content_app.gypi
+++ b/content/content_app.gypi
@@ -16,8 +16,8 @@
'app/content_main.cc',
'app/content_main.h',
'app/startup_helper_win.cc',
- 'app/startup_helper_win.h',
'public/app/content_main_delegate.h',
+ 'public/app/startup_helper_win.h',
],
'conditions': [
['OS=="win"', {
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 1a276bb..505846d 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -47,6 +47,7 @@
'public/common/pepper_plugin_info.h',
'public/common/resource_dispatcher_delegate.h',
'public/common/result_codes.h',
+ 'public/common/sandbox_init.h',
'public/common/security_style.h',
'public/common/serialized_script_value.cc',
'public/common/serialized_script_value.h',
@@ -206,10 +207,8 @@
'common/resource_messages.h',
'common/resource_response.cc',
'common/resource_response.h',
- 'common/sandbox_init_wrapper.h',
- 'common/sandbox_init_wrapper_linux.cc',
- 'common/sandbox_init_wrapper_mac.cc',
- 'common/sandbox_init_wrapper_win.cc',
+ 'common/sandbox_init_mac.cc',
+ 'common/sandbox_init_win.cc',
'common/sandbox_mac.h',
'common/sandbox_mac.mm',
'common/sandbox_methods_linux.h',
diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index e3217109..a4bb494 100644
--- a/content/gpu/gpu_main.cc
+++ b/content/gpu/gpu_main.cc
@@ -36,7 +36,7 @@
int GpuMain(const MainFunctionParams& parameters) {
base::Time start_time = base::Time::Now();
- const CommandLine& command_line = parameters.command_line_;
+ const CommandLine& command_line = parameters.command_line;
if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
ChildProcess::WaitForDebugger("Gpu");
}
@@ -77,7 +77,7 @@ int GpuMain(const MainFunctionParams& parameters) {
#if defined(OS_WIN)
sandbox::TargetServices* target_services =
- parameters.sandbox_info_.TargetServices();
+ parameters.sandbox_info->target_services;
// For windows, if the target_services interface is not zero, the process
// is sandboxed and we must call LowerToken() before rendering untrusted
// content.
diff --git a/content/plugin/plugin_main.cc b/content/plugin/plugin_main.cc
index 1f927459..8a5d0ff 100644
--- a/content/plugin/plugin_main.cc
+++ b/content/plugin/plugin_main.cc
@@ -89,7 +89,7 @@ int PluginMain(const MainFunctionParams& parameters) {
base::SystemMonitor system_monitor;
HighResolutionTimerManager high_resolution_timer_manager;
- const CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line;
#if defined(OS_LINUX)
@@ -99,7 +99,7 @@ int PluginMain(const MainFunctionParams& parameters) {
#elif defined(OS_WIN)
sandbox::TargetServices* target_services =
- parameters.sandbox_info_.TargetServices();
+ parameters.sandbox_info->target_services;
CoInitialize(NULL);
DVLOG(1) << "Started plugin with "
diff --git a/content/ppapi_plugin/ppapi_broker_main.cc b/content/ppapi_plugin/ppapi_broker_main.cc
index 8789a61..f2a546e 100644
--- a/content/ppapi_plugin/ppapi_broker_main.cc
+++ b/content/ppapi_plugin/ppapi_broker_main.cc
@@ -12,7 +12,7 @@
// Main function for starting the PPAPI broker process.
int PpapiBrokerMain(const MainFunctionParams& parameters) {
- const CommandLine& command_line = parameters.command_line_;
+ const CommandLine& command_line = parameters.command_line;
if (command_line.HasSwitch(switches::kPpapiStartupDialog)) {
ChildProcess::WaitForDebugger("PpapiBroker");
}
diff --git a/content/ppapi_plugin/ppapi_plugin_main.cc b/content/ppapi_plugin/ppapi_plugin_main.cc
index f732c12..11d771d 100644
--- a/content/ppapi_plugin/ppapi_plugin_main.cc
+++ b/content/ppapi_plugin/ppapi_plugin_main.cc
@@ -29,10 +29,10 @@ void* g_target_services = 0;
// Main function for starting the PPAPI plugin process.
int PpapiPluginMain(const MainFunctionParams& parameters) {
- const CommandLine& command_line = parameters.command_line_;
+ const CommandLine& command_line = parameters.command_line;
#if defined(OS_WIN)
- g_target_services = parameters.sandbox_info_.TargetServices();
+ g_target_services = parameters.sandbox_info->target_services;
#endif
// If |g_target_services| is not null this process is sandboxed. One side
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index d0e9b6c..1bb38b1 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -11,11 +11,11 @@
#include "base/rand_util.h"
#include "base/stringprintf.h"
#include "content/common/child_process.h"
-#include "content/common/sandbox_init_wrapper.h"
#include "content/ppapi_plugin/broker_process_dispatcher.h"
#include "content/ppapi_plugin/plugin_process_dispatcher.h"
#include "content/ppapi_plugin/ppapi_webkit_thread.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/sandbox_init.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h"
#include "ppapi/c/dev/ppp_network_state_dev.h"
@@ -201,11 +201,9 @@ void PpapiThread::OnMsgLoadPlugin(const FilePath& path) {
// We need to do this after getting |PPP_GetInterface()| (or presumably
// doing something nontrivial with the library), else the sandbox
// intercedes.
- CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
- SandboxInitWrapper sandbox_wrapper;
- if (!sandbox_wrapper.InitializeSandbox(*parsed_command_line,
- switches::kPpapiPluginProcess))
+ if (!content::InitializeSandbox()) {
LOG(WARNING) << "Failed to initialize sandbox";
+ }
#endif
// Get the InitializeModule function (required).
diff --git a/content/app/startup_helper_win.h b/content/public/app/startup_helper_win.h
index e20b638..2ed5e3f 100644
--- a/content/app/startup_helper_win.h
+++ b/content/public/app/startup_helper_win.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_APP_STARTUP_HELPER_WIN_H_
-#define CONTENT_APP_STARTUP_HELPER_WIN_H_
+#ifndef CONTENT_PUBLIC_APP_STARTUP_HELPER_WIN_H_
+#define CONTENT_PUBLIC_APP_STARTUP_HELPER_WIN_H_
#pragma once
class CommandLine;
@@ -31,4 +31,4 @@ void SetupCRT(const CommandLine& command_line);
} // namespace content
-#endif // CONTENT_APP_STARTUP_HELPER_WIN_H_
+#endif // CONTENT_PUBLIC_APP_STARTUP_HELPER_WIN_H_
diff --git a/content/public/common/sandbox_init.h b/content/public/common/sandbox_init.h
new file mode 100644
index 0000000..3415e0d
--- /dev/null
+++ b/content/public/common/sandbox_init.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
+#define CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
+#pragma once
+
+#include "build/build_config.h"
+#include "content/common/content_export.h"
+
+#if defined(OS_WIN)
+namespace sandbox {
+struct SandboxInterfaceInfo;
+}
+#endif
+
+namespace content {
+
+// Initialize the sandbox for renderer, gpu, utility, worker, nacl, and plug-in
+// processes, depending on the command line flags. Although The browser process
+// is not sandboxed, this also needs to be called because it will initialize
+// the broker code.
+// Returns true if the sandbox was initialized succesfully, false if an error
+// occurred. If process_type isn't one that needs sandboxing true is always
+// returned.
+#if defined(OS_WIN)
+CONTENT_EXPORT bool InitializeSandbox(
+ sandbox::SandboxInterfaceInfo* sandbox_info);
+#elif defined(OS_MACOSX)
+CONTENT_EXPORT bool InitializeSandbox();
+#endif
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
diff --git a/content/renderer/renderer_main.cc b/content/renderer/renderer_main.cc
index b5147c5..8d21de0 100644
--- a/content/renderer/renderer_main.cc
+++ b/content/renderer/renderer_main.cc
@@ -5,7 +5,6 @@
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/i18n/rtl.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/message_loop.h"
@@ -33,6 +32,7 @@
#include <unistd.h>
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "third_party/mach_override/mach_override.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#endif // OS_MACOSX
@@ -124,10 +124,10 @@ class RendererMessageLoopObserver : public MessageLoop::TaskObserver {
int RendererMain(const MainFunctionParams& parameters) {
TRACE_EVENT_BEGIN_ETW("RendererMain", 0, "");
- const CommandLine& parsed_command_line = parameters.command_line_;
- base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
+ const CommandLine& parsed_command_line = parameters.command_line;
#if defined(OS_MACOSX)
+ base::mac::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool;
InstallFrameworkHacks();
#endif // OS_MACOSX
@@ -222,8 +222,10 @@ int RendererMain(const MainFunctionParams& parameters) {
startup_timer.Stop(); // End of Startup Time Measurement.
if (run_loop) {
+#if defined(OS_MACOSX)
if (pool)
pool->Recycle();
+#endif
TRACE_EVENT_BEGIN_ETW("RendererMain.START_MSG_LOOP", 0, 0);
MessageLoop::current()->Run();
TRACE_EVENT_END_ETW("RendererMain.START_MSG_LOOP", 0, 0);
diff --git a/content/renderer/renderer_main_platform_delegate.h b/content/renderer/renderer_main_platform_delegate.h
index 630f2f1..b98eb0a 100644
--- a/content/renderer/renderer_main_platform_delegate.h
+++ b/content/renderer/renderer_main_platform_delegate.h
@@ -6,6 +6,13 @@
#define CHROME_RENDERER_RENDERER_MAIN_PLATFORM_DELEGATE_H_
#pragma once
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
+#include "base/basictypes.h"
#include "content/common/content_export.h"
#include "content/common/main_function_params.h"
diff --git a/content/renderer/renderer_main_platform_delegate_mac.mm b/content/renderer/renderer_main_platform_delegate_mac.mm
index ab17d012..c430733 100644
--- a/content/renderer/renderer_main_platform_delegate_mac.mm
+++ b/content/renderer/renderer_main_platform_delegate_mac.mm
@@ -14,6 +14,7 @@
#import "content/common/chrome_application_mac.h"
#include "content/common/sandbox_mac.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/sandbox_init.h"
#include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
RendererMainPlatformDelegate::RendererMainPlatformDelegate(
@@ -54,7 +55,7 @@ static void LogTestMessage(std::string message, bool is_error) {
}
bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
- const CommandLine& command_line = parameters_.command_line_;
+ const CommandLine& command_line = parameters_.command_line;
if (command_line.HasSwitch(switches::kTestSandbox)) {
std::string bundle_path =
@@ -76,10 +77,7 @@ bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
}
bool RendererMainPlatformDelegate::EnableSandbox() {
- CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
- SandboxInitWrapper sandbox_wrapper;
- return sandbox_wrapper.InitializeSandbox(*parsed_command_line,
- switches::kRendererProcess);
+ return content::InitializeSandbox();
}
void RendererMainPlatformDelegate::RunSandboxTests() {
diff --git a/content/renderer/renderer_main_platform_delegate_win.cc b/content/renderer/renderer_main_platform_delegate_win.cc
index e3b97e0..c917f0d 100644
--- a/content/renderer/renderer_main_platform_delegate_win.cc
+++ b/content/renderer/renderer_main_platform_delegate_win.cc
@@ -73,7 +73,7 @@ RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
void RendererMainPlatformDelegate::PlatformInitialize() {
// Be mindful of what resources you acquire here. They can be used by
// malicious code if the renderer gets compromised.
- const CommandLine& command_line = parameters_.command_line_;
+ const CommandLine& command_line = parameters_.command_line;
bool no_sandbox = command_line.HasSwitch(switches::kNoSandbox);
EnableThemeSupportForRenderer(no_sandbox);
@@ -92,12 +92,12 @@ void RendererMainPlatformDelegate::PlatformUninitialize() {
}
bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
- const CommandLine& command_line = parameters_.command_line_;
+ const CommandLine& command_line = parameters_.command_line;
DVLOG(1) << "Started renderer with " << command_line.GetCommandLineString();
sandbox::TargetServices* target_services =
- parameters_.sandbox_info_.TargetServices();
+ parameters_.sandbox_info->target_services;
if (target_services && !no_sandbox) {
std::wstring test_dll_name =
@@ -115,7 +115,7 @@ bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
bool RendererMainPlatformDelegate::EnableSandbox() {
sandbox::TargetServices* target_services =
- parameters_.sandbox_info_.TargetServices();
+ parameters_.sandbox_info->target_services;
if (target_services) {
// Cause advapi32 to load before the sandbox is turned on.
diff --git a/content/shell/shell_main.cc b/content/shell/shell_main.cc
index d6b2dde..b998aed 100644
--- a/content/shell/shell_main.cc
+++ b/content/shell/shell_main.cc
@@ -8,7 +8,7 @@
#include "sandbox/src/sandbox_types.h"
#if defined(OS_WIN)
-#include "content/app/startup_helper_win.h"
+#include "content/public/app/startup_helper_win.h"
#endif
#if defined(OS_WIN)
diff --git a/content/test/browser_test_base.cc b/content/test/browser_test_base.cc
index 57ca142..d1f89f8 100644
--- a/content/test/browser_test_base.cc
+++ b/content/test/browser_test_base.cc
@@ -27,10 +27,7 @@ BrowserTestBase::~BrowserTestBase() {
}
void BrowserTestBase::SetUp() {
- SandboxInitWrapper sandbox_wrapper;
- MainFunctionParams params(*CommandLine::ForCurrentProcess(),
- sandbox_wrapper,
- NULL);
+ MainFunctionParams params(*CommandLine::ForCurrentProcess());
params.ui_task =
NewRunnableMethod(this, &BrowserTestBase::ProxyRunTestOnMainThreadLoop);
diff --git a/content/test/content_browser_test.cc b/content/test/content_browser_test.cc
index 2f97e0e..b1dddd0 100644
--- a/content/test/content_browser_test.cc
+++ b/content/test/content_browser_test.cc
@@ -5,12 +5,15 @@
#include "content/test/content_browser_test.h"
#include "base/debug/stack_trace.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "content/shell/shell.h"
#include "content/shell/shell_main_delegate.h"
#include "content/test/test_content_client.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
ContentBrowserTest::ContentBrowserTest() {
}
@@ -46,6 +49,7 @@ void ContentBrowserTest::RunTestOnMainThreadLoop() {
signal(SIGTERM, DumpStackTraceSignalHandler);
#endif // defined(OS_POSIX)
+#if defined(OS_MACOSX)
// On Mac, without the following autorelease pool, code which is directly
// executed (as opposed to executed inside a message loop) would autorelease
// objects into a higher-level pool. This pool is not recycled in-sync with
@@ -54,14 +58,22 @@ void ContentBrowserTest::RunTestOnMainThreadLoop() {
// browser shutdown). To avoid this, the following pool is recycled after each
// time code is directly executed.
base::mac::ScopedNSAutoreleasePool pool;
+#endif
// Pump startup related events.
MessageLoopForUI::current()->RunAllPending();
+
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
RunTestOnMainThread();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
MessageLoopForUI::current()->Quit();
+#if defined(OS_MACOSX)
pool.Recycle();
+#endif
}
diff --git a/content/test/content_test_launcher.cc b/content/test/content_test_launcher.cc
index f5074cd8..f2cd5a3 100644
--- a/content/test/content_test_launcher.cc
+++ b/content/test/content_test_launcher.cc
@@ -15,7 +15,7 @@
#include "content/shell/shell_main_delegate.h"
#if defined(OS_WIN)
-#include "content/app/startup_helper_win.h"
+#include "content/public/app/startup_helper_win.h"
#include "sandbox/src/sandbox_types.h"
#endif // defined(OS_WIN)
diff --git a/content/test/render_view_test.cc b/content/test/render_view_test.cc
index 5ac9ff1..eacb390 100644
--- a/content/test/render_view_test.cc
+++ b/content/test/render_view_test.cc
@@ -96,10 +96,8 @@ void RenderViewTest::SetUp() {
render_thread_.reset(new MockRenderThread());
render_thread_->set_routing_id(kRouteId);
- sandbox_init_wrapper_.reset(new SandboxInitWrapper());
command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
- params_.reset(new MainFunctionParams(*command_line_, *sandbox_init_wrapper_,
- NULL));
+ params_.reset(new MainFunctionParams(*command_line_));
platform_.reset(new RendererMainPlatformDelegate(*params_));
platform_->PlatformInitialize();
@@ -154,7 +152,6 @@ void RenderViewTest::TearDown() {
platform_.reset();
params_.reset();
command_line_.reset();
- sandbox_init_wrapper_.reset();
}
int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout,
diff --git a/content/test/render_view_test.h b/content/test/render_view_test.h
index 1d3a6a5..e2b995a 100644
--- a/content/test/render_view_test.h
+++ b/content/test/render_view_test.h
@@ -12,7 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "content/common/main_function_params.h"
-#include "content/common/sandbox_init_wrapper.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/renderer/mock_content_renderer_client.h"
#include "content/renderer/renderer_webkitplatformsupport_impl.h"
@@ -126,7 +125,6 @@ class RenderViewTest : public testing::Test {
scoped_ptr<RendererMainPlatformDelegate> platform_;
scoped_ptr<MainFunctionParams> params_;
scoped_ptr<CommandLine> command_line_;
- scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_;
};
} // namespace content
diff --git a/content/test/test_launcher.cc b/content/test/test_launcher.cc
index 729384b..dde7d19 100644
--- a/content/test/test_launcher.cc
+++ b/content/test/test_launcher.cc
@@ -12,7 +12,6 @@
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/process_util.h"
@@ -33,6 +32,8 @@
#include "sandbox/src/dep.h"
#include "sandbox/src/sandbox_factory.h"
#include "sandbox/src/sandbox_types.h"
+#elif defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
#endif
namespace test_launcher {
@@ -302,9 +303,11 @@ int GetTestTerminationTimeout(const std::string& test_name,
int RunTest(TestLauncherDelegate* launcher_delegate,
const std::string& test_name,
int default_timeout_ms) {
+#if defined(OS_MACOSXS)
// Some of the below method calls will leak objects if there is no
// autorelease pool in place.
base::mac::ScopedNSAutoreleasePool pool;
+#endif
const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
CommandLine new_cmd_line(cmd_line->GetProgram());
diff --git a/content/utility/utility_main.cc b/content/utility/utility_main.cc
index f97d1d3..ccbdc65 100644
--- a/content/utility/utility_main.cc
+++ b/content/utility/utility_main.cc
@@ -29,10 +29,10 @@ int UtilityMain(const MainFunctionParams& parameters) {
utility_process.set_main_thread(new UtilityThreadImpl());
#if defined(OS_WIN)
- bool no_sandbox = parameters.command_line_.HasSwitch(switches::kNoSandbox);
+ bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox);
if (!no_sandbox) {
sandbox::TargetServices* target_services =
- parameters.sandbox_info_.TargetServices();
+ parameters.sandbox_info->target_services;
if (!target_services)
return false;
target_services->LowerToken();
diff --git a/content/worker/worker_main.cc b/content/worker/worker_main.cc
index 70e0aaf..8182a23 100644
--- a/content/worker/worker_main.cc
+++ b/content/worker/worker_main.cc
@@ -14,7 +14,7 @@
#include "content/worker/worker_thread.h"
#if defined(OS_WIN)
-#include "content/common/sandbox_init_wrapper.h"
+#include "content/public/common/sandbox_init.h"
#include "sandbox/src/sandbox.h"
#endif
@@ -31,7 +31,7 @@ int WorkerMain(const MainFunctionParams& parameters) {
worker_process.set_main_thread(new WorkerThread());
#if defined(OS_WIN)
sandbox::TargetServices* target_services =
- parameters.sandbox_info_.TargetServices();
+ parameters.sandbox_info->target_services;
if (!target_services)
return false;
@@ -45,7 +45,7 @@ int WorkerMain(const MainFunctionParams& parameters) {
target_services->LowerToken();
#endif
- const CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line;
if (parsed_command_line.HasSwitch(switches::kWaitForDebugger)) {
ChildProcess::WaitForDebugger("Worker");
}
diff --git a/gpu/command_buffer/client/cmd_buffer_helper_test.cc b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
index c32a803..7fe00a4 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper_test.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper_test.cc
@@ -5,7 +5,6 @@
// Tests for the Command Buffer Helper.
#include "base/callback.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "gpu/command_buffer/client/cmd_buffer_helper.h"
#include "gpu/command_buffer/service/mocks.h"
@@ -13,6 +12,10 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
namespace gpu {
using testing::Return;
@@ -152,7 +155,9 @@ class CommandBufferHelperTest : public testing::Test {
CommandBufferOffset get_helper_put() { return helper_->put_; }
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool_;
+#endif
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
diff --git a/gpu/command_buffer/client/fenced_allocator_test.cc b/gpu/command_buffer/client/fenced_allocator_test.cc
index aae3fd4..1aeaaee 100644
--- a/gpu/command_buffer/client/fenced_allocator_test.cc
+++ b/gpu/command_buffer/client/fenced_allocator_test.cc
@@ -6,7 +6,6 @@
#include "base/callback.h"
#include "base/message_loop.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "gpu/command_buffer/client/cmd_buffer_helper.h"
#include "gpu/command_buffer/client/fenced_allocator.h"
#include "gpu/command_buffer/service/cmd_buffer_engine.h"
@@ -15,6 +14,10 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
namespace gpu {
using testing::Return;
@@ -66,7 +69,9 @@ class BaseFencedAllocatorTest : public testing::Test {
return command_buffer_->GetState().token;
}
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool_;
+#endif
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
diff --git a/gpu/command_buffer/client/mapped_memory_unittest.cc b/gpu/command_buffer/client/mapped_memory_unittest.cc
index 6ca8c14..b5cb183 100644
--- a/gpu/command_buffer/client/mapped_memory_unittest.cc
+++ b/gpu/command_buffer/client/mapped_memory_unittest.cc
@@ -5,7 +5,6 @@
#include "gpu/command_buffer/client/mapped_memory.h"
#include "base/callback.h"
#include "base/message_loop.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "gpu/command_buffer/client/cmd_buffer_helper.h"
#include "gpu/command_buffer/service/mocks.h"
@@ -13,6 +12,10 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
namespace gpu {
using testing::Return;
@@ -64,7 +67,9 @@ class MappedMemoryTestBase : public testing::Test {
return command_buffer_->GetState().token;
}
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool_;
+#endif
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
diff --git a/gpu/command_buffer/client/ring_buffer_test.cc b/gpu/command_buffer/client/ring_buffer_test.cc
index ee21614..e73dbe2 100644
--- a/gpu/command_buffer/client/ring_buffer_test.cc
+++ b/gpu/command_buffer/client/ring_buffer_test.cc
@@ -7,7 +7,6 @@
#include "gpu/command_buffer/client/ring_buffer.h"
#include "base/callback.h"
#include "base/message_loop.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "gpu/command_buffer/client/cmd_buffer_helper.h"
#include "gpu/command_buffer/service/cmd_buffer_engine.h"
#include "gpu/command_buffer/service/mocks.h"
@@ -15,6 +14,10 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
namespace gpu {
using testing::Return;
@@ -90,7 +93,9 @@ class BaseRingBufferTest : public testing::Test {
return command_buffer_->GetState().token;
}
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool_;
+#endif
MessageLoop message_loop_;
scoped_ptr<AsyncAPIMock> api_mock_;
scoped_ptr<CommandBufferService> command_buffer_;
diff --git a/gpu/command_buffer/service/gpu_scheduler_unittest.cc b/gpu/command_buffer/service/gpu_scheduler_unittest.cc
index ce4fa11..2d230ec 100644
--- a/gpu/command_buffer/service/gpu_scheduler_unittest.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_unittest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "gpu/command_buffer/common/command_buffer_mock.h"
#include "gpu/command_buffer/service/gpu_scheduler.h"
@@ -12,6 +11,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
using testing::_;
using testing::DoAll;
using testing::Invoke;
@@ -70,7 +73,9 @@ class GpuSchedulerTest : public testing::Test {
return command_buffer_->GetState().error;
}
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool_;
+#endif
MessageLoop message_loop;
scoped_ptr<MockCommandBuffer> command_buffer_;
scoped_ptr<base::SharedMemory> shared_memory_;
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index c527b24..533a94c 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -26,7 +26,6 @@
#include "base/environment.h"
#include "base/file_path.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/test/mock_chrome_application_mac.h"
@@ -51,9 +50,9 @@
#if defined(TOOLKIT_USES_GTK)
#include "ui/gfx/gtk_util.h"
-#endif
-
-#if defined(OS_WIN)
+#elif defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#elif defined(OS_WIN)
// TODO(garykac) Make simple host into a proper GUI app on Windows so that we
// have an hModule for the dialog resource.
HMODULE g_hModule = NULL;
@@ -261,8 +260,11 @@ class SimpleHost {
};
int main(int argc, char** argv) {
- // Needed for the Mac, so we don't leak objects when threads are created.
+#if defined(OS_MACOSX)
+ // Needed so we don't leak objects when threads are created.
base::mac::ScopedNSAutoreleasePool pool;
+ mock_cr_app::RegisterMockCrApp();
+#endif
CommandLine::Init(argc, argv);
const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
@@ -274,10 +276,6 @@ int main(int argc, char** argv) {
gfx::GtkInitFromCommandLine(*cmd_line);
#endif // TOOLKIT_USES_GTK
-#if defined(OS_MACOSX)
- mock_cr_app::RegisterMockCrApp();
-#endif // OS_MACOSX
-
SimpleHost simple_host;
if (cmd_line->HasSwitch(kConfigSwitchName)) {
diff --git a/sandbox/src/sandbox_types.h b/sandbox/src/sandbox_types.h
index dee1838..ce9b767 100644
--- a/sandbox/src/sandbox_types.h
+++ b/sandbox/src/sandbox_types.h
@@ -51,16 +51,11 @@ enum TerminationCodes {
SBOX_FATAL_CLOSEHANDLES = 7010 // Failed to close pending handles.
};
-class TargetServices;
class BrokerServices;
+class TargetServices;
-// Contains the pointer to a target or broker service. Older code used
-// a union so the |legacy| member is there for us to detect we are
-// being passed a SandboxInterfaceInfo by old code. If legacy is not
-// null it means we are dealing with old code a must copy this value
-// into both |broker_services| and |target_services|.
+// Contains the pointer to a target or broker service.
struct SandboxInterfaceInfo {
- void* legacy;
BrokerServices* broker_services;
TargetServices* target_services;
};
diff --git a/webkit/tools/test_shell/run_all_tests.cc b/webkit/tools/test_shell/run_all_tests.cc
index 8486362..176f8b9 100644
--- a/webkit/tools/test_shell/run_all_tests.cc
+++ b/webkit/tools/test_shell/run_all_tests.cc
@@ -13,7 +13,6 @@
#endif
#include "base/command_line.h"
-#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/test/test_suite.h"
@@ -28,6 +27,7 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/path_service.h"
#endif
@@ -106,7 +106,9 @@ class TestShellTestSuite : public base::TestSuite {
};
int main(int argc, char** argv) {
+#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool scoped_pool;
+#endif
TestShellPlatformDelegate::PreflightArgs(&argc, &argv);
return TestShellTestSuite(argc, argv).Run();