summaryrefslogtreecommitdiffstats
path: root/content/browser/browser_main_loop.cc
diff options
context:
space:
mode:
authoraberent@chromium.org <aberent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-27 15:29:56 +0000
committeraberent@chromium.org <aberent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-27 15:29:56 +0000
commit232e09d18fa339b9dcb49f30d2e919fe673da1c5 (patch)
treed1a7e8698c6a7fab8f3f7925a81760f18504d5f7 /content/browser/browser_main_loop.cc
parentdc0fd43f60f29a9167f90cf1559ce1adc17d9969 (diff)
downloadchromium_src-232e09d18fa339b9dcb49f30d2e919fe673da1c5.zip
chromium_src-232e09d18fa339b9dcb49f30d2e919fe673da1c5.tar.gz
chromium_src-232e09d18fa339b9dcb49f30d2e919fe673da1c5.tar.bz2
Allow overlapping sync and async startup requests
On Android we can get a second request to start the browser while the an asynchronous request is in progress. Since the second request may be synchronous, we may have switch to completing initialization synchronously. This patch handles this by tracking which initialization tasks have been run, and running the remaining initialization tasks. BUG=260574 Review URL: https://chromiumcodereview.appspot.com/22691002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/browser_main_loop.cc')
-rw-r--r--content/browser/browser_main_loop.cc61
1 files changed, 39 insertions, 22 deletions
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 8bf6503..87bec3d 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() {