| OLD | NEW |
| 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" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 15 #include "content/browser/in_process_webkit/webkit_thread.h" |
| 15 #include "content/browser/trace_controller.h" | 16 #include "content/browser/trace_controller.h" |
| 16 #include "content/common/hi_res_timer_manager.h" | 17 #include "content/common/hi_res_timer_manager.h" |
| 17 #include "content/common/sandbox_policy.h" | 18 #include "content/common/sandbox_policy.h" |
| 18 #include "content/public/browser/browser_main_parts.h" | 19 #include "content/public/browser/browser_main_parts.h" |
| 19 #include "content/public/browser/browser_shutdown.h" | 20 #include "content/public/browser/browser_shutdown.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/main_function_params.h" | 23 #include "content/public/common/main_function_params.h" |
| 23 #include "content/public/common/result_codes.h" | 24 #include "content/public/common/result_codes.h" |
| 24 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 thread_id < BrowserThread::ID_COUNT; | 314 thread_id < BrowserThread::ID_COUNT; |
| 314 ++thread_id) { | 315 ++thread_id) { |
| 315 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; | 316 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; |
| 316 base::Thread::Options* options = &default_options; | 317 base::Thread::Options* options = &default_options; |
| 317 | 318 |
| 318 switch (thread_id) { | 319 switch (thread_id) { |
| 319 case BrowserThread::DB: | 320 case BrowserThread::DB: |
| 320 thread_to_start = &db_thread_; | 321 thread_to_start = &db_thread_; |
| 321 break; | 322 break; |
| 322 case BrowserThread::WEBKIT: | 323 case BrowserThread::WEBKIT: |
| 323 // For now, the WebKit thread in the browser is owned by | 324 // Special case as WebKitThread is a separate |
| 324 // ResourceDispatcherHost, not by the content framework. Until | 325 // type. |thread_to_start| is not used in this case. |
| 325 // this is fixed, we don't start the thread but still call | |
| 326 // Pre/PostStartThread for the ID. | |
| 327 break; | 326 break; |
| 328 case BrowserThread::FILE: | 327 case BrowserThread::FILE: |
| 329 thread_to_start = &file_thread_; | 328 thread_to_start = &file_thread_; |
| 330 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
| 331 // On Windows, the FILE thread needs to be have a UI message loop | 330 // On Windows, the FILE thread needs to be have a UI message loop |
| 332 // which pumps messages in such a way that Google Update can | 331 // which pumps messages in such a way that Google Update can |
| 333 // communicate back to us. | 332 // communicate back to us. |
| 334 options = &ui_message_loop_options; | 333 options = &ui_message_loop_options; |
| 335 #else | 334 #else |
| 336 options = &io_message_loop_options; | 335 options = &io_message_loop_options; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 358 default: | 357 default: |
| 359 NOTREACHED(); | 358 NOTREACHED(); |
| 360 break; | 359 break; |
| 361 } | 360 } |
| 362 | 361 |
| 363 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 362 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 364 | 363 |
| 365 if (parts_.get()) | 364 if (parts_.get()) |
| 366 parts_->PreStartThread(id); | 365 parts_->PreStartThread(id); |
| 367 | 366 |
| 368 if (thread_to_start) { | 367 if (thread_id == BrowserThread::WEBKIT) { |
| 368 webkit_thread_.reset(new WebKitThread); |
| 369 webkit_thread_->Initialize(); |
| 370 } else if (thread_to_start) { |
| 369 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 371 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
| 370 (*thread_to_start)->StartWithOptions(*options); | 372 (*thread_to_start)->StartWithOptions(*options); |
| 373 } else { |
| 374 NOTREACHED(); |
| 371 } | 375 } |
| 372 | 376 |
| 373 if (parts_.get()) | 377 if (parts_.get()) |
| 374 parts_->PostStartThread(id); | 378 parts_->PostStartThread(id); |
| 375 } | 379 } |
| 376 | 380 |
| 377 if (parts_.get()) | 381 if (parts_.get()) |
| 378 parts_->PreMainMessageLoopRun(); | 382 parts_->PreMainMessageLoopRun(); |
| 379 | 383 |
| 380 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 384 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 // the embedder to stop, by destroying ResourceDispatcherHost | 440 // the embedder to stop, by destroying ResourceDispatcherHost |
| 437 // before the DB thread is stopped) | 441 // before the DB thread is stopped) |
| 438 // | 442 // |
| 439 // - (Not sure why DB stops last.) | 443 // - (Not sure why DB stops last.) |
| 440 scoped_ptr<BrowserProcessSubThread>* thread_to_stop = NULL; | 444 scoped_ptr<BrowserProcessSubThread>* thread_to_stop = NULL; |
| 441 switch (thread_id) { | 445 switch (thread_id) { |
| 442 case BrowserThread::DB: | 446 case BrowserThread::DB: |
| 443 thread_to_stop = &db_thread_; | 447 thread_to_stop = &db_thread_; |
| 444 break; | 448 break; |
| 445 case BrowserThread::WEBKIT: | 449 case BrowserThread::WEBKIT: |
| 446 // For now, the WebKit thread in the browser is owned by | 450 // Special case as WebKitThread is a separate |
| 447 // ResourceDispatcherHost, not by the content framework. Until | 451 // type. |thread_to_stop| is not used in this case. |
| 448 // this is fixed, we don't stop the thread but still call | |
| 449 // Pre/PostStopThread for the ID. | |
| 450 break; | 452 break; |
| 451 case BrowserThread::FILE: | 453 case BrowserThread::FILE: |
| 452 thread_to_stop = &file_thread_; | 454 thread_to_stop = &file_thread_; |
| 453 break; | 455 break; |
| 454 case BrowserThread::PROCESS_LAUNCHER: | 456 case BrowserThread::PROCESS_LAUNCHER: |
| 455 thread_to_stop = &process_launcher_thread_; | 457 thread_to_stop = &process_launcher_thread_; |
| 456 break; | 458 break; |
| 457 case BrowserThread::CACHE: | 459 case BrowserThread::CACHE: |
| 458 thread_to_stop = &cache_thread_; | 460 thread_to_stop = &cache_thread_; |
| 459 break; | 461 break; |
| 460 case BrowserThread::IO: | 462 case BrowserThread::IO: |
| 461 thread_to_stop = &io_thread_; | 463 thread_to_stop = &io_thread_; |
| 462 break; | 464 break; |
| 463 #if defined(OS_CHROMEOS) | 465 #if defined(OS_CHROMEOS) |
| 464 case BrowserThread::WEB_SOCKET_PROXY: | 466 case BrowserThread::WEB_SOCKET_PROXY: |
| 465 thread_to_stop = &web_socket_proxy_thread_; | 467 thread_to_stop = &web_socket_proxy_thread_; |
| 466 break; | 468 break; |
| 467 #endif | 469 #endif |
| 468 case BrowserThread::UI: | 470 case BrowserThread::UI: |
| 469 case BrowserThread::ID_COUNT: | 471 case BrowserThread::ID_COUNT: |
| 470 default: | 472 default: |
| 471 NOTREACHED(); | 473 NOTREACHED(); |
| 472 break; | 474 break; |
| 473 } | 475 } |
| 474 | 476 |
| 475 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 477 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
| 476 | 478 |
| 477 if (parts_.get()) | 479 if (parts_.get()) |
| 478 parts_->PreStopThread(id); | 480 parts_->PreStopThread(id); |
| 479 if (thread_to_stop) | 481 |
| 482 if (id == BrowserThread::WEBKIT) { |
| 483 webkit_thread_.reset(); |
| 484 } else if (thread_to_stop) { |
| 480 thread_to_stop->reset(); | 485 thread_to_stop->reset(); |
| 486 } else { |
| 487 NOTREACHED(); |
| 488 } |
| 489 |
| 481 if (parts_.get()) | 490 if (parts_.get()) |
| 482 parts_->PostStopThread(id); | 491 parts_->PostStopThread(id); |
| 483 } | 492 } |
| 484 | 493 |
| 485 if (parts_.get()) | 494 if (parts_.get()) |
| 486 parts_->PostDestroyThreads(); | 495 parts_->PostDestroyThreads(); |
| 487 } | 496 } |
| 488 | 497 |
| 489 void BrowserMainLoop::InitializeMainThread() { | 498 void BrowserMainLoop::InitializeMainThread() { |
| 490 const char* kThreadName = "CrBrowserMain"; | 499 const char* kThreadName = "CrBrowserMain"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); | 550 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); |
| 542 | 551 |
| 543 #if defined(OS_MACOSX) | 552 #if defined(OS_MACOSX) |
| 544 MessageLoopForUI::current()->Run(); | 553 MessageLoopForUI::current()->Run(); |
| 545 #else | 554 #else |
| 546 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 555 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
| 547 #endif | 556 #endif |
| 548 } | 557 } |
| 549 | 558 |
| 550 } // namespace content | 559 } // namespace content |
| OLD | NEW |