// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PAUSABLE_TASK_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PAUSABLE_TASK_H_ #include #include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/frame/pausable_timer.h" #include "third_party/blink/renderer/platform/heap/self_keep_alive.h" namespace blink { // A class that monitors the lifetime and suspension state of a context, and // runs a task either when the context is unsuspended or when the context is // invalidated. class CORE_EXPORT PausableTask final : public GarbageCollectedFinalized, public PausableTimer { USING_GARBAGE_COLLECTED_MIXIN(PausableTask); public: // Note: This asserts that the context is currently suspended. PausableTask(ExecutionContext*, WebLocalFrame::PausableTaskCallback); ~PausableTask() override; // Checks if the context is paused, and, if not, executes the callback // immediately. Otherwise constructs a PausableTask that will run the // callback when execution is unpaused. static void Post(ExecutionContext*, WebLocalFrame::PausableTaskCallback); // PausableTimer: void ContextDestroyed(ExecutionContext*) override; void Fired() override; private: void Dispose(); WebLocalFrame::PausableTaskCallback callback_; SelfKeepAlive keep_alive_; }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_PAUSABLE_TASK_H_