OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_main.h" | 5 #include "content/browser/browser_main.h" |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "content/browser/browser_main_loop.h" | 12 #include "content/browser/browser_main_loop.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
14 #include "content/browser/notification_service_impl.h" | 14 #include "content/browser/notification_service_impl.h" |
15 #include "content/common/main_function_params.h" | 15 #include "content/common/main_function_params.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 | 17 |
18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
19 #include "base/win/scoped_com_initializer.h" | 19 #include "base/win/scoped_com_initializer.h" |
20 #include "content/common/sandbox_policy.h" | |
21 #include "sandbox/src/sandbox.h" | |
22 #endif | 20 #endif |
23 | 21 |
24 namespace { | 22 namespace { |
25 | 23 |
26 #if defined(OS_WIN) | |
27 // Windows-specific initialization code for the sandbox broker services. | |
28 void InitializeBrokerServices(const MainFunctionParams& parameters, | |
29 const CommandLine& parsed_command_line) { | |
30 sandbox::BrokerServices* broker_services = | |
31 parameters.sandbox_info_.BrokerServices(); | |
32 if (broker_services) { | |
33 sandbox::InitBrokerServices(broker_services); | |
34 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { | |
35 bool use_winsta = !parsed_command_line.HasSwitch( | |
36 switches::kDisableAltWinstation); | |
37 // Precreate the desktop and window station used by the renderers. | |
38 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
39 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | |
40 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
41 policy->Release(); | |
42 } | |
43 } | |
44 } | |
45 #endif | |
46 | |
47 bool g_exited_main_message_loop = false; | 24 bool g_exited_main_message_loop = false; |
48 | 25 |
49 } // namespace | 26 } // namespace |
50 | 27 |
51 namespace content { | 28 namespace content { |
52 | 29 |
53 bool ExitedMainMessageLoop() { | 30 bool ExitedMainMessageLoop() { |
54 return g_exited_main_message_loop; | 31 return g_exited_main_message_loop; |
55 } | 32 } |
56 | 33 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // TODO(viettrungluu): put the remainder into BrowserMainParts | 77 // TODO(viettrungluu): put the remainder into BrowserMainParts |
101 | 78 |
102 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
103 #if !defined(NO_TCMALLOC) | 80 #if !defined(NO_TCMALLOC) |
104 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 81 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
105 // allocator selection is not supported. | 82 // allocator selection is not supported. |
106 | 83 |
107 // Make this call before going multithreaded, or spawning any subprocesses. | 84 // Make this call before going multithreaded, or spawning any subprocesses. |
108 base::allocator::SetupSubprocessAllocator(); | 85 base::allocator::SetupSubprocessAllocator(); |
109 #endif | 86 #endif |
110 // The broker service initialization needs to run early because it will | |
111 // initialize the sandbox broker, which requires the process to swap its | |
112 // window station. During this time all the UI will be broken. This has to | |
113 // run before threads and windows are created. | |
114 InitializeBrokerServices(parameters, parameters.command_line_); | |
115 | 87 |
116 base::win::ScopedCOMInitializer com_initializer; | 88 base::win::ScopedCOMInitializer com_initializer; |
117 #endif // OS_WIN | 89 #endif // OS_WIN |
118 | 90 |
119 base::StatisticsRecorder statistics; | 91 base::StatisticsRecorder statistics; |
120 | 92 |
121 main_loop->RunMainMessageLoopParts(&g_exited_main_message_loop); | 93 main_loop->RunMainMessageLoopParts(&g_exited_main_message_loop); |
122 | 94 |
123 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); | 95 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); |
124 | 96 |
125 return main_loop->GetResultCode(); | 97 return main_loop->GetResultCode(); |
126 } | 98 } |
OLD | NEW |