Chromium Code Reviews| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) | 520 #if !defined(OS_IOS) && (!defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)) |
| 521 // Single-process is an unsupported and not fully tested mode, so | 521 // Single-process is an unsupported and not fully tested mode, so |
| 522 // don't enable it for official Chrome builds (except on Android). | 522 // don't enable it for official Chrome builds (except on Android). |
| 523 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) | 523 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
| 524 RenderProcessHost::SetRunRendererInProcess(true); | 524 RenderProcessHost::SetRunRendererInProcess(true); |
| 525 #endif | 525 #endif |
| 526 return result_code_; | 526 return result_code_; |
| 527 } | 527 } |
| 528 | 528 |
| 529 void BrowserMainLoop::CreateStartupTasks() { | 529 void BrowserMainLoop::CreateStartupTasks() { |
| 530 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks") | 530 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); |
| 531 | |
| 532 // First time through, we really want to create all the tasks | |
| 533 if (!startup_task_runner_.get()) { | |
| 534 #if defined(OS_ANDROID) | |
| 535 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | |
| 536 base::Bind(&BrowserStartupComplete), | |
| 537 base::MessageLoop::current()->message_loop_proxy())); | |
| 538 #else | |
| 539 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | |
| 540 base::Callback<void(int)>(), | |
| 541 base::MessageLoop::current()->message_loop_proxy())); | |
| 542 #endif | |
| 543 StartupTask pre_create_threads = | |
| 544 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); | |
| 545 startup_task_runner_->AddTask(pre_create_threads); | |
| 546 | |
| 547 StartupTask create_threads = | |
| 548 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); | |
| 549 startup_task_runner_->AddTask(create_threads); | |
| 550 | |
| 551 StartupTask browser_thread_started = base::Bind( | |
| 552 &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); | |
| 553 startup_task_runner_->AddTask(browser_thread_started); | |
| 554 | |
| 555 StartupTask pre_main_message_loop_run = base::Bind( | |
| 556 &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); | |
| 557 startup_task_runner_->AddTask(pre_main_message_loop_run); | |
| 531 | 558 |
| 532 #if defined(OS_ANDROID) | 559 #if defined(OS_ANDROID) |
| 533 scoped_refptr<StartupTaskRunner> task_runner = | 560 if (BrowserMayStartAsynchronously()) { |
| 534 new StartupTaskRunner(BrowserMayStartAsynchronously(), | 561 startup_task_runner_->StartRunningTasksAsync(); |
| 535 base::Bind(&BrowserStartupComplete), | 562 } |
| 536 base::MessageLoop::current()->message_loop_proxy()); | 563 #endif |
| 564 } | |
| 565 #if defined(OS_ANDROID) | |
| 566 if (!BrowserMayStartAsynchronously()) { | |
| 567 // A second request for asynchronous startup can be ignored, so | |
| 568 // StartupRunningTasksAsync is only called first time through. If, however, | |
| 569 // this is a request for synchronous startup then it must override any | |
| 570 // previous call for async startup, so we call RunAllTasksNow() | |
| 571 // unconditionally. | |
| 572 startup_task_runner_->RunAllTasksNow(); | |
| 573 } | |
| 537 #else | 574 #else |
| 538 scoped_refptr<StartupTaskRunner> task_runner = | 575 startup_task_runner_->RunAllTasksNow(); |
| 539 new StartupTaskRunner(false, | |
| 540 base::Callback<void(int)>(), | |
| 541 base::MessageLoop::current()->message_loop_proxy()); | |
| 542 #endif | 576 #endif |
| 543 StartupTask pre_create_threads = | |
| 544 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); | |
| 545 task_runner->AddTask(pre_create_threads); | |
| 546 | |
| 547 StartupTask create_threads = | |
| 548 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); | |
| 549 task_runner->AddTask(create_threads); | |
| 550 | |
| 551 StartupTask browser_thread_started = base::Bind( | |
| 552 &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); | |
| 553 task_runner->AddTask(browser_thread_started); | |
| 554 | |
| 555 StartupTask pre_main_message_loop_run = base::Bind( | |
| 556 &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); | |
| 557 task_runner->AddTask(pre_main_message_loop_run); | |
| 558 | |
| 559 task_runner->StartRunningTasks(); | |
| 560 } | 577 } |
| 561 | 578 |
| 562 int BrowserMainLoop::CreateThreads() { | 579 int BrowserMainLoop::CreateThreads() { |
| 563 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); | 580 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads"); |
| 564 | 581 |
| 565 base::Thread::Options default_options; | 582 base::Thread::Options default_options; |
| 566 base::Thread::Options io_message_loop_options; | 583 base::Thread::Options io_message_loop_options; |
| 567 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 584 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 568 base::Thread::Options ui_message_loop_options; | 585 base::Thread::Options ui_message_loop_options; |
| 569 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 586 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 } | 891 } |
| 875 | 892 |
| 876 { | 893 { |
| 877 TRACE_EVENT0( | 894 TRACE_EVENT0( |
| 878 "startup", | 895 "startup", |
| 879 "BrowserMainLoop::BrowserThreadsStarted::InitUserInputMonitor"); | 896 "BrowserMainLoop::BrowserThreadsStarted::InitUserInputMonitor"); |
| 880 user_input_monitor_ = media::UserInputMonitor::Create( | 897 user_input_monitor_ = media::UserInputMonitor::Create( |
| 881 io_thread_->message_loop_proxy(), main_thread_->message_loop_proxy()); | 898 io_thread_->message_loop_proxy(), main_thread_->message_loop_proxy()); |
| 882 } | 899 } |
| 883 | 900 |
| 884 // Alert the clipboard class to which threads are allowed to access the | 901 // Alert the clipboard class to which threads are allowed to access the |
|
Yaron
2013/08/22 06:00:26
Nit: indentation
aberent
2013/08/23 11:40:21
Done.
| |
| 885 // clipboard: | 902 // clipboard: |
| 886 std::vector<base::PlatformThreadId> allowed_clipboard_threads; | 903 std::vector<base::PlatformThreadId> allowed_clipboard_threads; |
| 887 // The current thread is the UI thread. | 904 // The current thread is the UI thread. |
| 888 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); | 905 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); |
| 889 #if defined(OS_WIN) | 906 #if defined(OS_WIN) |
| 890 // On Windows, clipboards are also used on the File or IO threads. | 907 // On Windows, clipboards are also used on the File or IO threads. |
| 891 allowed_clipboard_threads.push_back(file_thread_->thread_id()); | 908 allowed_clipboard_threads.push_back(file_thread_->thread_id()); |
| 892 allowed_clipboard_threads.push_back(io_thread_->thread_id()); | 909 allowed_clipboard_threads.push_back(io_thread_->thread_id()); |
| 893 #endif | 910 #endif |
| 894 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); | 911 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); |
| 895 | 912 |
| 896 // When running the GPU thread in-process, avoid optimistically starting it | 913 // When running the GPU thread in-process, avoid optimistically starting it |
| 897 // since creating the GPU thread races against creation of the one-and-only | 914 // since creating the GPU thread races against creation of the one-and-only |
| 898 // ChildProcess instance which is created by the renderer thread. | 915 // ChildProcess instance which is created by the renderer thread. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 if (parameters_.ui_task) | 990 if (parameters_.ui_task) |
| 974 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 991 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
| 975 *parameters_.ui_task); | 992 *parameters_.ui_task); |
| 976 | 993 |
| 977 base::RunLoop run_loop; | 994 base::RunLoop run_loop; |
| 978 run_loop.Run(); | 995 run_loop.Run(); |
| 979 #endif | 996 #endif |
| 980 } | 997 } |
| 981 | 998 |
| 982 } // namespace content | 999 } // namespace content |
| OLD | NEW |