Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef TRACED_TASK_COMMON_H
8 #define TRACED_TASK_COMMON_H
10 #include "base/task.h"
11 #include "GeckoTaskTracer.h"
12 #include "nsCOMPtr.h"
13 #include "nsThreadUtils.h"
15 namespace mozilla {
16 namespace tasktracer {
18 class TracedTaskCommon
19 {
20 public:
21 TracedTaskCommon();
22 virtual ~TracedTaskCommon() {}
24 protected:
25 void Init();
27 // Sets up the metadata on the current thread's TraceInfo for this task.
28 // After Run(), ClearTraceInfo is called to reset the metadata.
29 void SetTraceInfo();
30 void ClearTraceInfo();
32 // Its own task Id, an unique number base on its thread Id and a last unique
33 // task Id stored in its TraceInfo.
34 uint64_t mTaskId;
36 uint64_t mSourceEventId;
37 SourceEventType mSourceEventType;
38 };
40 class TracedRunnable : public TracedTaskCommon
41 , public nsRunnable
42 {
43 public:
44 NS_DECL_NSIRUNNABLE
46 TracedRunnable(nsIRunnable* aOriginalObj);
48 private:
49 virtual ~TracedRunnable() {}
51 nsCOMPtr<nsIRunnable> mOriginalObj;
52 };
54 class TracedTask : public TracedTaskCommon
55 , public Task
56 {
57 public:
58 TracedTask(Task* aOriginalObj);
59 ~TracedTask()
60 {
61 if (mOriginalObj) {
62 delete mOriginalObj;
63 mOriginalObj = nullptr;
64 }
65 }
67 virtual void Run();
69 private:
70 Task* mOriginalObj;
71 };
73 // FakeTracedTask is for tracking events that are not directly dispatched from
74 // their parents, e.g. The timer events.
75 class FakeTracedTask : public TracedTaskCommon
76 {
77 public:
78 FakeTracedTask() : TracedTaskCommon() {}
79 FakeTracedTask(int* aVptr);
80 FakeTracedTask(const FakeTracedTask& aTask);
81 void BeginFakeTracedTask();
82 void EndFakeTracedTask();
83 };
85 class AutoRunFakeTracedTask
86 {
87 public:
88 AutoRunFakeTracedTask(FakeTracedTask* aFakeTracedTask);
89 ~AutoRunFakeTracedTask();
90 private:
91 FakeTracedTask mFakeTracedTask;
92 bool mInitialized;
93 };
95 } // namespace tasktracer
96 } // namespace mozilla
98 #endif