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

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

Issue 669603002: Reland: Refactor Script(Loader|Runner): don't access Resources all over the place... (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: test update Created 6 years, 2 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
« no previous file with comments | « Source/bindings/core/v8/ScriptStreamerTest.cpp ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 33
34 namespace blink { 34 namespace blink {
35 35
36 PendingScript::~PendingScript() 36 PendingScript::~PendingScript()
37 { 37 {
38 } 38 }
39 39
40 void PendingScript::watchForLoad(ScriptResourceClient* client) 40 void PendingScript::watchForLoad(ScriptResourceClient* client)
41 { 41 {
42 ASSERT(!m_watchingForLoad); 42 ASSERT(!m_watchingForLoad);
43 ASSERT(!isReady()); 43 // addClient() will call notifyFinished() if the load is complete. Callers
44 // who do not expect to be re-entered from this call should not call
45 // watchForLoad for a PendingScript which isReady. We also need to set
46 // m_watchingForLoad early, since addClient() can result in calling
47 // notifyFinished and further stopWatchingForLoad().
48 m_watchingForLoad = true;
44 if (m_streamer) { 49 if (m_streamer) {
45 m_streamer->addClient(client); 50 m_streamer->addClient(client);
46 } else { 51 } else {
47 // addClient() will call notifyFinished() if the load is
48 // complete. Callers do not expect to be re-entered from this call, so
49 // they should not become a client of an already-loaded Resource.
50 resource()->addClient(client); 52 resource()->addClient(client);
51 } 53 }
52 m_watchingForLoad = true;
53 } 54 }
54 55
55 void PendingScript::stopWatchingForLoad(ScriptResourceClient* client) 56 void PendingScript::stopWatchingForLoad(ScriptResourceClient* client)
56 { 57 {
57 if (!m_watchingForLoad) 58 if (!m_watchingForLoad)
58 return; 59 return;
59 ASSERT(resource()); 60 ASSERT(resource());
60 if (m_streamer) { 61 if (m_streamer) {
61 m_streamer->cancel();
62 m_streamer->removeClient(client); 62 m_streamer->removeClient(client);
63 m_streamer.clear();
64 } else { 63 } else {
65 resource()->removeClient(client); 64 resource()->removeClient(client);
66 } 65 }
67 m_watchingForLoad = false; 66 m_watchingForLoad = false;
68 } 67 }
69 68
70 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear() 69 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear()
71 { 70 {
72 setScriptResource(0); 71 setScriptResource(0);
73 m_watchingForLoad = false; 72 m_watchingForLoad = false;
74 m_startingPosition = TextPosition::belowRangePosition(); 73 m_startingPosition = TextPosition::belowRangePosition();
74 if (m_streamer)
75 m_streamer->cancel();
75 m_streamer.release(); 76 m_streamer.release();
76 return m_element.release(); 77 return m_element.release();
77 } 78 }
78 79
79 void PendingScript::setScriptResource(ScriptResource* resource) 80 void PendingScript::setScriptResource(ScriptResource* resource)
80 { 81 {
81 setResource(resource); 82 setResource(resource);
82 } 83 }
83 84
84 void PendingScript::notifyFinished(Resource* resource) 85 void PendingScript::notifyFinished(Resource* resource)
(...skipping 29 matching lines...) Expand all
114 bool PendingScript::isReady() const 115 bool PendingScript::isReady() const
115 { 116 {
116 if (resource() && !resource()->isLoaded()) 117 if (resource() && !resource()->isLoaded())
117 return false; 118 return false;
118 if (m_streamer && !m_streamer->isFinished()) 119 if (m_streamer && !m_streamer->isFinished())
119 return false; 120 return false;
120 return true; 121 return true;
121 } 122 }
122 123
123 } 124 }
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptStreamerTest.cpp ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698