OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "core/page/ScopedPageLoadDeferrer.h" | 21 #include "core/page/ScopedPageSuspender.h" |
22 | 22 |
23 #include "core/dom/Document.h" | 23 #include "core/dom/Document.h" |
24 #include "core/loader/FrameLoader.h" | 24 #include "core/loader/FrameLoader.h" |
25 #include "core/page/Page.h" | 25 #include "core/page/Page.h" |
26 #include "platform/heap/Handle.h" | 26 #include "platform/heap/Handle.h" |
27 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
28 #include "public/platform/WebScheduler.h" | 28 #include "public/platform/WebScheduler.h" |
29 #include "wtf/StdLibExtras.h" | 29 #include "wtf/StdLibExtras.h" |
30 #include "wtf/Vector.h" | 30 #include "wtf/Vector.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 unsigned s_deferralCount = 0; | 36 unsigned s_suspensionCount = 0; |
37 | 37 |
38 void setDefersLoading(bool isDeferred) { | 38 void setSuspended(bool isSuspended) { |
39 // Make a copy of the collection. Undeferring loads can cause script to run, | 39 // Make a copy of the collection. Undeferring loads can cause script to run, |
40 // which would mutate ordinaryPages() in the middle of iteration. | 40 // which would mutate ordinaryPages() in the middle of iteration. |
41 HeapVector<Member<Page>> pages; | 41 HeapVector<Member<Page>> pages; |
42 copyToVector(Page::ordinaryPages(), pages); | 42 copyToVector(Page::ordinaryPages(), pages); |
43 for (const auto& page : pages) | 43 for (const auto& page : pages) |
44 page->setDefersLoading(isDeferred); | 44 page->setSuspended(isSuspended); |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer() { | 49 ScopedPageSuspender::ScopedPageSuspender() { |
50 if (++s_deferralCount > 1) | 50 if (++s_suspensionCount > 1) |
51 return; | 51 return; |
52 | 52 |
53 setDefersLoading(true); | 53 setSuspended(true); |
54 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); | 54 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); |
55 } | 55 } |
56 | 56 |
57 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() { | 57 ScopedPageSuspender::~ScopedPageSuspender() { |
58 if (--s_deferralCount > 0) | 58 if (--s_suspensionCount > 0) |
59 return; | 59 return; |
60 | 60 |
61 setDefersLoading(false); | 61 setSuspended(false); |
62 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); | 62 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); |
63 } | 63 } |
64 | 64 |
65 bool ScopedPageLoadDeferrer::isActive() { | 65 bool ScopedPageSuspender::isActive() { |
66 return s_deferralCount > 0; | 66 return s_suspensionCount > 0; |
67 } | 67 } |
68 | 68 |
69 } // namespace blink | 69 } // namespace blink |
OLD | NEW |