| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 #ifndef MainThreadTaskRunner_h | 27 #ifndef MainThreadTaskRunner_h |
| 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/Vector.h" | 35 #include "wtf/Vector.h" |
| 36 #include "wtf/WeakPtr.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 class ExecutionContext; | 40 class ExecutionContext; |
| 40 class ExecutionContextTask; | 41 class ExecutionContextTask; |
| 41 | 42 |
| 42 class CORE_EXPORT MainThreadTaskRunner final : public GarbageCollectedFinalized<
MainThreadTaskRunner> { | 43 class CORE_EXPORT MainThreadTaskRunner final { |
| 44 USING_FAST_MALLOC(MainThreadTaskRunner); |
| 43 WTF_MAKE_NONCOPYABLE(MainThreadTaskRunner); | 45 WTF_MAKE_NONCOPYABLE(MainThreadTaskRunner); |
| 44 public: | 46 public: |
| 45 static MainThreadTaskRunner* create(ExecutionContext*); | 47 static PassOwnPtr<MainThreadTaskRunner> create(ExecutionContext*); |
| 46 | 48 |
| 47 ~MainThreadTaskRunner(); | 49 ~MainThreadTaskRunner(); |
| 48 | 50 |
| 49 DECLARE_TRACE(); | 51 DECLARE_TRACE(); |
| 50 | 52 |
| 51 void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask>
); // Executes the task on context's thread asynchronously. | 53 void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask>
); // Executes the task on context's thread asynchronously. |
| 52 void postInspectorTask(const WebTraceLocation&, std::unique_ptr<ExecutionCon
textTask>); | 54 void postInspectorTask(const WebTraceLocation&, std::unique_ptr<ExecutionCon
textTask>); |
| 53 void perform(std::unique_ptr<ExecutionContextTask>, bool); | 55 void perform(std::unique_ptr<ExecutionContextTask>, bool); |
| 54 | 56 |
| 55 void suspend(); | 57 void suspend(); |
| 56 void resume(); | 58 void resume(); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 explicit MainThreadTaskRunner(ExecutionContext*); | 61 explicit MainThreadTaskRunner(ExecutionContext*); |
| 60 | 62 |
| 61 void pendingTasksTimerFired(Timer<MainThreadTaskRunner>*); | 63 void pendingTasksTimerFired(Timer<MainThreadTaskRunner>*); |
| 62 | 64 |
| 63 void postTaskInternal(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>, bool isInspectorTask); | 65 void postTaskInternal(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>, bool isInspectorTask); |
| 64 | 66 |
| 65 Member<ExecutionContext> m_context; | 67 // Untraced back reference to the owner Document; |
| 68 // this object has identical lifetime to it. |
| 69 UntracedMember<ExecutionContext> m_context; |
| 66 Timer<MainThreadTaskRunner> m_pendingTasksTimer; | 70 Timer<MainThreadTaskRunner> m_pendingTasksTimer; |
| 67 Vector<std::unique_ptr<ExecutionContextTask>> m_pendingTasks; | 71 Vector<std::unique_ptr<ExecutionContextTask>> m_pendingTasks; |
| 68 bool m_suspended; | 72 bool m_suspended; |
| 73 WeakPtrFactory<MainThreadTaskRunner> m_weakFactory; |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 inline MainThreadTaskRunner* MainThreadTaskRunner::create(ExecutionContext* cont
ext) | 76 inline PassOwnPtr<MainThreadTaskRunner> MainThreadTaskRunner::create(ExecutionCo
ntext* context) |
| 72 { | 77 { |
| 73 return new MainThreadTaskRunner(context); | 78 return adoptPtr(new MainThreadTaskRunner(context)); |
| 74 } | 79 } |
| 75 | 80 |
| 76 } // namespace blink | 81 } // namespace blink |
| 77 | 82 |
| 78 #endif | 83 #endif |
| OLD | NEW |