1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/task/sequence_manager/graceful_queue_shutdown_helper.h" 6 7 #include "base/task/sequence_manager/task_queue_impl.h" 8 9 namespace base { 10 namespace sequence_manager { 11 namespace internal { 12 GracefulQueueShutdownHelper()13GracefulQueueShutdownHelper::GracefulQueueShutdownHelper() 14 : sequence_manager_deleted_(false) {} 15 16 GracefulQueueShutdownHelper::~GracefulQueueShutdownHelper() = default; 17 GracefullyShutdownTaskQueue(std::unique_ptr<internal::TaskQueueImpl> task_queue)18void GracefulQueueShutdownHelper::GracefullyShutdownTaskQueue( 19 std::unique_ptr<internal::TaskQueueImpl> task_queue) { 20 AutoLock lock(lock_); 21 if (sequence_manager_deleted_) 22 return; 23 queues_.push_back(std::move(task_queue)); 24 } 25 OnSequenceManagerDeleted()26void GracefulQueueShutdownHelper::OnSequenceManagerDeleted() { 27 AutoLock lock(lock_); 28 sequence_manager_deleted_ = true; 29 queues_.clear(); 30 } 31 32 std::vector<std::unique_ptr<internal::TaskQueueImpl>> TakeQueues()33GracefulQueueShutdownHelper::TakeQueues() { 34 AutoLock lock(lock_); 35 std::vector<std::unique_ptr<internal::TaskQueueImpl>> result; 36 result.swap(queues_); 37 return result; 38 } 39 40 } // namespace internal 41 } // namespace sequence_manager 42 } // namespace base 43