OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/statistics_recorder.h" | 13 #include "base/metrics/statistics_recorder.h" |
14 #include "content/browser/browser_main_loop.h" | 14 #include "content/browser/browser_main_loop.h" |
15 #include "content/browser/notification_service_impl.h" | 15 #include "content/browser/notification_service_impl.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/main_function_params.h" | 17 #include "content/public/common/main_function_params.h" |
18 #include "ui/base/ime/input_method_initializer.h" | 18 #include "ui/base/ime/input_method_initializer.h" |
19 | 19 |
20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
21 #include "base/win/metro.h" | 21 #include "base/win/metro.h" |
| 22 #include "base/win/win_util.h" |
22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
23 #include "ui/base/win/scoped_ole_initializer.h" | 24 #include "ui/base/win/scoped_ole_initializer.h" |
24 #endif | 25 #endif |
25 | 26 |
26 bool g_exited_main_message_loop = false; | 27 bool g_exited_main_message_loop = false; |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 | 30 |
30 class BrowserMainRunnerImpl : public BrowserMainRunner { | 31 class BrowserMainRunnerImpl : public BrowserMainRunner { |
31 public: | 32 public: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // Make this call before going multithreaded, or spawning any subprocesses. | 97 // Make this call before going multithreaded, or spawning any subprocesses. |
97 base::allocator::SetupSubprocessAllocator(); | 98 base::allocator::SetupSubprocessAllocator(); |
98 #endif | 99 #endif |
99 ui::InitializeInputMethod(); | 100 ui::InitializeInputMethod(); |
100 | 101 |
101 main_loop_->CreateStartupTasks(); | 102 main_loop_->CreateStartupTasks(); |
102 int result_code = main_loop_->GetResultCode(); | 103 int result_code = main_loop_->GetResultCode(); |
103 if (result_code > 0) | 104 if (result_code > 0) |
104 return result_code; | 105 return result_code; |
105 | 106 |
| 107 #if defined(OS_WIN) |
| 108 // The process should crash when going through abnormal termination. |
| 109 // Make sure this is done only when Shutdown() will be called. |
| 110 base::win::SetShouldCrashOnProcessDetach(true); |
| 111 base::win::SetAbortBehaviorForCrashReporting(); |
| 112 #endif |
| 113 |
106 // Return -1 to indicate no early termination. | 114 // Return -1 to indicate no early termination. |
107 return -1; | 115 return -1; |
108 } | 116 } |
109 | 117 |
110 virtual int Run() OVERRIDE { | 118 virtual int Run() OVERRIDE { |
111 DCHECK(is_initialized_); | 119 DCHECK(is_initialized_); |
112 DCHECK(!is_shutdown_); | 120 DCHECK(!is_shutdown_); |
113 main_loop_->RunMainMessageLoopParts(); | 121 main_loop_->RunMainMessageLoopParts(); |
114 return main_loop_->GetResultCode(); | 122 return main_loop_->GetResultCode(); |
115 } | 123 } |
116 | 124 |
117 virtual void Shutdown() OVERRIDE { | 125 virtual void Shutdown() OVERRIDE { |
118 DCHECK(is_initialized_); | 126 DCHECK(is_initialized_); |
119 DCHECK(!is_shutdown_); | 127 DCHECK(!is_shutdown_); |
120 g_exited_main_message_loop = true; | 128 g_exited_main_message_loop = true; |
121 | 129 |
122 main_loop_->ShutdownThreadsAndCleanUp(); | 130 main_loop_->ShutdownThreadsAndCleanUp(); |
123 | 131 |
124 ui::ShutdownInputMethod(); | 132 ui::ShutdownInputMethod(); |
125 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
126 ole_initializer_.reset(NULL); | 134 ole_initializer_.reset(NULL); |
127 #endif | 135 #endif |
128 | 136 |
129 main_loop_.reset(NULL); | 137 main_loop_.reset(NULL); |
130 | 138 |
131 notification_service_.reset(NULL); | 139 notification_service_.reset(NULL); |
132 | 140 |
| 141 #if defined(OS_WIN) |
| 142 base::win::SetShouldCrashOnProcessDetach(false); |
| 143 #endif |
| 144 |
133 is_shutdown_ = true; | 145 is_shutdown_ = true; |
134 } | 146 } |
135 | 147 |
136 protected: | 148 protected: |
137 // True if the runner has been initialized. | 149 // True if the runner has been initialized. |
138 bool is_initialized_; | 150 bool is_initialized_; |
139 | 151 |
140 // True if the runner has been shut down. | 152 // True if the runner has been shut down. |
141 bool is_shutdown_; | 153 bool is_shutdown_; |
142 | 154 |
143 scoped_ptr<NotificationServiceImpl> notification_service_; | 155 scoped_ptr<NotificationServiceImpl> notification_service_; |
144 scoped_ptr<BrowserMainLoop> main_loop_; | 156 scoped_ptr<BrowserMainLoop> main_loop_; |
145 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
146 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 158 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
147 #endif | 159 #endif |
148 | 160 |
149 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 161 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
150 }; | 162 }; |
151 | 163 |
152 // static | 164 // static |
153 BrowserMainRunner* BrowserMainRunner::Create() { | 165 BrowserMainRunner* BrowserMainRunner::Create() { |
154 return new BrowserMainRunnerImpl(); | 166 return new BrowserMainRunnerImpl(); |
155 } | 167 } |
156 | 168 |
157 } // namespace content | 169 } // namespace content |
OLD | NEW |