Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: third_party/WebKit/Source/core/page/ScopedPageLoadDeferrer.cpp

Issue 2174263002: Defer loads in new pages/frames if ScopedPageLoadDeferral is active (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hammer Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ScopedPageLoadDeferrer.h"
22 22
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/frame/LocalFrame.h"
25 #include "core/loader/FrameLoader.h" 24 #include "core/loader/FrameLoader.h"
26 #include "core/page/Page.h" 25 #include "core/page/Page.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/HashSet.h" 29 #include "wtf/StdLibExtras.h"
30 #include "wtf/Vector.h"
30 31
31 namespace blink { 32 namespace blink {
32 33
33 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) 34 namespace {
35
36 using DeferredPages = Vector<Persistent<Page>, 16>;
37
38 unsigned s_deferralCount = 0;
39
40 DeferredPages& deferredPages()
34 { 41 {
42 DEFINE_STATIC_LOCAL(DeferredPages, pages, ());
43 return pages;
44 }
45
46 void setDefersLoading(bool isDeferred)
47 {
48 for (const auto& page : deferredPages())
49 page->setDefersLoading(isDeferred);
50 }
51
52 } // namespace
53
54 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer()
55 {
56 if (++s_deferralCount > 1)
57 return;
58
35 for (Page* page : Page::ordinaryPages()) { 59 for (Page* page : Page::ordinaryPages()) {
36 if (page == exclusion || page->defersLoading()) 60 if (page->defersLoading())
37 continue; 61 continue;
38 m_deferredPages.append(page); 62 deferredPages().append(page);
39 } 63 }
40 64
41 setDefersLoading(true); 65 setDefersLoading(true);
42 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); 66 Platform::current()->currentThread()->scheduler()->suspendTimerQueue();
43 } 67 }
44 68
45 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() 69 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer()
46 { 70 {
47 setDefersLoading(false); 71 if (--s_deferralCount == 0) {
48 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); 72 setDefersLoading(false);
73 Platform::current()->currentThread()->scheduler()->resumeTimerQueue();
74 }
49 } 75 }
50 76
51 void ScopedPageLoadDeferrer::setDefersLoading(bool isDeferred) 77 void ScopedPageLoadDeferrer::deferIfNeeded(Page* page)
52 { 78 {
53 79 if (s_deferralCount > 0) {
54 for (const auto& page : m_deferredPages) 80 deferredPages().append(page);
55 page->setDefersLoading(isDeferred); 81 page->setDefersLoading(true);
82 }
56 } 83 }
57 84
58 } // namespace blink 85 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698