Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: gin/shell/gin_main.cc

Issue 2877963002: Initialize TaskScheduler in gin_main.cc. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/task_scheduler/task_scheduler.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "gin/array_buffer.h" 19 #include "gin/array_buffer.h"
19 #include "gin/modules/console.h" 20 #include "gin/modules/console.h"
20 #include "gin/modules/module_runner_delegate.h" 21 #include "gin/modules/module_runner_delegate.h"
21 #include "gin/public/isolate_holder.h" 22 #include "gin/public/isolate_holder.h"
22 #include "gin/try_catch.h" 23 #include "gin/try_catch.h"
23 #include "gin/v8_initializer.h" 24 #include "gin/v8_initializer.h"
24 25
25 namespace gin { 26 namespace gin {
26 namespace { 27 namespace {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 int main(int argc, char** argv) { 67 int main(int argc, char** argv) {
67 base::AtExitManager at_exit; 68 base::AtExitManager at_exit;
68 base::CommandLine::Init(argc, argv); 69 base::CommandLine::Init(argc, argv);
69 base::i18n::InitializeICU(); 70 base::i18n::InitializeICU();
70 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 71 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
71 gin::V8Initializer::LoadV8Snapshot(); 72 gin::V8Initializer::LoadV8Snapshot();
72 gin::V8Initializer::LoadV8Natives(); 73 gin::V8Initializer::LoadV8Natives();
73 #endif 74 #endif
74 75
75 base::MessageLoop message_loop; 76 base::MessageLoop message_loop;
77 base::TaskScheduler::CreateAndStartWithDefaultParams("gin");
76 78
77 // Initialize the base::FeatureList since IsolateHolder can depend on it. 79 // Initialize the base::FeatureList since IsolateHolder can depend on it.
78 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList)); 80 base::FeatureList::SetInstance(base::WrapUnique(new base::FeatureList));
79 81
80 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, 82 {
81 gin::IsolateHolder::kStableV8Extras, 83 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
82 gin::ArrayBufferAllocator::SharedInstance()); 84 gin::IsolateHolder::kStableV8Extras,
83 gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); 85 gin::ArrayBufferAllocator::SharedInstance());
86 gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get());
84 87
85 gin::GinShellRunnerDelegate delegate; 88 gin::GinShellRunnerDelegate delegate;
86 gin::ShellRunner runner(&delegate, instance.isolate()); 89 gin::ShellRunner runner(&delegate, instance.isolate());
87 90
88 { 91 {
89 gin::Runner::Scope scope(&runner); 92 gin::Runner::Scope scope(&runner);
90 runner.GetContextHolder() 93 runner.GetContextHolder()
91 ->isolate() 94 ->isolate()
92 ->SetCaptureStackTraceForUncaughtExceptions(true); 95 ->SetCaptureStackTraceForUncaughtExceptions(true);
96 }
97
98 base::CommandLine::StringVector args =
99 base::CommandLine::ForCurrentProcess()->GetArgs();
100 for (base::CommandLine::StringVector::const_iterator it = args.begin();
101 it != args.end(); ++it) {
102 base::ThreadTaskRunnerHandle::Get()->PostTask(
103 FROM_HERE,
104 base::Bind(gin::Run, runner.GetWeakPtr(), base::FilePath(*it)));
105 }
106
107 base::RunLoop().RunUntilIdle();
93 } 108 }
94 109
95 base::CommandLine::StringVector args = 110 // gin::IsolateHolder waits for tasks running in TaskScheduler in its
96 base::CommandLine::ForCurrentProcess()->GetArgs(); 111 // destructor and thus must be destroyed before TaskScheduler starts skipping
97 for (base::CommandLine::StringVector::const_iterator it = args.begin(); 112 // CONTINUE_ON_SHUTDOWN tasks.
98 it != args.end(); ++it) { 113 base::TaskScheduler::GetInstance()->Shutdown();
99 base::ThreadTaskRunnerHandle::Get()->PostTask(
100 FROM_HERE,
101 base::Bind(gin::Run, runner.GetWeakPtr(), base::FilePath(*it)));
102 }
103 114
104 base::RunLoop().RunUntilIdle();
105 return 0; 115 return 0;
106 } 116 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698