| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #define MainThreadTaskRunner_h | 28 #define MainThreadTaskRunner_h |
| 29 | 29 |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "platform/Timer.h" | 31 #include "platform/Timer.h" |
| 32 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 33 #include "wtf/Allocator.h" | 33 #include "wtf/Allocator.h" |
| 34 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
| 35 #include "wtf/OwnPtr.h" | 35 #include "wtf/OwnPtr.h" |
| 36 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
| 38 #include "wtf/WeakPtr.h" |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 class ExecutionContext; | 42 class ExecutionContext; |
| 42 class ExecutionContextTask; | 43 class ExecutionContextTask; |
| 43 | 44 |
| 44 class CORE_EXPORT MainThreadTaskRunner final : public GarbageCollectedFinalized<
MainThreadTaskRunner> { | 45 class CORE_EXPORT MainThreadTaskRunner final { |
| 46 USING_FAST_MALLOC(MainThreadTaskRunner); |
| 45 WTF_MAKE_NONCOPYABLE(MainThreadTaskRunner); | 47 WTF_MAKE_NONCOPYABLE(MainThreadTaskRunner); |
| 46 public: | 48 public: |
| 47 static MainThreadTaskRunner* create(ExecutionContext*); | 49 static PassOwnPtr<MainThreadTaskRunner> create(ExecutionContext*); |
| 48 | 50 |
| 49 ~MainThreadTaskRunner(); | 51 ~MainThreadTaskRunner(); |
| 50 | 52 |
| 51 DECLARE_TRACE(); | 53 DECLARE_TRACE(); |
| 52 | 54 |
| 53 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); //
Executes the task on context's thread asynchronously. | 55 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); //
Executes the task on context's thread asynchronously. |
| 54 void postInspectorTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextT
ask>); | 56 void postInspectorTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextT
ask>); |
| 55 void perform(PassOwnPtr<ExecutionContextTask>, bool); | 57 void perform(PassOwnPtr<ExecutionContextTask>, bool); |
| 56 | 58 |
| 57 void suspend(); | 59 void suspend(); |
| 58 void resume(); | 60 void resume(); |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 explicit MainThreadTaskRunner(ExecutionContext*); | 63 explicit MainThreadTaskRunner(ExecutionContext*); |
| 62 | 64 |
| 63 void pendingTasksTimerFired(Timer<MainThreadTaskRunner>*); | 65 void pendingTasksTimerFired(Timer<MainThreadTaskRunner>*); |
| 64 | 66 |
| 65 void postTaskInternal(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa
sk>, bool isInspectorTask); | 67 void postTaskInternal(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa
sk>, bool isInspectorTask); |
| 66 | 68 |
| 67 Member<ExecutionContext> m_context; | 69 // Untraced back reference to the owner Document; |
| 70 // this object has identical lifetime to it. |
| 71 UntracedMember<ExecutionContext> m_context; |
| 68 Timer<MainThreadTaskRunner> m_pendingTasksTimer; | 72 Timer<MainThreadTaskRunner> m_pendingTasksTimer; |
| 69 Vector<OwnPtr<ExecutionContextTask>> m_pendingTasks; | 73 Vector<OwnPtr<ExecutionContextTask>> m_pendingTasks; |
| 70 bool m_suspended; | 74 bool m_suspended; |
| 75 WeakPtrFactory<MainThreadTaskRunner> m_weakFactory; |
| 71 }; | 76 }; |
| 72 | 77 |
| 73 inline MainThreadTaskRunner* MainThreadTaskRunner::create(ExecutionContext* cont
ext) | 78 inline PassOwnPtr<MainThreadTaskRunner> MainThreadTaskRunner::create(ExecutionCo
ntext* context) |
| 74 { | 79 { |
| 75 return new MainThreadTaskRunner(context); | 80 return adoptPtr(new MainThreadTaskRunner(context)); |
| 76 } | 81 } |
| 77 | 82 |
| 78 } // namespace blink | 83 } // namespace blink |
| 79 | 84 |
| 80 #endif | 85 #endif |
| OLD | NEW |