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: base/threading/sequenced_worker_pool.cc

Issue 1904273002: Enforce singleton not allowed behavior for CONTINUE_ON_SHUTDOWN tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made a Singleton leaky in test_support_android.cc Created 4 years, 5 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 | « base/test/test_support_android.cc ('k') | net/proxy/dhcpcsvc_init_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Gets the worker for the current thread out of thread-local storage. 240 // Gets the worker for the current thread out of thread-local storage.
241 static Worker* GetForCurrentThread(); 241 static Worker* GetForCurrentThread();
242 242
243 // Indicates that a task is about to be run. The parameters provide 243 // Indicates that a task is about to be run. The parameters provide
244 // additional metainformation about the task being run. 244 // additional metainformation about the task being run.
245 void set_running_task_info(SequenceToken token, 245 void set_running_task_info(SequenceToken token,
246 WorkerShutdown shutdown_behavior) { 246 WorkerShutdown shutdown_behavior) {
247 is_processing_task_ = true; 247 is_processing_task_ = true;
248 task_sequence_token_ = token; 248 task_sequence_token_ = token;
249 task_shutdown_behavior_ = shutdown_behavior; 249 task_shutdown_behavior_ = shutdown_behavior;
250
251 // It is dangerous for tasks with CONTINUE_ON_SHUTDOWN to access a class
252 // that implements a non-leaky base::Singleton because they are generally
253 // destroyed before the process terminates via an AtExitManager
254 // registration. This will trigger a DCHECK to warn of such cases. See the
255 // comment about CONTINUE_ON_SHUTDOWN for more details.
256 ThreadRestrictions::SetSingletonAllowed(task_shutdown_behavior_ !=
257 CONTINUE_ON_SHUTDOWN);
250 } 258 }
251 259
252 // Indicates that the task has finished running. 260 // Indicates that the task has finished running.
253 void reset_running_task_info() { is_processing_task_ = false; } 261 void reset_running_task_info() { is_processing_task_ = false; }
254 262
255 // Whether the worker is processing a task. 263 // Whether the worker is processing a task.
256 bool is_processing_task() { return is_processing_task_; } 264 bool is_processing_task() { return is_processing_task_; }
257 265
258 SequenceToken task_sequence_token() const { 266 SequenceToken task_sequence_token() const {
259 DCHECK(is_processing_task_); 267 DCHECK(is_processing_task_);
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1407 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1400 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1408 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1401 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1409 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1402 } 1410 }
1403 1411
1404 bool SequencedWorkerPool::IsShutdownInProgress() { 1412 bool SequencedWorkerPool::IsShutdownInProgress() {
1405 return inner_->IsShutdownInProgress(); 1413 return inner_->IsShutdownInProgress();
1406 } 1414 }
1407 1415
1408 } // namespace base 1416 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_support_android.cc ('k') | net/proxy/dhcpcsvc_init_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698