Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 8539038: Add ChromeBrowserMainExtraParts for non main parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify CL. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) 151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters)
152 : parameters_(parameters), 152 : parameters_(parameters),
153 parsed_command_line_(parameters.command_line), 153 parsed_command_line_(parameters.command_line),
154 result_code_(content::RESULT_CODE_NORMAL_EXIT) { 154 result_code_(content::RESULT_CODE_NORMAL_EXIT) {
155 #if defined(OS_WIN) 155 #if defined(OS_WIN)
156 OleInitialize(NULL); 156 OleInitialize(NULL);
157 #endif 157 #endif
158 } 158 }
159 159
160 BrowserMainLoop::~BrowserMainLoop() { 160 BrowserMainLoop::~BrowserMainLoop() {
161 // Destroy added parts in reverse order. 161 delete parts_;
162 for (int i = static_cast<int>(parts_list_.size())-1; i >= 0; --i)
163 delete parts_list_[i];
164 parts_list_.clear();
165 162
166 #if defined(OS_WIN) 163 #if defined(OS_WIN)
167 OleUninitialize(); 164 OleUninitialize();
168 #endif 165 #endif
169 } 166 }
170 167
171 void BrowserMainLoop::Init() { 168 void BrowserMainLoop::Init() {
172 GetContentClient()->browser()->CreateBrowserMainParts( 169 parts_ = GetContentClient()->browser()->CreateBrowserMainParts(parameters_);
173 parameters_, &parts_list_);
174 } 170 }
175 171
176 // BrowserMainLoop stages ================================================== 172 // BrowserMainLoop stages ==================================================
177 173
178 void BrowserMainLoop::EarlyInitialization() { 174 void BrowserMainLoop::EarlyInitialization() {
179 for (size_t i = 0; i < parts_list_.size(); ++i) 175 if (parts_)
180 parts_list_[i]->PreEarlyInitialization(); 176 parts_->PreEarlyInitialization();
181 177
182 #if defined(OS_WIN) 178 #if defined(OS_WIN)
183 net::EnsureWinsockInit(); 179 net::EnsureWinsockInit();
184 #endif 180 #endif
185 181
186 #if !defined(USE_OPENSSL) 182 #if !defined(USE_OPENSSL)
187 // Use NSS for SSL by default. 183 // Use NSS for SSL by default.
188 // The default client socket factory uses NSS for SSL by default on 184 // The default client socket factory uses NSS for SSL by default on
189 // Windows and Mac. 185 // Windows and Mac.
190 bool init_nspr = false; 186 bool init_nspr = false;
(...skipping 25 matching lines...) Expand all
216 if (parsed_command_line_.HasSwitch( 212 if (parsed_command_line_.HasSwitch(
217 switches::kEnableDNSCertProvenanceChecking)) { 213 switches::kEnableDNSCertProvenanceChecking)) {
218 net::SSLConfigService::EnableDNSCertProvenanceChecking(); 214 net::SSLConfigService::EnableDNSCertProvenanceChecking();
219 } 215 }
220 216
221 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't 217 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't
222 // seem dependent on SSL initialization(). 218 // seem dependent on SSL initialization().
223 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) 219 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen))
224 net::set_tcp_fastopen_enabled(true); 220 net::set_tcp_fastopen_enabled(true);
225 221
226 for (size_t i = 0; i < parts_list_.size(); ++i) 222 if (parts_)
227 parts_list_[i]->PostEarlyInitialization(); 223 parts_->PostEarlyInitialization();
228 } 224 }
229 225
230 void BrowserMainLoop::MainMessageLoopStart() { 226 void BrowserMainLoop::MainMessageLoopStart() {
231 for (size_t i = 0; i < parts_list_.size(); ++i) 227 if (parts_)
232 parts_list_[i]->PreMainMessageLoopStart(); 228 parts_->PreMainMessageLoopStart();
233 229
234 #if defined(OS_WIN) 230 #if defined(OS_WIN)
235 // If we're running tests (ui_task is non-null), then the ResourceBundle 231 // If we're running tests (ui_task is non-null), then the ResourceBundle
236 // has already been initialized. 232 // has already been initialized.
237 if (!parameters_.ui_task) { 233 if (!parameters_.ui_task) {
238 // Override the configured locale with the user's preferred UI language. 234 // Override the configured locale with the user's preferred UI language.
239 l10n_util::OverrideLocaleWithUILanguageList(); 235 l10n_util::OverrideLocaleWithUILanguageList();
240 } 236 }
241 #endif 237 #endif
242 238
243 // Must first NULL pointer or we hit a DCHECK that the newly constructed 239 // Must first NULL pointer or we hit a DCHECK that the newly constructed
244 // message loop is the current one. 240 // message loop is the current one.
245 main_message_loop_.reset(); 241 main_message_loop_.reset();
246 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); 242 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
247 243
248 InitializeMainThread(); 244 InitializeMainThread();
249 245
250 // Start tracing to a file if needed. 246 // Start tracing to a file if needed.
251 if (base::debug::TraceLog::GetInstance()->IsEnabled()) 247 if (base::debug::TraceLog::GetInstance()->IsEnabled())
252 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_); 248 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_);
253 249
254 system_monitor_.reset(new base::SystemMonitor); 250 system_monitor_.reset(new base::SystemMonitor);
255 hi_res_timer_manager_.reset(new HighResolutionTimerManager); 251 hi_res_timer_manager_.reset(new HighResolutionTimerManager);
256 252
257 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 253 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
258 254
259 for (size_t i = 0; i < parts_list_.size(); ++i) 255 if (parts_)
260 parts_list_[i]->PostMainMessageLoopStart(); 256 parts_->PostMainMessageLoopStart();
261 } 257 }
262 258
263 void BrowserMainLoop::RunMainMessageLoopParts( 259 void BrowserMainLoop::RunMainMessageLoopParts(
264 bool* completed_main_message_loop) { 260 bool* completed_main_message_loop) {
265 for (size_t i = 0; i < parts_list_.size(); ++i) 261 if (parts_)
266 parts_list_[i]->PreMainMessageLoopRun(); 262 parts_->PreMainMessageLoopRun();
267 263
268 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 264 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
269 // If the UI thread blocks, the whole UI is unresponsive. 265 // If the UI thread blocks, the whole UI is unresponsive.
270 // Do not allow disk IO from the UI thread. 266 // Do not allow disk IO from the UI thread.
271 base::ThreadRestrictions::SetIOAllowed(false); 267 base::ThreadRestrictions::SetIOAllowed(false);
272 268
273 // Iterate through each of the parts. If any of them ran the main
274 // message loop then they should return |true|. Otherwise
275 // BrowserMainLoop::MainMessageLoopRun loop will be run.
276 bool ran_main_loop = false; 269 bool ran_main_loop = false;
277 for (size_t i = 0; i < parts_list_.size(); ++i) { 270 if (parts_)
278 int result_code = result_code_; 271 ran_main_loop = parts_->MainMessageLoopRun(&result_code_);
279 if (parts_list_[i]->MainMessageLoopRun(&result_code)) { 272
280 ran_main_loop = true;
281 result_code_ = result_code;
282 }
283 }
284 if (!ran_main_loop) 273 if (!ran_main_loop)
285 MainMessageLoopRun(); 274 MainMessageLoopRun();
286 275
287 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 276 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
288 277
289 if (completed_main_message_loop) 278 if (completed_main_message_loop)
290 *completed_main_message_loop = true; 279 *completed_main_message_loop = true;
291 280
292 for (size_t i = 0; i < parts_list_.size(); ++i) 281 if (parts_)
293 parts_list_[i]->PostMainMessageLoopRun(); 282 parts_->PostMainMessageLoopRun();
294 } 283 }
295 284
296 void BrowserMainLoop::InitializeMainThread() { 285 void BrowserMainLoop::InitializeMainThread() {
297 const char* kThreadName = "CrBrowserMain"; 286 const char* kThreadName = "CrBrowserMain";
298 base::PlatformThread::SetName(kThreadName); 287 base::PlatformThread::SetName(kThreadName);
299 main_message_loop_->set_thread_name(kThreadName); 288 main_message_loop_->set_thread_name(kThreadName);
300 tracked_objects::ThreadData::InitializeThreadContext(kThreadName); 289 tracked_objects::ThreadData::InitializeThreadContext(kThreadName);
301 290
302 // Register the main thread by instantiating it, but don't call any methods. 291 // Register the main thread by instantiating it, but don't call any methods.
303 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, 292 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI,
(...skipping 29 matching lines...) Expand all
333 322
334 #if defined(OS_WIN) 323 #if defined(OS_WIN)
335 // Init common control sex. 324 // Init common control sex.
336 INITCOMMONCONTROLSEX config; 325 INITCOMMONCONTROLSEX config;
337 config.dwSize = sizeof(config); 326 config.dwSize = sizeof(config);
338 config.dwICC = ICC_WIN95_CLASSES; 327 config.dwICC = ICC_WIN95_CLASSES;
339 if (!InitCommonControlsEx(&config)) 328 if (!InitCommonControlsEx(&config))
340 LOG_GETLASTERROR(FATAL); 329 LOG_GETLASTERROR(FATAL);
341 #endif 330 #endif
342 331
343 for (size_t i = 0; i < parts_list_.size(); ++i) 332 if (parts_)
344 parts_list_[i]->ToolkitInitialized(); 333 parts_->ToolkitInitialized();
345 } 334 }
346 335
347 void BrowserMainLoop::MainMessageLoopRun() { 336 void BrowserMainLoop::MainMessageLoopRun() {
348 if (parameters_.ui_task) 337 if (parameters_.ui_task)
349 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); 338 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task);
350 339
351 #if defined(OS_MACOSX) 340 #if defined(OS_MACOSX)
352 MessageLoopForUI::current()->Run(); 341 MessageLoopForUI::current()->Run();
353 #else 342 #else
354 MessageLoopForUI::current()->RunWithDispatcher(NULL); 343 MessageLoopForUI::current()->RunWithDispatcher(NULL);
355 #endif 344 #endif
356 } 345 }
357 346
358 } // namespace content 347 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698