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" | |
23 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
24 #include "ui/base/win/scoped_ole_initializer.h" | 23 #include "ui/base/win/scoped_ole_initializer.h" |
25 #endif | 24 #endif |
26 | 25 |
27 bool g_exited_main_message_loop = false; | 26 bool g_exited_main_message_loop = false; |
28 | 27 |
29 namespace content { | 28 namespace content { |
30 | 29 |
31 class BrowserMainRunnerImpl : public BrowserMainRunner { | 30 class BrowserMainRunnerImpl : public BrowserMainRunner { |
32 public: | 31 public: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Make this call before going multithreaded, or spawning any subprocesses. | 96 // Make this call before going multithreaded, or spawning any subprocesses. |
98 base::allocator::SetupSubprocessAllocator(); | 97 base::allocator::SetupSubprocessAllocator(); |
99 #endif | 98 #endif |
100 ui::InitializeInputMethod(); | 99 ui::InitializeInputMethod(); |
101 | 100 |
102 main_loop_->CreateStartupTasks(); | 101 main_loop_->CreateStartupTasks(); |
103 int result_code = main_loop_->GetResultCode(); | 102 int result_code = main_loop_->GetResultCode(); |
104 if (result_code > 0) | 103 if (result_code > 0) |
105 return result_code; | 104 return result_code; |
106 | 105 |
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 | |
114 // Return -1 to indicate no early termination. | 106 // Return -1 to indicate no early termination. |
115 return -1; | 107 return -1; |
116 } | 108 } |
117 | 109 |
118 virtual int Run() OVERRIDE { | 110 virtual int Run() OVERRIDE { |
119 DCHECK(is_initialized_); | 111 DCHECK(is_initialized_); |
120 DCHECK(!is_shutdown_); | 112 DCHECK(!is_shutdown_); |
121 main_loop_->RunMainMessageLoopParts(); | 113 main_loop_->RunMainMessageLoopParts(); |
122 return main_loop_->GetResultCode(); | 114 return main_loop_->GetResultCode(); |
123 } | 115 } |
124 | 116 |
125 virtual void Shutdown() OVERRIDE { | 117 virtual void Shutdown() OVERRIDE { |
126 DCHECK(is_initialized_); | 118 DCHECK(is_initialized_); |
127 DCHECK(!is_shutdown_); | 119 DCHECK(!is_shutdown_); |
128 g_exited_main_message_loop = true; | 120 g_exited_main_message_loop = true; |
129 | 121 |
130 main_loop_->ShutdownThreadsAndCleanUp(); | 122 main_loop_->ShutdownThreadsAndCleanUp(); |
131 | 123 |
132 ui::ShutdownInputMethod(); | 124 ui::ShutdownInputMethod(); |
133 #if defined(OS_WIN) | 125 #if defined(OS_WIN) |
134 ole_initializer_.reset(NULL); | 126 ole_initializer_.reset(NULL); |
135 #endif | 127 #endif |
136 | 128 |
137 main_loop_.reset(NULL); | 129 main_loop_.reset(NULL); |
138 | 130 |
139 notification_service_.reset(NULL); | 131 notification_service_.reset(NULL); |
140 | 132 |
141 #if defined(OS_WIN) | |
142 base::win::SetShouldCrashOnProcessDetach(false); | |
143 #endif | |
144 | |
145 is_shutdown_ = true; | 133 is_shutdown_ = true; |
146 } | 134 } |
147 | 135 |
148 protected: | 136 protected: |
149 // True if the runner has been initialized. | 137 // True if the runner has been initialized. |
150 bool is_initialized_; | 138 bool is_initialized_; |
151 | 139 |
152 // True if the runner has been shut down. | 140 // True if the runner has been shut down. |
153 bool is_shutdown_; | 141 bool is_shutdown_; |
154 | 142 |
155 scoped_ptr<NotificationServiceImpl> notification_service_; | 143 scoped_ptr<NotificationServiceImpl> notification_service_; |
156 scoped_ptr<BrowserMainLoop> main_loop_; | 144 scoped_ptr<BrowserMainLoop> main_loop_; |
157 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
158 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 146 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
159 #endif | 147 #endif |
160 | 148 |
161 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 149 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
162 }; | 150 }; |
163 | 151 |
164 // static | 152 // static |
165 BrowserMainRunner* BrowserMainRunner::Create() { | 153 BrowserMainRunner* BrowserMainRunner::Create() { |
166 return new BrowserMainRunnerImpl(); | 154 return new BrowserMainRunnerImpl(); |
167 } | 155 } |
168 | 156 |
169 } // namespace content | 157 } // namespace content |
OLD | NEW |