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 #ifndef BASE_TASK_SEQUENCE_MANAGER_GRACEFUL_QUEUE_SHUTDOWN_HELPER_H_ 6 #define BASE_TASK_SEQUENCE_MANAGER_GRACEFUL_QUEUE_SHUTDOWN_HELPER_H_ 7 8 #include <memory> 9 #include <vector> 10 11 #include "base/macros.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/synchronization/lock.h" 14 15 namespace base { 16 namespace sequence_manager { 17 namespace internal { 18 19 class TaskQueueImpl; 20 21 // Thread-safe helper to shutdown queues from any thread. 22 class GracefulQueueShutdownHelper 23 : public RefCountedThreadSafe<GracefulQueueShutdownHelper> { 24 public: 25 GracefulQueueShutdownHelper(); 26 27 void GracefullyShutdownTaskQueue( 28 std::unique_ptr<internal::TaskQueueImpl> queue); 29 30 void OnSequenceManagerDeleted(); 31 32 std::vector<std::unique_ptr<internal::TaskQueueImpl>> TakeQueues(); 33 34 private: 35 // This class is ref-counted so it controls its own lifetime. 36 ~GracefulQueueShutdownHelper(); 37 friend class RefCountedThreadSafe<GracefulQueueShutdownHelper>; 38 39 Lock lock_; 40 bool sequence_manager_deleted_; 41 std::vector<std::unique_ptr<internal::TaskQueueImpl>> queues_; 42 43 DISALLOW_COPY_AND_ASSIGN(GracefulQueueShutdownHelper); 44 }; 45 46 } // namespace internal 47 } // namespace sequence_manager 48 } // namespace base 49 50 #endif // BASE_TASK_SEQUENCE_MANAGER_GRACEFUL_QUEUE_SHUTDOWN_HELPER_H_ 51