This source file includes following definitions.
- is_shutdown_
- Initialize
- Run
- Shutdown
- Create
#include "content/public/browser/browser_main_runner.h"
#include "base/allocator/allocator_shim.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/statistics_recorder.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/browser_shutdown_profile_dumper.h"
#include "content/browser/notification_service_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "ui/base/ime/input_method_initializer.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "ui/base/win/scoped_ole_initializer.h"
#endif
bool g_exited_main_message_loop = false;
namespace content {
class BrowserMainRunnerImpl : public BrowserMainRunner {
public:
BrowserMainRunnerImpl()
: initialization_started_(false), is_shutdown_(false) {}
virtual ~BrowserMainRunnerImpl() {
if (initialization_started_ && !is_shutdown_)
Shutdown();
}
virtual int Initialize(const MainFunctionParams& parameters) OVERRIDE {
TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize");
if (!initialization_started_) {
initialization_started_ = true;
#if !defined(OS_IOS)
if (parameters.command_line.HasSwitch(switches::kWaitForDebugger))
base::debug::WaitForDebugger(60, true);
#endif
#if defined(OS_WIN)
if (base::win::GetVersion() < base::win::VERSION_VISTA) {
ImmDisableTextFrameService(static_cast<DWORD>(-1));
}
#endif
base::StatisticsRecorder::Initialize();
notification_service_.reset(new NotificationServiceImpl);
#if defined(OS_WIN)
ole_initializer_.reset(new ui::ScopedOleInitializer);
#endif
main_loop_.reset(new BrowserMainLoop(parameters));
main_loop_->Init();
main_loop_->EarlyInitialization();
main_loop_->InitializeToolkit();
main_loop_->MainMessageLoopStart();
#if defined(OS_WIN) && !defined(NO_TCMALLOC)
base::allocator::SetupSubprocessAllocator();
#endif
ui::InitializeInputMethod();
}
main_loop_->CreateStartupTasks();
int result_code = main_loop_->GetResultCode();
if (result_code > 0)
return result_code;
return -1;
}
virtual int Run() OVERRIDE {
DCHECK(initialization_started_);
DCHECK(!is_shutdown_);
main_loop_->RunMainMessageLoopParts();
return main_loop_->GetResultCode();
}
virtual void Shutdown() OVERRIDE {
DCHECK(initialization_started_);
DCHECK(!is_shutdown_);
#ifdef LEAK_SANITIZER
__lsan_do_leak_check();
#endif
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
scoped_ptr<BrowserShutdownProfileDumper> profiler;
if (command_line.HasSwitch(switches::kTraceShutdown))
profiler.reset(new BrowserShutdownProfileDumper());
{
TRACE_EVENT0("shutdown", "BrowserMainRunner");
g_exited_main_message_loop = true;
main_loop_->ShutdownThreadsAndCleanUp();
ui::ShutdownInputMethod();
#if defined(OS_WIN)
ole_initializer_.reset(NULL);
#endif
main_loop_.reset(NULL);
notification_service_.reset(NULL);
is_shutdown_ = true;
}
}
protected:
bool initialization_started_;
bool is_shutdown_;
scoped_ptr<NotificationServiceImpl> notification_service_;
scoped_ptr<BrowserMainLoop> main_loop_;
#if defined(OS_WIN)
scoped_ptr<ui::ScopedOleInitializer> ole_initializer_;
#endif
DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl);
};
BrowserMainRunner* BrowserMainRunner::Create() {
return new BrowserMainRunnerImpl();
}
}