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/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 } // namespace | 128 } // namespace |
129 | 129 |
130 #endif // OS_WIN | 130 #endif // OS_WIN |
131 | 131 |
132 class BrowserMainRunnerImpl : public BrowserMainRunner { | 132 class BrowserMainRunnerImpl : public BrowserMainRunner { |
133 public: | 133 public: |
134 BrowserMainRunnerImpl() | 134 BrowserMainRunnerImpl() |
135 : initialization_started_(false), is_shutdown_(false) {} | 135 : initialization_started_(false), is_shutdown_(false) {} |
136 | 136 |
137 virtual ~BrowserMainRunnerImpl() { | 137 ~BrowserMainRunnerImpl() override { |
138 if (initialization_started_ && !is_shutdown_) | 138 if (initialization_started_ && !is_shutdown_) |
139 Shutdown(); | 139 Shutdown(); |
140 } | 140 } |
141 | 141 |
142 virtual int Initialize(const MainFunctionParams& parameters) override { | 142 int Initialize(const MainFunctionParams& parameters) override { |
143 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize"); | 143 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize"); |
144 // On Android we normally initialize the browser in a series of UI thread | 144 // On Android we normally initialize the browser in a series of UI thread |
145 // tasks. While this is happening a second request can come from the OS or | 145 // tasks. While this is happening a second request can come from the OS or |
146 // another application to start the browser. If this happens then we must | 146 // another application to start the browser. If this happens then we must |
147 // not run these parts of initialization twice. | 147 // not run these parts of initialization twice. |
148 if (!initialization_started_) { | 148 if (!initialization_started_) { |
149 initialization_started_ = true; | 149 initialization_started_ = true; |
150 | 150 |
151 #if !defined(OS_IOS) | 151 #if !defined(OS_IOS) |
152 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 152 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 209 } |
210 main_loop_->CreateStartupTasks(); | 210 main_loop_->CreateStartupTasks(); |
211 int result_code = main_loop_->GetResultCode(); | 211 int result_code = main_loop_->GetResultCode(); |
212 if (result_code > 0) | 212 if (result_code > 0) |
213 return result_code; | 213 return result_code; |
214 | 214 |
215 // Return -1 to indicate no early termination. | 215 // Return -1 to indicate no early termination. |
216 return -1; | 216 return -1; |
217 } | 217 } |
218 | 218 |
219 virtual int Run() override { | 219 int Run() override { |
220 DCHECK(initialization_started_); | 220 DCHECK(initialization_started_); |
221 DCHECK(!is_shutdown_); | 221 DCHECK(!is_shutdown_); |
222 main_loop_->RunMainMessageLoopParts(); | 222 main_loop_->RunMainMessageLoopParts(); |
223 return main_loop_->GetResultCode(); | 223 return main_loop_->GetResultCode(); |
224 } | 224 } |
225 | 225 |
226 virtual void Shutdown() override { | 226 void Shutdown() override { |
227 DCHECK(initialization_started_); | 227 DCHECK(initialization_started_); |
228 DCHECK(!is_shutdown_); | 228 DCHECK(!is_shutdown_); |
229 #ifdef LEAK_SANITIZER | 229 #ifdef LEAK_SANITIZER |
230 // Invoke leak detection now, to avoid dealing with shutdown-only leaks. | 230 // Invoke leak detection now, to avoid dealing with shutdown-only leaks. |
231 // Normally this will have already happened in | 231 // Normally this will have already happened in |
232 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is | 232 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is |
233 // only for processes which do not instantiate a BrowserProcess. | 233 // only for processes which do not instantiate a BrowserProcess. |
234 // If leaks are found, the process will exit here. | 234 // If leaks are found, the process will exit here. |
235 __lsan_do_leak_check(); | 235 __lsan_do_leak_check(); |
236 #endif | 236 #endif |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 299 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
300 }; | 300 }; |
301 | 301 |
302 // static | 302 // static |
303 BrowserMainRunner* BrowserMainRunner::Create() { | 303 BrowserMainRunner* BrowserMainRunner::Create() { |
304 return new BrowserMainRunnerImpl(); | 304 return new BrowserMainRunnerImpl(); |
305 } | 305 } |
306 | 306 |
307 } // namespace content | 307 } // namespace content |
OLD | NEW |