Chromium Code Reviews| Index: content/browser/browser_main_loop.cc |
| diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc |
| index 8bde5f271e923f131213bf0ca34c6e9359d0737f..043f1d58c2f97e5eacc48ed8c19e3a93001936d6 100644 |
| --- a/content/browser/browser_main_loop.cc |
| +++ b/content/browser/browser_main_loop.cc |
| @@ -527,36 +527,53 @@ int BrowserMainLoop::PreCreateThreads() { |
| } |
| void BrowserMainLoop::CreateStartupTasks() { |
| - TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks") |
| + TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); |
| + // First time through, we really want to create all the tasks |
| + if (!startup_task_runner_.get()) { |
| #if defined(OS_ANDROID) |
| - scoped_refptr<StartupTaskRunner> task_runner = |
| - new StartupTaskRunner(BrowserMayStartAsynchronously(), |
| - base::Bind(&BrowserStartupComplete), |
| - base::MessageLoop::current()->message_loop_proxy()); |
| + startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( |
| + base::Bind(&BrowserStartupComplete), |
| + base::MessageLoop::current()->message_loop_proxy())); |
| #else |
| - scoped_refptr<StartupTaskRunner> task_runner = |
| - new StartupTaskRunner(false, |
| - base::Callback<void(int)>(), |
| - base::MessageLoop::current()->message_loop_proxy()); |
| + startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( |
| + base::Callback<void(int)>(), |
| + base::MessageLoop::current()->message_loop_proxy())); |
| #endif |
| - StartupTask pre_create_threads = |
| - base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); |
| - task_runner->AddTask(pre_create_threads); |
| + StartupTask pre_create_threads = |
| + base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); |
| + startup_task_runner_->AddTask(pre_create_threads); |
| - StartupTask create_threads = |
| - base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); |
| - task_runner->AddTask(create_threads); |
| + StartupTask create_threads = |
| + base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); |
| + startup_task_runner_->AddTask(create_threads); |
| - StartupTask browser_thread_started = base::Bind( |
| - &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); |
| - task_runner->AddTask(browser_thread_started); |
| + StartupTask browser_thread_started = base::Bind( |
| + &BrowserMainLoop::BrowserThreadsStarted, base::Unretained(this)); |
| + startup_task_runner_->AddTask(browser_thread_started); |
| - StartupTask pre_main_message_loop_run = base::Bind( |
| - &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); |
| - task_runner->AddTask(pre_main_message_loop_run); |
| + StartupTask pre_main_message_loop_run = base::Bind( |
| + &BrowserMainLoop::PreMainMessageLoopRun, base::Unretained(this)); |
| + startup_task_runner_->AddTask(pre_main_message_loop_run); |
| - task_runner->StartRunningTasks(); |
| +#if defined(OS_ANDROID) |
| + if (BrowserMayStartAsynchronously()) { |
| + startup_task_runner_->StartRunningTasksAsync(); |
| + } |
| +#endif |
| + } |
| +#if defined(OS_ANDROID) |
| + if (!BrowserMayStartAsynchronously()) { |
| + // A second request for asynchronous startup can be ignored, so |
| + // StartupRunningTasksAsync is only called first time through. If, however, |
| + // this is a request for synchronous startup then it must override any |
| + // previous call for async startup, so we call RunAllTasksNow() |
| + // unconditionally. |
| + startup_task_runner_->RunAllTasksNow(); |
| + } |
| +#else |
| + startup_task_runner_->RunAllTasksNow(); |
| +#endif |
| } |
| int BrowserMainLoop::CreateThreads() { |
| @@ -881,11 +898,11 @@ int BrowserMainLoop::BrowserThreadsStarted() { |
| io_thread_->message_loop_proxy(), main_thread_->message_loop_proxy()); |
| } |
| - // Alert the clipboard class to which threads are allowed to access the |
| - // clipboard: |
| - std::vector<base::PlatformThreadId> allowed_clipboard_threads; |
| - // The current thread is the UI thread. |
| - allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); |
| + // 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.
|
| + // clipboard: |
| + std::vector<base::PlatformThreadId> allowed_clipboard_threads; |
| + // The current thread is the UI thread. |
| + allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); |
| #if defined(OS_WIN) |
| // On Windows, clipboards are also used on the File or IO threads. |
| allowed_clipboard_threads.push_back(file_thread_->thread_id()); |