Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebThread.h
blobb84f76ff86ea349268ce91427c0d68baeb3038d6
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef WebThread_h
26 #define WebThread_h
28 #include "WebCommon.h"
29 #include <stdint.h>
31 namespace blink {
32 class WebScheduler;
33 class WebTaskRunner;
34 class WebTraceLocation;
36 // Always an integer value.
37 typedef uintptr_t PlatformThreadId;
39 // Provides an interface to an embedder-defined thread implementation.
41 // Deleting the thread blocks until all pending, non-delayed tasks have been
42 // run.
43 class BLINK_PLATFORM_EXPORT WebThread {
44 public:
45 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is
46 // expected to complete before this deadline.
47 class IdleTask {
48 public:
49 virtual ~IdleTask() { }
50 virtual void run(double deadlineSeconds) = 0;
53 class BLINK_PLATFORM_EXPORT TaskObserver {
54 public:
55 virtual ~TaskObserver() { }
56 virtual void willProcessTask() = 0;
57 virtual void didProcessTask() = 0;
61 // Returns a WebTaskRunner bound to the underlying scheduler's default task queue.
62 virtual WebTaskRunner* taskRunner() { return nullptr; }
64 virtual bool isCurrentThread() const = 0;
65 virtual PlatformThreadId threadId() const { return 0; }
67 virtual void addTaskObserver(TaskObserver*) { }
68 virtual void removeTaskObserver(TaskObserver*) { }
70 // Returns the scheduler associated with the thread.
71 virtual WebScheduler* scheduler() const = 0;
73 virtual ~WebThread() { }
76 } // namespace blink
78 #endif