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" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 options = &io_message_loop_options; | 336 options = &io_message_loop_options; |
337 #endif | 337 #endif |
338 break; | 338 break; |
339 case BrowserThread::PROCESS_LAUNCHER: | 339 case BrowserThread::PROCESS_LAUNCHER: |
340 thread_to_start = &process_launcher_thread_; | 340 thread_to_start = &process_launcher_thread_; |
341 break; | 341 break; |
342 case BrowserThread::CACHE: | 342 case BrowserThread::CACHE: |
343 thread_to_start = &cache_thread_; | 343 thread_to_start = &cache_thread_; |
344 options = &io_message_loop_options; | 344 options = &io_message_loop_options; |
345 break; | 345 break; |
| 346 case BrowserThread::JAVA_BRIDGE: |
| 347 #if defined(ENABLE_JAVA_BRIDGE) |
| 348 thread_to_start = &java_bridge_thread_; |
| 349 #endif |
| 350 break; |
346 case BrowserThread::IO: | 351 case BrowserThread::IO: |
347 thread_to_start = &io_thread_; | 352 thread_to_start = &io_thread_; |
348 options = &io_message_loop_options; | 353 options = &io_message_loop_options; |
349 break; | 354 break; |
350 #if defined(OS_CHROMEOS) | 355 #if defined(OS_CHROMEOS) |
351 case BrowserThread::WEB_SOCKET_PROXY: | 356 case BrowserThread::WEB_SOCKET_PROXY: |
352 thread_to_start = &web_socket_proxy_thread_; | 357 thread_to_start = &web_socket_proxy_thread_; |
353 options = &io_message_loop_options; | 358 options = &io_message_loop_options; |
354 break; | 359 break; |
355 #endif | 360 #endif |
356 case BrowserThread::UI: | 361 case BrowserThread::UI: |
357 case BrowserThread::ID_COUNT: | 362 case BrowserThread::ID_COUNT: |
358 default: | 363 default: |
359 NOTREACHED(); | 364 NOTREACHED(); |
360 break; | 365 break; |
361 } | 366 } |
362 | 367 |
363 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 368 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
364 | 369 |
365 if (parts_.get()) | 370 if (parts_.get()) |
366 parts_->PreStartThread(id); | 371 parts_->PreStartThread(id); |
367 | 372 |
368 if (thread_id == BrowserThread::WEBKIT) { | 373 if (thread_id == BrowserThread::WEBKIT) { |
369 webkit_thread_.reset(new WebKitThread); | 374 webkit_thread_.reset(new WebKitThread); |
370 webkit_thread_->Initialize(); | 375 webkit_thread_->Initialize(); |
371 } else if (thread_to_start) { | 376 } else if (thread_to_start) { |
372 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 377 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
373 (*thread_to_start)->StartWithOptions(*options); | 378 (*thread_to_start)->StartWithOptions(*options); |
374 } else { | |
375 NOTREACHED(); | |
376 } | 379 } |
377 | 380 |
378 if (parts_.get()) | 381 if (parts_.get()) |
379 parts_->PostStartThread(id); | 382 parts_->PostStartThread(id); |
380 } | 383 } |
381 | 384 |
382 if (parts_.get()) | 385 if (parts_.get()) |
383 parts_->PreMainMessageLoopRun(); | 386 parts_->PreMainMessageLoopRun(); |
384 | 387 |
385 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 388 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // BrowserThread IDs and DCHECKing on a missing case in the switch | 425 // BrowserThread IDs and DCHECKing on a missing case in the switch |
423 // statement helps avoid a mismatch between this code and the | 426 // statement helps avoid a mismatch between this code and the |
424 // BrowserThread::ID enumeration. | 427 // BrowserThread::ID enumeration. |
425 // | 428 // |
426 // The destruction order is the reverse order of occurrence in the | 429 // The destruction order is the reverse order of occurrence in the |
427 // BrowserThread::ID list. The rationale for the order is as | 430 // BrowserThread::ID list. The rationale for the order is as |
428 // follows (need to be filled in a bit): | 431 // follows (need to be filled in a bit): |
429 // | 432 // |
430 // - (Not sure why the WEB_SOCKET_PROXY thread is stopped first.) | 433 // - (Not sure why the WEB_SOCKET_PROXY thread is stopped first.) |
431 // | 434 // |
| 435 // - The JAVA_BRIDGE thread receives messages from the UI thread, and posts |
| 436 // messages to and receives messages from the IO thread. Of the |
| 437 // interactions with the IO thread, receiving messages is more common, so |
| 438 // make sure this thread outlives the IO thread to take advantage of the |
| 439 // optimization in BrowserThread. |
| 440 // |
432 // - The IO thread is the only user of the CACHE thread. | 441 // - The IO thread is the only user of the CACHE thread. |
433 // | 442 // |
434 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | 443 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
435 // the IO thread posted a task to terminate a process on the | 444 // the IO thread posted a task to terminate a process on the |
436 // process launcher thread. | 445 // process launcher thread. |
437 // | 446 // |
438 // - (Not sure why FILE needs to stop before WEBKIT.) | 447 // - (Not sure why FILE needs to stop before WEBKIT.) |
439 // | 448 // |
440 // - The WEBKIT thread (which currently is the responsibility of | 449 // - The WEBKIT thread (which currently is the responsibility of |
441 // the embedder to stop, by destroying ResourceDispatcherHost | 450 // the embedder to stop, by destroying ResourceDispatcherHost |
(...skipping 14 matching lines...) Expand all Loading... |
456 break; | 465 break; |
457 case BrowserThread::FILE: | 466 case BrowserThread::FILE: |
458 thread_to_stop = &file_thread_; | 467 thread_to_stop = &file_thread_; |
459 break; | 468 break; |
460 case BrowserThread::PROCESS_LAUNCHER: | 469 case BrowserThread::PROCESS_LAUNCHER: |
461 thread_to_stop = &process_launcher_thread_; | 470 thread_to_stop = &process_launcher_thread_; |
462 break; | 471 break; |
463 case BrowserThread::CACHE: | 472 case BrowserThread::CACHE: |
464 thread_to_stop = &cache_thread_; | 473 thread_to_stop = &cache_thread_; |
465 break; | 474 break; |
| 475 case BrowserThread::JAVA_BRIDGE: |
| 476 #if defined(ENABLE_JAVA_BRIDGE) |
| 477 thread_to_stop = &java_bridge_thread_; |
| 478 #endif |
| 479 break; |
466 case BrowserThread::IO: | 480 case BrowserThread::IO: |
467 thread_to_stop = &io_thread_; | 481 thread_to_stop = &io_thread_; |
468 break; | 482 break; |
469 #if defined(OS_CHROMEOS) | 483 #if defined(OS_CHROMEOS) |
470 case BrowserThread::WEB_SOCKET_PROXY: | 484 case BrowserThread::WEB_SOCKET_PROXY: |
471 thread_to_stop = &web_socket_proxy_thread_; | 485 thread_to_stop = &web_socket_proxy_thread_; |
472 break; | 486 break; |
473 #endif | 487 #endif |
474 case BrowserThread::UI: | 488 case BrowserThread::UI: |
475 case BrowserThread::ID_COUNT: | 489 case BrowserThread::ID_COUNT: |
476 default: | 490 default: |
477 NOTREACHED(); | 491 NOTREACHED(); |
478 break; | 492 break; |
479 } | 493 } |
480 | 494 |
481 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 495 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
482 | 496 |
483 if (parts_.get()) | 497 if (parts_.get()) |
484 parts_->PreStopThread(id); | 498 parts_->PreStopThread(id); |
485 | 499 |
486 if (id == BrowserThread::WEBKIT) { | 500 if (id == BrowserThread::WEBKIT) { |
487 webkit_thread_.reset(); | 501 webkit_thread_.reset(); |
488 } else if (thread_to_stop) { | 502 } else if (thread_to_stop) { |
489 thread_to_stop->reset(); | 503 thread_to_stop->reset(); |
490 } else { | |
491 NOTREACHED(); | |
492 } | 504 } |
493 | 505 |
494 if (parts_.get()) | 506 if (parts_.get()) |
495 parts_->PostStopThread(id); | 507 parts_->PostStopThread(id); |
496 } | 508 } |
497 | 509 |
498 if (parts_.get()) | 510 if (parts_.get()) |
499 parts_->PostDestroyThreads(); | 511 parts_->PostDestroyThreads(); |
500 } | 512 } |
501 | 513 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); | 566 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); |
555 | 567 |
556 #if defined(OS_MACOSX) | 568 #if defined(OS_MACOSX) |
557 MessageLoopForUI::current()->Run(); | 569 MessageLoopForUI::current()->Run(); |
558 #else | 570 #else |
559 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 571 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
560 #endif | 572 #endif |
561 } | 573 } |
562 | 574 |
563 } // namespace content | 575 } // namespace content |
OLD | NEW |