| Index: content/renderer/scheduler/deadline_task_runner.h
|
| diff --git a/content/renderer/scheduler/deadline_task_runner.h b/content/renderer/scheduler/deadline_task_runner.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bd458b948a1eced9cb3f1f4ccf3ea494063dca58
|
| --- /dev/null
|
| +++ b/content/renderer/scheduler/deadline_task_runner.h
|
| @@ -0,0 +1,52 @@
|
| +// Copyright 2015 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 CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_
|
| +#define CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +#include "base/time/time.h"
|
| +
|
| +namespace content {
|
| +
|
| +class DeadlineTaskRunner {
|
| + public:
|
| + DeadlineTaskRunner(const base::Closure& callback,
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
| +
|
| + ~DeadlineTaskRunner();
|
| +
|
| + // If there is no outstanding task then a task is posted to run at |deadline|.
|
| + // If there is an outstanding task which is:
|
| + // a) sooner - then this is a NOP.
|
| + // b) later - then the outstanding task is cancelled and a new task is
|
| + // posted to run at |deadline|.
|
| + //
|
| + // Once the deadline task has run, we reset.
|
| + void SetDeadline(const tracked_objects::Location& from_here,
|
| + base::TimeTicks deadline,
|
| + base::TimeTicks now);
|
| +
|
| + private:
|
| + void Cancel();
|
| + void RunInternal();
|
| + void InitializeRunInternal();
|
| +
|
| + base::Closure run_internal_;
|
| + base::Closure callback_;
|
| + base::TimeTicks deadline_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| +
|
| + // Used to ensure RunInternal() is not run when this object is destroyed.
|
| + base::WeakPtrFactory<DeadlineTaskRunner> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DeadlineTaskRunner);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_RENDERER_SCHEDULER_DEADLINE_TASK_RUNNER_H_
|
|
|