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

Side by Side Diff: Source/core/inspector/InspectorResourceContentLoader.cpp

Issue 800113002: Use C++11 range-based for loop in Source/core/inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: REBASE AGAIN! Created 6 years 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "config.h" 5 #include "config.h"
6 #include "core/inspector/InspectorResourceContentLoader.h" 6 #include "core/inspector/InspectorResourceContentLoader.h"
7 7
8 #include "core/FetchInitiatorTypeNames.h" 8 #include "core/FetchInitiatorTypeNames.h"
9 #include "core/css/CSSStyleSheet.h" 9 #include "core/css/CSSStyleSheet.h"
10 #include "core/css/StyleSheetContents.h" 10 #include "core/css/StyleSheetContents.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 { 84 {
85 m_started = true; 85 m_started = true;
86 Vector<Document*> documents; 86 Vector<Document*> documents;
87 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver seNext()) { 87 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver seNext()) {
88 if (!frame->isLocalFrame()) 88 if (!frame->isLocalFrame())
89 continue; 89 continue;
90 LocalFrame* localFrame = toLocalFrame(frame); 90 LocalFrame* localFrame = toLocalFrame(frame);
91 documents.append(localFrame->document()); 91 documents.append(localFrame->document());
92 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); 92 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame));
93 } 93 }
94 for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum entIt != documents.end(); ++documentIt) { 94 for (const auto& documentIt : documents) {
95 Document* document = *documentIt; 95 Document* document = documentIt;
96 HashSet<String> urlsToFetch; 96 HashSet<String> urlsToFetch;
97 97
98 ResourceRequest resourceRequest; 98 ResourceRequest resourceRequest;
99 HistoryItem* item = document->frame() ? document->frame()->loader().curr entItem() : 0; 99 HistoryItem* item = document->frame() ? document->frame()->loader().curr entItem() : 0;
100 if (item) { 100 if (item) {
101 resourceRequest = FrameLoader::requestFromHistoryItem(item, ReturnCa cheDataDontLoad); 101 resourceRequest = FrameLoader::requestFromHistoryItem(item, ReturnCa cheDataDontLoad);
102 } else { 102 } else {
103 resourceRequest = document->url(); 103 resourceRequest = document->url();
104 resourceRequest.setCachePolicy(ReturnCacheDataDontLoad); 104 resourceRequest.setCachePolicy(ReturnCacheDataDontLoad);
105 } 105 }
106 resourceRequest.setRequestContext(blink::WebURLRequest::RequestContextIn ternal); 106 resourceRequest.setRequestContext(blink::WebURLRequest::RequestContextIn ternal);
107 107
108 if (!resourceRequest.url().string().isEmpty()) { 108 if (!resourceRequest.url().string().isEmpty()) {
109 urlsToFetch.add(resourceRequest.url().string()); 109 urlsToFetch.add(resourceRequest.url().string());
110 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter nal); 110 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter nal);
111 ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour ce(request); 111 ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour ce(request);
112 if (resource) { 112 if (resource) {
113 // Prevent garbage collection by holding a reference to this res ource. 113 // Prevent garbage collection by holding a reference to this res ource.
114 m_resources.append(resource.get()); 114 m_resources.append(resource.get());
115 ResourceClient* resourceClient = new ResourceClient(this); 115 ResourceClient* resourceClient = new ResourceClient(this);
116 m_pendingResourceClients.add(resourceClient); 116 m_pendingResourceClients.add(resourceClient);
117 resourceClient->waitForResource(resource.get()); 117 resourceClient->waitForResource(resource.get());
118 } 118 }
119 } 119 }
120 120
121 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > styleSheets; 121 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > styleSheets;
122 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); 122 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets);
123 for (WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> >::const_iterato r stylesheetIt = styleSheets.begin(); stylesheetIt != styleSheets.end(); ++style sheetIt) { 123 for (const auto& stylesheetIt : styleSheets) {
124 CSSStyleSheet* styleSheet = *stylesheetIt; 124 CSSStyleSheet* styleSheet = stylesheetIt;
125 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted ()) 125 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted ())
126 continue; 126 continue;
127 String url = styleSheet->baseURL().string(); 127 String url = styleSheet->baseURL().string();
128 if (url.isEmpty() || urlsToFetch.contains(url)) 128 if (url.isEmpty() || urlsToFetch.contains(url))
129 continue; 129 continue;
130 urlsToFetch.add(url); 130 urlsToFetch.add(url);
131 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames:: internal); 131 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames:: internal);
132 request.mutableResourceRequest().setRequestContext(blink::WebURLRequ est::RequestContextInternal); 132 request.mutableResourceRequest().setRequestContext(blink::WebURLRequ est::RequestContextInternal);
133 ResourcePtr<Resource> resource = document->fetcher()->fetchCSSStyleS heet(request); 133 ResourcePtr<Resource> resource = document->fetcher()->fetchCSSStyleS heet(request);
134 if (!resource) 134 if (!resource)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 void InspectorResourceContentLoader::dispose() 167 void InspectorResourceContentLoader::dispose()
168 { 168 {
169 stop(); 169 stop();
170 } 170 }
171 171
172 void InspectorResourceContentLoader::stop() 172 void InspectorResourceContentLoader::stop()
173 { 173 {
174 HashSet<ResourceClient*> pendingResourceClients; 174 HashSet<ResourceClient*> pendingResourceClients;
175 m_pendingResourceClients.swap(pendingResourceClients); 175 m_pendingResourceClients.swap(pendingResourceClients);
176 for (HashSet<ResourceClient*>::const_iterator it = pendingResourceClients.be gin(); it != pendingResourceClients.end(); ++it) 176 for (const auto& it : pendingResourceClients)
177 (*it)->m_loader = 0; 177 it->m_loader = 0;
178 m_resources.clear(); 178 m_resources.clear();
179 // Make sure all callbacks are called to prevent infinite waiting time. 179 // Make sure all callbacks are called to prevent infinite waiting time.
180 checkDone(); 180 checkDone();
181 } 181 }
182 182
183 bool InspectorResourceContentLoader::hasFinished() 183 bool InspectorResourceContentLoader::hasFinished()
184 { 184 {
185 return m_allRequestsStarted && m_pendingResourceClients.size() == 0; 185 return m_allRequestsStarted && m_pendingResourceClients.size() == 0;
186 } 186 }
187 187
188 void InspectorResourceContentLoader::checkDone() 188 void InspectorResourceContentLoader::checkDone()
189 { 189 {
190 if (!hasFinished()) 190 if (!hasFinished())
191 return; 191 return;
192 PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> > callbacks; 192 PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> > callbacks;
193 callbacks.swap(m_callbacks); 193 callbacks.swap(m_callbacks);
194 for (PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> >::const_iter ator it = callbacks.begin(); it != callbacks.end(); ++it) 194 for (const auto& it : callbacks)
195 (*it)->handleEvent(); 195 it->handleEvent();
196 } 196 }
197 197
198 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) 198 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client)
199 { 199 {
200 m_pendingResourceClients.remove(client); 200 m_pendingResourceClients.remove(client);
201 checkDone(); 201 checkDone();
202 } 202 }
203 203
204 } // namespace blink 204 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698