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

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 2857983003: Use constexpr TaskTraits constructor in content. (Closed)
Patch Set: CR gab #8 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 // thread will not be joined on shutdown, and may cause use-after-free if 1002 // thread will not be joined on shutdown, and may cause use-after-free if
1003 // anything tries to access objects deleted by AtExitManager, such as 1003 // anything tries to access objects deleted by AtExitManager, such as
1004 // non-leaky LazyInstance. 1004 // non-leaky LazyInstance.
1005 base::MessageLoop* message_loop = nullptr; 1005 base::MessageLoop* message_loop = nullptr;
1006 bool redirect_thread = redirect_nonUInonIO_browser_threads; 1006 bool redirect_thread = redirect_nonUInonIO_browser_threads;
1007 1007
1008 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using 1008 // Otherwise this thread ID will be backed by a SingleThreadTaskRunner using
1009 // |non_ui_non_io_task_runner_traits| (which can be augmented below). 1009 // |non_ui_non_io_task_runner_traits| (which can be augmented below).
1010 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so 1010 // TODO(gab): Existing non-UI/non-IO BrowserThreads allow sync primitives so
1011 // the initial redirection will as well but they probably don't need to. 1011 // the initial redirection will as well but they probably don't need to.
1012 base::TaskTraits non_ui_non_io_task_runner_traits = 1012 base::TaskTraits non_ui_non_io_task_runner_traits;
1013 base::TaskTraits().MayBlock().WithBaseSyncPrimitives(); 1013
1014 // Note: if you're copying these TaskTraits elsewhere, you most likely don't
1015 // need and shouldn't use base::WithBaseSyncPrimitives() -- see its
1016 // documentation.
1017 constexpr base::TaskTraits kUserVisibleTraits = {
1018 base::MayBlock(), base::WithBaseSyncPrimitives(),
1019 base::TaskPriority::USER_VISIBLE,
1020 base::TaskShutdownBehavior::BLOCK_SHUTDOWN};
1021 constexpr base::TaskTraits kUserBlockingTraits = {
1022 base::MayBlock(), base::WithBaseSyncPrimitives(),
1023 base::TaskPriority::USER_BLOCKING,
1024 base::TaskShutdownBehavior::BLOCK_SHUTDOWN};
1014 1025
1015 switch (thread_id) { 1026 switch (thread_id) {
1016 case BrowserThread::DB: 1027 case BrowserThread::DB:
1017 TRACE_EVENT_BEGIN1("startup", 1028 TRACE_EVENT_BEGIN1("startup",
1018 "BrowserMainLoop::CreateThreads:start", 1029 "BrowserMainLoop::CreateThreads:start",
1019 "Thread", "BrowserThread::DB"); 1030 "Thread", "BrowserThread::DB");
1020 if (redirect_thread) { 1031 if (redirect_thread) {
1021 non_ui_non_io_task_runner_traits 1032 non_ui_non_io_task_runner_traits = kUserVisibleTraits;
1022 .WithPriority(base::TaskPriority::USER_VISIBLE)
1023 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1024 } else { 1033 } else {
1025 thread_to_start = &db_thread_; 1034 thread_to_start = &db_thread_;
1026 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1035 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1027 } 1036 }
1028 break; 1037 break;
1029 case BrowserThread::FILE_USER_BLOCKING: 1038 case BrowserThread::FILE_USER_BLOCKING:
1030 TRACE_EVENT_BEGIN1("startup", 1039 TRACE_EVENT_BEGIN1("startup",
1031 "BrowserMainLoop::CreateThreads:start", 1040 "BrowserMainLoop::CreateThreads:start",
1032 "Thread", "BrowserThread::FILE_USER_BLOCKING"); 1041 "Thread", "BrowserThread::FILE_USER_BLOCKING");
1033 if (redirect_thread) { 1042 if (redirect_thread) {
1034 non_ui_non_io_task_runner_traits 1043 non_ui_non_io_task_runner_traits = kUserBlockingTraits;
1035 .WithPriority(base::TaskPriority::USER_BLOCKING)
1036 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1037 } else { 1044 } else {
1038 thread_to_start = &file_user_blocking_thread_; 1045 thread_to_start = &file_user_blocking_thread_;
1039 } 1046 }
1040 break; 1047 break;
1041 case BrowserThread::FILE: 1048 case BrowserThread::FILE:
1042 TRACE_EVENT_BEGIN1("startup", 1049 TRACE_EVENT_BEGIN1("startup",
1043 "BrowserMainLoop::CreateThreads:start", 1050 "BrowserMainLoop::CreateThreads:start",
1044 "Thread", "BrowserThread::FILE"); 1051 "Thread", "BrowserThread::FILE");
1045 1052
1046 #if defined(OS_WIN) 1053 #if defined(OS_WIN)
1047 // On Windows, the FILE thread needs to have a UI message loop which 1054 // On Windows, the FILE thread needs to have a UI message loop which
1048 // pumps messages in such a way that Google Update can communicate back 1055 // pumps messages in such a way that Google Update can communicate back
1049 // to us. 1056 // to us.
1050 // TODO(robliao): Need to support COM in TaskScheduler before 1057 // TODO(robliao): Need to support COM in TaskScheduler before
1051 // redirecting the FILE thread on Windows. http://crbug.com/662122 1058 // redirecting the FILE thread on Windows. http://crbug.com/662122
1052 thread_to_start = &file_thread_; 1059 thread_to_start = &file_thread_;
1053 options = ui_message_loop_options; 1060 options = ui_message_loop_options;
1054 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1061 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1055 #else 1062 #else
1056 if (redirect_thread) { 1063 if (redirect_thread) {
1057 non_ui_non_io_task_runner_traits 1064 non_ui_non_io_task_runner_traits = kUserVisibleTraits;
1058 .WithPriority(base::TaskPriority::USER_VISIBLE)
1059 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1060 } else { 1065 } else {
1061 thread_to_start = &file_thread_; 1066 thread_to_start = &file_thread_;
1062 options = io_message_loop_options; 1067 options = io_message_loop_options;
1063 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1068 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1064 } 1069 }
1065 #endif 1070 #endif
1066 break; 1071 break;
1067 case BrowserThread::PROCESS_LAUNCHER: 1072 case BrowserThread::PROCESS_LAUNCHER:
1068 TRACE_EVENT_BEGIN1("startup", 1073 TRACE_EVENT_BEGIN1("startup",
1069 "BrowserMainLoop::CreateThreads:start", 1074 "BrowserMainLoop::CreateThreads:start",
1070 "Thread", "BrowserThread::PROCESS_LAUNCHER"); 1075 "Thread", "BrowserThread::PROCESS_LAUNCHER");
1071 #if defined(OS_ANDROID) 1076 #if defined(OS_ANDROID)
1072 // Android specializes Launcher thread so it is accessible in java. 1077 // Android specializes Launcher thread so it is accessible in java.
1073 // Note Android never does clean shutdown, so shutdown use-after-free 1078 // Note Android never does clean shutdown, so shutdown use-after-free
1074 // concerns are not a problem in practice. 1079 // concerns are not a problem in practice.
1075 redirect_thread = false; 1080 redirect_thread = false;
1076 message_loop = android::LauncherThread::GetMessageLoop(); 1081 message_loop = android::LauncherThread::GetMessageLoop();
1077 DCHECK(message_loop); 1082 DCHECK(message_loop);
1078 #endif 1083 #endif
1079 if (redirect_thread) { 1084 if (redirect_thread) {
1080 non_ui_non_io_task_runner_traits 1085 non_ui_non_io_task_runner_traits = kUserBlockingTraits;
1081 .WithPriority(base::TaskPriority::USER_BLOCKING)
1082 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1083 } else { 1086 } else {
1084 thread_to_start = &process_launcher_thread_; 1087 thread_to_start = &process_launcher_thread_;
1085 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1088 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1086 } 1089 }
1087 break; 1090 break;
1088 case BrowserThread::CACHE: 1091 case BrowserThread::CACHE:
1089 TRACE_EVENT_BEGIN1("startup", 1092 TRACE_EVENT_BEGIN1("startup",
1090 "BrowserMainLoop::CreateThreads:start", 1093 "BrowserMainLoop::CreateThreads:start",
1091 "Thread", "BrowserThread::CACHE"); 1094 "Thread", "BrowserThread::CACHE");
1092 #if defined(OS_WIN) 1095 #if defined(OS_WIN)
1093 // TaskScheduler doesn't support async I/O on Windows as CACHE thread is 1096 // TaskScheduler doesn't support async I/O on Windows as CACHE thread is
1094 // the only user and this use case is going away in 1097 // the only user and this use case is going away in
1095 // https://codereview.chromium.org/2216583003/. 1098 // https://codereview.chromium.org/2216583003/.
1096 // TODO(gavinp): Remove this ifdef (and thus enable redirection of the 1099 // TODO(gavinp): Remove this ifdef (and thus enable redirection of the
1097 // CACHE thread on Windows) once that CL lands. 1100 // CACHE thread on Windows) once that CL lands.
1098 thread_to_start = &cache_thread_; 1101 thread_to_start = &cache_thread_;
1099 options = io_message_loop_options; 1102 options = io_message_loop_options;
1100 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1103 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1101 #else // OS_WIN 1104 #else // OS_WIN
1102 if (redirect_thread) { 1105 if (redirect_thread) {
1103 non_ui_non_io_task_runner_traits 1106 non_ui_non_io_task_runner_traits = kUserBlockingTraits;
1104 .WithPriority(base::TaskPriority::USER_BLOCKING)
1105 .WithShutdownBehavior(base::TaskShutdownBehavior::BLOCK_SHUTDOWN);
1106 } else { 1107 } else {
1107 thread_to_start = &cache_thread_; 1108 thread_to_start = &cache_thread_;
1108 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 1109 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1109 } 1110 }
1110 #endif // OS_WIN 1111 #endif // OS_WIN
1111 break; 1112 break;
1112 case BrowserThread::IO: 1113 case BrowserThread::IO:
1113 TRACE_EVENT_BEGIN1("startup", 1114 TRACE_EVENT_BEGIN1("startup",
1114 "BrowserMainLoop::CreateThreads:start", 1115 "BrowserMainLoop::CreateThreads:start",
1115 "Thread", "BrowserThread::IO"); 1116 "Thread", "BrowserThread::IO");
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), 1769 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
1769 MediaInternals::GetInstance()); 1770 MediaInternals::GetInstance());
1770 } 1771 }
1771 CHECK(audio_manager_); 1772 CHECK(audio_manager_);
1772 1773
1773 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 1774 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
1774 CHECK(audio_system_); 1775 CHECK(audio_system_);
1775 } 1776 }
1776 1777
1777 } // namespace content 1778 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/blob_storage/chrome_blob_storage_context.cc ('k') | content/browser/devtools/protocol/page_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698