OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WebViewScheduler_h | 5 #ifndef WebViewScheduler_h |
6 #define WebViewScheduler_h | 6 #define WebViewScheduler_h |
7 | 7 |
8 #include "WebCommon.h" | 8 #include "WebCommon.h" |
9 #include "public/platform/BlameContext.h" | 9 #include "public/platform/BlameContext.h" |
10 | 10 |
| 11 #if INSIDE_BLINK |
| 12 #include "wtf/Forward.h" |
| 13 #include "wtf/WeakPtr.h" |
| 14 #else |
| 15 namespace WTF { |
| 16 template<typename T> class WeakPtrFactory; |
| 17 } |
| 18 #endif |
| 19 |
11 #include <memory> | 20 #include <memory> |
12 | 21 |
13 namespace blink { | 22 namespace blink { |
14 | 23 |
15 class WebFrameScheduler; | 24 class WebFrameScheduler; |
16 | 25 |
17 class BLINK_PLATFORM_EXPORT WebViewScheduler { | 26 class BLINK_PLATFORM_EXPORT WebViewScheduler { |
18 public: | 27 public: |
19 virtual ~WebViewScheduler() { } | 28 WebViewScheduler(); |
| 29 virtual ~WebViewScheduler(); |
20 | 30 |
21 // The scheduler may throttle tasks associated with background pages. | 31 // The scheduler may throttle tasks associated with background pages. |
22 virtual void setPageVisible(bool) = 0; | 32 virtual void setPageVisible(bool) = 0; |
23 | 33 |
24 // Creates a new WebFrameScheduler. The caller is responsible for deleting | 34 // Creates a new WebFrameScheduler. The caller is responsible for deleting |
25 // it. All tasks executed by the frame scheduler will be attributed to | 35 // it. All tasks executed by the frame scheduler will be attributed to |
26 // |BlameContext|. | 36 // |BlameContext|. |
27 virtual std::unique_ptr<WebFrameScheduler> createFrameScheduler(BlameContext
*) = 0; | 37 virtual std::unique_ptr<WebFrameScheduler> createFrameScheduler(BlameContext
*) = 0; |
28 | 38 |
29 // Instructs this WebViewScheduler to use virtual time. When virtual time is
enabled | 39 // Instructs this WebViewScheduler to use virtual time. When virtual time is
enabled |
30 // the system doesn't actually sleep for the delays between tasks before exe
cuting | 40 // the system doesn't actually sleep for the delays between tasks before exe
cuting |
31 // them. E.g: A-E are delayed tasks | 41 // them. E.g: A-E are delayed tasks |
32 // | 42 // |
33 // | A B C D E (normal) | 43 // | A B C D E (normal) |
34 // |-----------------------------> time | 44 // |-----------------------------> time |
35 // | 45 // |
36 // |ABCDE (virtual time) | 46 // |ABCDE (virtual time) |
37 // |-----------------------------> time | 47 // |-----------------------------> time |
38 virtual void enableVirtualTime() = 0; | 48 virtual void enableVirtualTime() = 0; |
39 | 49 |
40 // Controls whether or not virtual time is allowed to advance. If virtual ti
me | 50 // Controls whether or not virtual time is allowed to advance. If virtual ti
me |
41 // is not allowed to advance then delayed tasks posted to the WebTaskRunners
owned | 51 // is not allowed to advance then delayed tasks posted to the WebTaskRunners
owned |
42 // by any child WebFrameSchedulers will be paused. If virtual time is allowe
d to | 52 // by any child WebFrameSchedulers will be paused. If virtual time is allowe
d to |
43 // advance then tasks will be run in time order (as usual) but virtual time
will | 53 // advance then tasks will be run in time order (as usual) but virtual time
will |
44 // fast forward so that the system doesn't actually sleep for the delays bet
ween | 54 // fast forward so that the system doesn't actually sleep for the delays bet
ween |
45 // tasks before executing them. | 55 // tasks before executing them. |
46 virtual void setAllowVirtualTimeToAdvance(bool) = 0; | 56 virtual void setAllowVirtualTimeToAdvance(bool) = 0; |
| 57 |
| 58 // Returns true if virtual time is allowed to advance. |
| 59 virtual bool virtualTimeAllowedToAdvance() const = 0; |
| 60 |
| 61 void incrementPendingResourceLoadCount(); |
| 62 void decrementPendingResourceLoadCount(); |
| 63 |
| 64 enum class VirtualTimePolicy { |
| 65 ADVANCE, |
| 66 PAUSE, |
| 67 PAUSE_IF_NETWORK_FETCHES_PENDING |
| 68 }; |
| 69 |
| 70 void setVirtualTimePolicy(VirtualTimePolicy); |
| 71 |
| 72 #ifdef INSIDE_BLINK |
| 73 void setVirtualTimePolicy(const WTF::String&); |
| 74 |
| 75 WeakPtr<WebViewScheduler> createWeakPtr() { return m_weakPtrFactory->createW
eakPtr(); } |
| 76 #endif |
| 77 |
| 78 private: |
| 79 int m_pendingResourceLoadCount; |
| 80 VirtualTimePolicy m_virtualTimePolicy; |
| 81 |
| 82 // This is ugly. We can't use WTF types outside of blink but we can forward
declare them. |
| 83 std::unique_ptr<WTF::WeakPtrFactory<WebViewScheduler>> m_weakPtrFactory; |
47 }; | 84 }; |
48 | 85 |
49 } // namespace blink | 86 } // namespace blink |
50 | 87 |
51 #endif // WebViewScheduler | 88 #endif // WebViewScheduler |
OLD | NEW |