summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/public/platform/WebTaskRunner.h
blob: 4369ad949589fefd4217b8656f6daffa59611e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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 WebTaskRunner_h
#define WebTaskRunner_h

#include "WebCommon.h"

#ifdef INSIDE_BLINK
#include "wtf/Functional.h"
#endif

namespace blink {

class WebTraceLocation;

// The blink representation of a chromium SingleThreadTaskRunner.
class BLINK_PLATFORM_EXPORT WebTaskRunner {
public:
    virtual ~WebTaskRunner() {}

    class BLINK_PLATFORM_EXPORT Task {
    public:
        virtual ~Task() { }
        virtual void run() = 0;
    };

    // Schedule a task to be run on the the associated WebThread.
    // Takes ownership of |Task|. Can be called from any thread.
    virtual void postTask(const WebTraceLocation&, Task*) {}

    // Schedule a task to be run after |delayMs| on the the associated WebThread.
    // Takes ownership of |Task|. Can be called from any thread.
    virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) {}

#ifdef INSIDE_BLINK
    // Helpers for posting bound functions as tasks.
    typedef Function<void()> ClosureTask;

    void postTask(const WebTraceLocation&, PassOwnPtr<ClosureTask>);
    // TODO(alexclarke): Remove this when possible.
    void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ClosureTask>, long long delayMs);
    void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ClosureTask>, double delayMs);
#endif
};

} // namespace blink

#endif // WebTaskRunner_h