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

Side by Side Diff: third_party/WebKit/Source/core/dom/PendingScript.cpp

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 years, 10 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) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 35
36 PassOwnPtrWillBeRawPtr<PendingScript> PendingScript::create(Element* element, Sc riptResource* resource) 36 PassOwnPtrWillBeRawPtr<PendingScript> PendingScript::create(Element* element, Sc riptResource* resource)
37 { 37 {
38 return adoptPtrWillBeNoop(new PendingScript(element, resource)); 38 return adoptPtrWillBeNoop(new PendingScript(element, resource));
39 } 39 }
40 40
41 PendingScript::PendingScript(Element* element, ScriptResource* resource) 41 PendingScript::PendingScript(Element* element, ScriptResource* resource)
42 : m_watchingForLoad(false) 42 : m_watchingForLoad(false)
43 , m_element(element) 43 , m_element(element)
44 , m_integrityFailure(false) 44 , m_integrityFailure(false)
45 , m_client(nullptr)
45 { 46 {
46 setScriptResource(resource); 47 setScriptResource(resource);
48 #if ENABLE(OILPAN)
49 ThreadState::current()->registerPreFinalizer(this);
50 #endif
47 } 51 }
48 52
49 PendingScript::~PendingScript() 53 PendingScript::~PendingScript()
50 { 54 {
51 } 55 }
52 56
57 void PendingScript::dispose()
58 {
59 if (!m_client)
60 return;
61 stopWatchingForLoad();
62 releaseElementAndClear();
63 }
64
53 PendingScript& PendingScript::operator=(const PendingScript& other) 65 PendingScript& PendingScript::operator=(const PendingScript& other)
54 { 66 {
55 if (this == &other) 67 if (this == &other)
56 return *this; 68 return *this;
57 69
58 m_watchingForLoad = other.m_watchingForLoad; 70 m_watchingForLoad = other.m_watchingForLoad;
59 m_element = other.m_element; 71 m_element = other.m_element;
60 m_startingPosition = other.m_startingPosition; 72 m_startingPosition = other.m_startingPosition;
61 m_integrityFailure = other.m_integrityFailure; 73 m_integrityFailure = other.m_integrityFailure;
62 m_streamer = other.m_streamer; 74 m_streamer = other.m_streamer;
63 this->ResourceOwner<ScriptResource, ScriptResourceClient>::operator=(other); 75 this->ResourceOwner<ScriptResource, ScriptResourceClient>::operator=(other);
64 return *this; 76 return *this;
65 } 77 }
66 78
67 void PendingScript::watchForLoad(ScriptResourceClient* client) 79 void PendingScript::watchForLoad(ScriptResourceClient* client)
68 { 80 {
69 ASSERT(!m_watchingForLoad); 81 ASSERT(!m_watchingForLoad);
70 // addClient() will call notifyFinished() if the load is complete. Callers 82 // addClient() will call streamingFinished() if the load is complete. Caller s
71 // who do not expect to be re-entered from this call should not call 83 // who do not expect to be re-entered from this call should not call
72 // watchForLoad for a PendingScript which isReady. We also need to set 84 // watchForLoad for a PendingScript which isReady. We also need to set
73 // m_watchingForLoad early, since addClient() can result in calling 85 // m_watchingForLoad early, since addClient() can result in calling
74 // notifyFinished and further stopWatchingForLoad(). 86 // notifyFinished and further stopWatchingForLoad().
75 m_watchingForLoad = true; 87 m_watchingForLoad = true;
76 if (m_streamer) { 88 m_client = client;
77 m_streamer->addClient(client); 89 if (!m_streamer)
78 } else {
79 resource()->addClient(client); 90 resource()->addClient(client);
80 }
81 } 91 }
82 92
83 void PendingScript::stopWatchingForLoad(ScriptResourceClient* client) 93 void PendingScript::stopWatchingForLoad()
84 { 94 {
85 if (!m_watchingForLoad) 95 if (!m_watchingForLoad)
86 return; 96 return;
87 ASSERT(resource()); 97 ASSERT(resource());
88 if (m_streamer) { 98 if (!m_streamer)
89 m_streamer->removeClient(client); 99 resource()->removeClient(m_client);
90 } else { 100 m_client = nullptr;
91 resource()->removeClient(client);
92 }
93 m_watchingForLoad = false; 101 m_watchingForLoad = false;
94 } 102 }
95 103
104 void PendingScript::streamingFinished()
105 {
106 ASSERT(resource());
107 if (m_client)
108 m_client->notifyFinished(resource());
109 }
110
96 void PendingScript::setElement(Element* element) 111 void PendingScript::setElement(Element* element)
97 { 112 {
98 m_element = element; 113 m_element = element;
99 } 114 }
100 115
101 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear() 116 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear()
102 { 117 {
103 setScriptResource(0); 118 setScriptResource(0);
104 m_watchingForLoad = false; 119 m_watchingForLoad = false;
105 m_startingPosition = TextPosition::belowRangePosition(); 120 m_startingPosition = TextPosition::belowRangePosition();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 bool PendingScript::isReady() const 212 bool PendingScript::isReady() const
198 { 213 {
199 if (resource() && !resource()->isLoaded()) 214 if (resource() && !resource()->isLoaded())
200 return false; 215 return false;
201 if (m_streamer && !m_streamer->isFinished()) 216 if (m_streamer && !m_streamer->isFinished())
202 return false; 217 return false;
203 return true; 218 return true;
204 } 219 }
205 220
206 } // namespace blink 221 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/PendingScript.h ('k') | third_party/WebKit/Source/core/dom/ProcessingInstruction.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698