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" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #include "ui/base/win/scoped_ole_initializer.h" | 24 #include "ui/base/win/scoped_ole_initializer.h" |
25 #endif | 25 #endif |
26 | 26 |
27 bool g_exited_main_message_loop = false; | 27 bool g_exited_main_message_loop = false; |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 | 30 |
31 class BrowserMainRunnerImpl : public BrowserMainRunner { | 31 class BrowserMainRunnerImpl : public BrowserMainRunner { |
32 public: | 32 public: |
33 BrowserMainRunnerImpl() : is_initialized_(false), is_shutdown_(false) {} | 33 BrowserMainRunnerImpl() |
34 : initialization_started_(false), is_shutdown_(false) {} | |
34 | 35 |
35 virtual ~BrowserMainRunnerImpl() { | 36 virtual ~BrowserMainRunnerImpl() { |
36 if (is_initialized_ && !is_shutdown_) | 37 if (initialization_started_ && !is_shutdown_) |
37 Shutdown(); | 38 Shutdown(); |
38 } | 39 } |
39 | 40 |
40 virtual int Initialize(const MainFunctionParams& parameters) | 41 virtual int Initialize(const MainFunctionParams& parameters) OVERRIDE { |
41 OVERRIDE { | 42 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize"); |
42 TRACE_EVENT0("startup", "BrowserMainRunnerImpl::Initialize") | 43 // On Android we normally initialize the browser in a series of UI thread |
43 is_initialized_ = true; | 44 // tasks. While this is happening a second request can come from the OS or |
45 // another application to start the browser. If this happens then we must | |
46 // not run these parts of initialization twice. | |
47 if (!initialization_started_) { | |
48 initialization_started_ = true; | |
44 | 49 |
45 #if !defined(OS_IOS) | 50 #if !defined(OS_IOS) |
46 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) | 51 if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) |
47 base::debug::WaitForDebugger(60, true); | 52 base::debug::WaitForDebugger(60, true); |
48 #endif | 53 #endif |
49 | 54 |
50 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
51 if (parameters.command_line.HasSwitch( | 56 if (parameters.command_line.HasSwitch( |
52 switches::kEnableTextServicesFramework)) { | 57 switches::kEnableTextServicesFramework)) { |
53 base::win::SetForceToUseTSF(); | 58 base::win::SetForceToUseTSF(); |
54 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 59 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
55 // When "Extend support of advanced text services to all programs" | 60 // When "Extend support of advanced text services to all programs" |
56 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on | 61 // (a.k.a. Cicero Unaware Application Support; CUAS) is enabled on |
57 // Windows XP and handwriting modules shipped with Office 2003 are | 62 // Windows XP and handwriting modules shipped with Office 2003 are |
58 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then crash | 63 // installed, "penjpn.dll" and "skchui.dll" will be loaded and then |
59 // unless a user installs Office 2003 SP3. To prevent these modules from | 64 // crash |
60 // being loaded, disable TSF entirely. crbug/160914. | 65 // unless a user installs Office 2003 SP3. To prevent these modules from |
61 // TODO(yukawa): Add a high-level wrapper for this instead of calling | 66 // being loaded, disable TSF entirely. crbug/160914. |
62 // Win32 API here directly. | 67 // TODO(yukawa): Add a high-level wrapper for this instead of calling |
63 ImmDisableTextFrameService(static_cast<DWORD>(-1)); | 68 // Win32 API here directly. |
64 } | 69 ImmDisableTextFrameService(static_cast<DWORD>(-1)); |
70 } | |
65 #endif // OS_WIN | 71 #endif // OS_WIN |
66 | 72 |
67 base::StatisticsRecorder::Initialize(); | 73 base::StatisticsRecorder::Initialize(); |
68 | 74 |
69 notification_service_.reset(new NotificationServiceImpl); | 75 notification_service_.reset(new NotificationServiceImpl); |
70 | 76 |
71 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
72 // Ole must be initialized before starting message pump, so that TSF | 78 // Ole must be initialized before starting message pump, so that TSF |
73 // (Text Services Framework) module can interact with the message pump | 79 // (Text Services Framework) module can interact with the message pump |
74 // on Windows 8 Metro mode. | 80 // on Windows 8 Metro mode. |
75 ole_initializer_.reset(new ui::ScopedOleInitializer); | 81 ole_initializer_.reset(new ui::ScopedOleInitializer); |
76 #endif // OS_WIN | 82 #endif // OS_WIN |
77 | 83 |
78 main_loop_.reset(new BrowserMainLoop(parameters)); | 84 main_loop_.reset(new BrowserMainLoop(parameters)); |
79 | 85 |
80 main_loop_->Init(); | 86 main_loop_->Init(); |
81 | 87 |
82 main_loop_->EarlyInitialization(); | 88 main_loop_->EarlyInitialization(); |
83 | 89 |
84 // Must happen before we try to use a message loop or display any UI. | 90 // Must happen before we try to use a message loop or display any UI. |
85 main_loop_->InitializeToolkit(); | 91 main_loop_->InitializeToolkit(); |
86 | 92 |
87 main_loop_->MainMessageLoopStart(); | 93 main_loop_->MainMessageLoopStart(); |
88 | 94 |
89 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here | 95 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here |
90 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 96 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
91 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 97 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
92 | 98 |
93 #if defined(OS_WIN) && !defined(NO_TCMALLOC) | 99 #if defined(OS_WIN) && !defined(NO_TCMALLOC) |
94 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic | 100 // When linking shared libraries, NO_TCMALLOC is defined, and dynamic |
95 // allocator selection is not supported. | 101 // allocator selection is not supported. |
96 | 102 |
97 // Make this call before going multithreaded, or spawning any subprocesses. | 103 // Make this call before going multithreaded, or spawning any |
98 base::allocator::SetupSubprocessAllocator(); | 104 // subprocesses. |
105 base::allocator::SetupSubprocessAllocator(); | |
99 #endif | 106 #endif |
100 ui::InitializeInputMethod(); | 107 ui::InitializeInputMethod(); |
101 | 108 } |
102 main_loop_->CreateStartupTasks(); | 109 main_loop_->CreateStartupTasks(); |
103 int result_code = main_loop_->GetResultCode(); | 110 int result_code = main_loop_->GetResultCode(); |
104 if (result_code > 0) | 111 if (result_code > 0) |
105 return result_code; | 112 return result_code; |
106 | 113 |
107 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
108 // The process should crash when going through abnormal termination. | 115 // The process should crash when going through abnormal termination. |
109 // Make sure this is done only when Shutdown() will be called. | 116 // Make sure this is done only when Shutdown() will be called. |
110 base::win::SetShouldCrashOnProcessDetach(true); | 117 base::win::SetShouldCrashOnProcessDetach(true); |
111 base::win::SetAbortBehaviorForCrashReporting(); | 118 base::win::SetAbortBehaviorForCrashReporting(); |
112 #endif | 119 #endif |
113 | 120 |
114 // Return -1 to indicate no early termination. | 121 // Return -1 to indicate no early termination. |
115 return -1; | 122 return -1; |
116 } | 123 } |
117 | 124 |
118 virtual int Run() OVERRIDE { | 125 virtual int Run() OVERRIDE { |
119 DCHECK(is_initialized_); | 126 DCHECK(initialization_started_); |
120 DCHECK(!is_shutdown_); | 127 DCHECK(!is_shutdown_); |
121 main_loop_->RunMainMessageLoopParts(); | 128 main_loop_->RunMainMessageLoopParts(); |
122 return main_loop_->GetResultCode(); | 129 return main_loop_->GetResultCode(); |
123 } | 130 } |
124 | 131 |
125 virtual void Shutdown() OVERRIDE { | 132 virtual void Shutdown() OVERRIDE { |
126 DCHECK(is_initialized_); | 133 DCHECK(initialization_started_); |
127 DCHECK(!is_shutdown_); | 134 DCHECK(!is_shutdown_); |
128 g_exited_main_message_loop = true; | 135 g_exited_main_message_loop = true; |
129 | 136 |
130 main_loop_->ShutdownThreadsAndCleanUp(); | 137 main_loop_->ShutdownThreadsAndCleanUp(); |
131 | 138 |
132 ui::ShutdownInputMethod(); | 139 ui::ShutdownInputMethod(); |
133 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
134 ole_initializer_.reset(NULL); | 141 ole_initializer_.reset(NULL); |
135 #endif | 142 #endif |
136 | 143 |
137 main_loop_.reset(NULL); | 144 main_loop_.reset(NULL); |
138 | 145 |
139 notification_service_.reset(NULL); | 146 notification_service_.reset(NULL); |
140 | 147 |
141 #if defined(OS_WIN) | 148 #if defined(OS_WIN) |
142 base::win::SetShouldCrashOnProcessDetach(false); | 149 base::win::SetShouldCrashOnProcessDetach(false); |
143 #endif | 150 #endif |
144 | 151 |
145 is_shutdown_ = true; | 152 is_shutdown_ = true; |
146 } | 153 } |
147 | 154 |
148 protected: | 155 protected: |
149 // True if the runner has been initialized. | 156 // True if the runner has been initialized. |
Yaron
2013/08/22 06:00:26
Nit: update
aberent
2013/08/23 11:40:21
Done.
| |
150 bool is_initialized_; | 157 bool initialization_started_; |
151 | 158 |
152 // True if the runner has been shut down. | 159 // True if the runner has been shut down. |
153 bool is_shutdown_; | 160 bool is_shutdown_; |
154 | 161 |
155 scoped_ptr<NotificationServiceImpl> notification_service_; | 162 scoped_ptr<NotificationServiceImpl> notification_service_; |
156 scoped_ptr<BrowserMainLoop> main_loop_; | 163 scoped_ptr<BrowserMainLoop> main_loop_; |
157 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
158 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 165 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
159 #endif | 166 #endif |
160 | 167 |
161 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 168 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
162 }; | 169 }; |
163 | 170 |
164 // static | 171 // static |
165 BrowserMainRunner* BrowserMainRunner::Create() { | 172 BrowserMainRunner* BrowserMainRunner::Create() { |
166 return new BrowserMainRunnerImpl(); | 173 return new BrowserMainRunnerImpl(); |
167 } | 174 } |
168 | 175 |
169 } // namespace content | 176 } // namespace content |
OLD | NEW |