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/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 startup_task_runner_->RunAllTasksNow(); | 591 startup_task_runner_->RunAllTasksNow(); |
592 } | 592 } |
593 #else | 593 #else |
594 startup_task_runner_->RunAllTasksNow(); | 594 startup_task_runner_->RunAllTasksNow(); |
595 #endif | 595 #endif |
596 } | 596 } |
597 | 597 |
598 int BrowserMainLoop::CreateThreads() { | 598 int BrowserMainLoop::CreateThreads() { |
599 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); | 599 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); |
600 | 600 |
601 base::Thread::Options default_options; | |
602 base::Thread::Options io_message_loop_options; | 601 base::Thread::Options io_message_loop_options; |
603 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 602 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
604 base::Thread::Options ui_message_loop_options; | 603 base::Thread::Options ui_message_loop_options; |
605 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 604 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
606 | 605 |
607 // Start threads in the order they occur in the BrowserThread::ID | 606 // Start threads in the order they occur in the BrowserThread::ID |
608 // enumeration, except for BrowserThread::UI which is the main | 607 // enumeration, except for BrowserThread::UI which is the main |
609 // thread. | 608 // thread. |
610 // | 609 // |
611 // Must be size_t so we can increment it. | 610 // Must be size_t so we can increment it. |
612 for (size_t thread_id = BrowserThread::UI + 1; | 611 for (size_t thread_id = BrowserThread::UI + 1; |
613 thread_id < BrowserThread::ID_COUNT; | 612 thread_id < BrowserThread::ID_COUNT; |
614 ++thread_id) { | 613 ++thread_id) { |
615 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; | 614 scoped_ptr<BrowserProcessSubThread>* thread_to_start = NULL; |
616 base::Thread::Options* options = &default_options; | 615 base::Thread::Options options; |
617 | 616 |
618 switch (thread_id) { | 617 switch (thread_id) { |
619 case BrowserThread::DB: | 618 case BrowserThread::DB: |
620 TRACE_EVENT_BEGIN1("startup", | 619 TRACE_EVENT_BEGIN1("startup", |
621 "BrowserMainLoop::CreateThreads:start", | 620 "BrowserMainLoop::CreateThreads:start", |
622 "Thread", "BrowserThread::DB"); | 621 "Thread", "BrowserThread::DB"); |
623 thread_to_start = &db_thread_; | 622 thread_to_start = &db_thread_; |
| 623 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
624 break; | 624 break; |
625 case BrowserThread::FILE_USER_BLOCKING: | 625 case BrowserThread::FILE_USER_BLOCKING: |
626 TRACE_EVENT_BEGIN1("startup", | 626 TRACE_EVENT_BEGIN1("startup", |
627 "BrowserMainLoop::CreateThreads:start", | 627 "BrowserMainLoop::CreateThreads:start", |
628 "Thread", "BrowserThread::FILE_USER_BLOCKING"); | 628 "Thread", "BrowserThread::FILE_USER_BLOCKING"); |
629 thread_to_start = &file_user_blocking_thread_; | 629 thread_to_start = &file_user_blocking_thread_; |
630 break; | 630 break; |
631 case BrowserThread::FILE: | 631 case BrowserThread::FILE: |
632 TRACE_EVENT_BEGIN1("startup", | 632 TRACE_EVENT_BEGIN1("startup", |
633 "BrowserMainLoop::CreateThreads:start", | 633 "BrowserMainLoop::CreateThreads:start", |
634 "Thread", "BrowserThread::FILE"); | 634 "Thread", "BrowserThread::FILE"); |
635 thread_to_start = &file_thread_; | 635 thread_to_start = &file_thread_; |
636 #if defined(OS_WIN) | 636 #if defined(OS_WIN) |
637 // On Windows, the FILE thread needs to be have a UI message loop | 637 // On Windows, the FILE thread needs to be have a UI message loop |
638 // which pumps messages in such a way that Google Update can | 638 // which pumps messages in such a way that Google Update can |
639 // communicate back to us. | 639 // communicate back to us. |
640 options = &ui_message_loop_options; | 640 options = ui_message_loop_options; |
641 #else | 641 #else |
642 options = &io_message_loop_options; | 642 options = io_message_loop_options; |
643 #endif | 643 #endif |
| 644 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
644 break; | 645 break; |
645 case BrowserThread::PROCESS_LAUNCHER: | 646 case BrowserThread::PROCESS_LAUNCHER: |
646 TRACE_EVENT_BEGIN1("startup", | 647 TRACE_EVENT_BEGIN1("startup", |
647 "BrowserMainLoop::CreateThreads:start", | 648 "BrowserMainLoop::CreateThreads:start", |
648 "Thread", "BrowserThread::PROCESS_LAUNCHER"); | 649 "Thread", "BrowserThread::PROCESS_LAUNCHER"); |
649 thread_to_start = &process_launcher_thread_; | 650 thread_to_start = &process_launcher_thread_; |
| 651 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
650 break; | 652 break; |
651 case BrowserThread::CACHE: | 653 case BrowserThread::CACHE: |
652 TRACE_EVENT_BEGIN1("startup", | 654 TRACE_EVENT_BEGIN1("startup", |
653 "BrowserMainLoop::CreateThreads:start", | 655 "BrowserMainLoop::CreateThreads:start", |
654 "Thread", "BrowserThread::CACHE"); | 656 "Thread", "BrowserThread::CACHE"); |
655 thread_to_start = &cache_thread_; | 657 thread_to_start = &cache_thread_; |
656 options = &io_message_loop_options; | 658 options = io_message_loop_options; |
| 659 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
657 break; | 660 break; |
658 case BrowserThread::IO: | 661 case BrowserThread::IO: |
659 TRACE_EVENT_BEGIN1("startup", | 662 TRACE_EVENT_BEGIN1("startup", |
660 "BrowserMainLoop::CreateThreads:start", | 663 "BrowserMainLoop::CreateThreads:start", |
661 "Thread", "BrowserThread::IO"); | 664 "Thread", "BrowserThread::IO"); |
662 thread_to_start = &io_thread_; | 665 thread_to_start = &io_thread_; |
663 options = &io_message_loop_options; | 666 options = io_message_loop_options; |
664 break; | 667 break; |
665 case BrowserThread::UI: | 668 case BrowserThread::UI: |
666 case BrowserThread::ID_COUNT: | 669 case BrowserThread::ID_COUNT: |
667 default: | 670 default: |
668 NOTREACHED(); | 671 NOTREACHED(); |
669 break; | 672 break; |
670 } | 673 } |
671 | 674 |
672 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); | 675 BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); |
673 | 676 |
674 if (thread_to_start) { | 677 if (thread_to_start) { |
675 (*thread_to_start).reset(new BrowserProcessSubThread(id)); | 678 (*thread_to_start).reset(new BrowserProcessSubThread(id)); |
676 (*thread_to_start)->StartWithOptions(*options); | 679 (*thread_to_start)->StartWithOptions(options); |
677 } else { | 680 } else { |
678 NOTREACHED(); | 681 NOTREACHED(); |
679 } | 682 } |
680 | 683 |
681 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); | 684 TRACE_EVENT_END0("startup", "BrowserMainLoop::CreateThreads:start"); |
682 } | 685 } |
683 created_threads_ = true; | 686 created_threads_ = true; |
684 return result_code_; | 687 return result_code_; |
685 } | 688 } |
686 | 689 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 base::TimeDelta::FromSeconds(delay_secs)); | 1143 base::TimeDelta::FromSeconds(delay_secs)); |
1141 } | 1144 } |
1142 | 1145 |
1143 void BrowserMainLoop::EndStartupTracing(const base::FilePath& trace_file) { | 1146 void BrowserMainLoop::EndStartupTracing(const base::FilePath& trace_file) { |
1144 is_tracing_startup_ = false; | 1147 is_tracing_startup_ = false; |
1145 TracingController::GetInstance()->DisableRecording( | 1148 TracingController::GetInstance()->DisableRecording( |
1146 trace_file, base::Bind(&OnStoppedStartupTracing)); | 1149 trace_file, base::Bind(&OnStoppedStartupTracing)); |
1147 } | 1150 } |
1148 | 1151 |
1149 } // namespace content | 1152 } // namespace content |
OLD | NEW |