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

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 1710733002: Move multipart resource handling to core/fetch (2/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@multipart-cleanup
Patch Set: rebase Created 4 years, 9 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) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 { 197 {
198 InspectorInstrumentation::removedResourceFromMemoryCache(this); 198 InspectorInstrumentation::removedResourceFromMemoryCache(this);
199 } 199 }
200 200
201 DEFINE_TRACE(Resource) 201 DEFINE_TRACE(Resource)
202 { 202 {
203 visitor->trace(m_loader); 203 visitor->trace(m_loader);
204 #if ENABLE(OILPAN) 204 #if ENABLE(OILPAN)
205 visitor->trace(m_cacheHandler); 205 visitor->trace(m_cacheHandler);
206 #endif 206 #endif
207 visitor->trace(m_multipartParser);
208 MultipartImageResourceParser::Client::trace(visitor);
207 } 209 }
208 210
209 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns) 211 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns)
210 { 212 {
211 m_options = options; 213 m_options = options;
212 m_loading = true; 214 m_loading = true;
213 215
214 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); 216 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest);
215 if (!accept().isEmpty()) 217 if (!accept().isEmpty())
216 request.setHTTPAccept(accept()); 218 request.setHTTPAccept(accept());
(...skipping 23 matching lines...) Expand all
240 return; 242 return;
241 243
242 ResourceClientWalker<ResourceClient> w(m_clients); 244 ResourceClientWalker<ResourceClient> w(m_clients);
243 while (ResourceClient* c = w.next()) 245 while (ResourceClient* c = w.next())
244 c->notifyFinished(this); 246 c->notifyFinished(this);
245 } 247 }
246 248
247 void Resource::appendData(const char* data, size_t length) 249 void Resource::appendData(const char* data, size_t length)
248 { 250 {
249 TRACE_EVENT0("blink", "Resource::appendData"); 251 TRACE_EVENT0("blink", "Resource::appendData");
252 if (isMultipartImage()) {
253 m_multipartParser->addData(data, length);
254 return;
255 }
256 appendDataInternal(data, length);
257 }
258
259 void Resource::appendDataInternal(const char* data, size_t length)
260 {
250 ASSERT(m_revalidatingRequest.isNull()); 261 ASSERT(m_revalidatingRequest.isNull());
251 ASSERT(!errorOccurred()); 262 ASSERT(!errorOccurred());
252 if (m_options.dataBufferingPolicy == DoNotBufferData) 263 if (m_options.dataBufferingPolicy == DoNotBufferData)
253 return; 264 return;
254 if (m_data) 265 if (m_data)
255 m_data->append(data, length); 266 m_data->append(data, length);
256 else 267 else
257 m_data = SharedBuffer::createPurgeable(data, length); 268 m_data = SharedBuffer::createPurgeable(data, length);
258 setEncodedSize(m_data->size()); 269 setEncodedSize(m_data->size());
259 } 270 }
(...skipping 20 matching lines...) Expand all
280 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); 291 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin();
281 for (int i = it->value; i; i--) { 292 for (int i = it->value; i; i--) {
282 m_finishedClients.add(it->key); 293 m_finishedClients.add(it->key);
283 m_clients.remove(it); 294 m_clients.remove(it);
284 } 295 }
285 } 296 }
286 } 297 }
287 298
288 void Resource::error(Resource::Status status) 299 void Resource::error(Resource::Status status)
289 { 300 {
301 if (m_multipartParser)
302 m_multipartParser->cancel();
303
290 if (!m_revalidatingRequest.isNull()) 304 if (!m_revalidatingRequest.isNull())
291 m_revalidatingRequest = ResourceRequest(); 305 m_revalidatingRequest = ResourceRequest();
292 306
293 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded())) 307 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded()))
294 memoryCache()->remove(this); 308 memoryCache()->remove(this);
295 309
296 setStatus(status); 310 setStatus(status);
297 ASSERT(errorOccurred()); 311 ASSERT(errorOccurred());
298 m_data.clear(); 312 m_data.clear();
299 313
300 setLoading(false); 314 setLoading(false);
301 checkNotify(); 315 checkNotify();
302 markClientsFinished(); 316 markClientsFinished();
303 } 317 }
304 318
305 void Resource::finishOnePart() 319 void Resource::finishOnePart()
306 { 320 {
307 setLoading(false); 321 setLoading(false);
308 checkNotify(); 322 checkNotify();
309 } 323 }
310 324
311 void Resource::finish() 325 void Resource::finish()
312 { 326 {
313 ASSERT(m_revalidatingRequest.isNull()); 327 ASSERT(m_revalidatingRequest.isNull());
314 ASSERT(!errorOccurred()); 328 ASSERT(!errorOccurred());
329 if (m_multipartParser)
330 m_multipartParser->finish();
331
315 finishOnePart(); 332 finishOnePart();
316 markClientsFinished(); 333 markClientsFinished();
317 if (!errorOccurred()) 334 if (!errorOccurred())
318 m_status = Cached; 335 m_status = Cached;
319 } 336 }
320 337
321 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const 338 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const
322 { 339 {
323 String ignoredErrorDescription; 340 String ignoredErrorDescription;
324 return passesAccessControlCheck(securityOrigin, ignoredErrorDescription); 341 return passesAccessControlCheck(securityOrigin, ignoredErrorDescription);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 { 466 {
450 m_responseTimestamp = currentTime(); 467 m_responseTimestamp = currentTime();
451 468
452 if (!m_revalidatingRequest.isNull()) { 469 if (!m_revalidatingRequest.isNull()) {
453 if (response.httpStatusCode() == 304) { 470 if (response.httpStatusCode() == 304) {
454 revalidationSucceeded(response); 471 revalidationSucceeded(response);
455 return; 472 return;
456 } 473 }
457 revalidationFailed(); 474 revalidationFailed();
458 } 475 }
459 476 // If there's no boundary, just handle the request normally. In the gecko
Nate Chapin 2016/02/25 22:07:53 This comment looks like very outdated.
yhirano 2016/02/27 01:27:45 Deleted.
477 // code, nsMultiMixedConv::OnStartRequest throws an exception.
478 if (response.isMultipart() && !response.multipartBoundary().isEmpty() && (m_ type == Resource::Image || m_type == Resource::MainResource) && !m_multipartPars er)
479 m_multipartParser = new MultipartImageResourceParser(response, response. multipartBoundary(), this);
460 setResponse(response); 480 setResponse(response);
461 String encoding = response.textEncodingName(); 481 String encoding = response.textEncodingName();
462 if (!encoding.isNull()) 482 if (!encoding.isNull())
463 setEncoding(encoding); 483 setEncoding(encoding);
464 } 484 }
465 485
466 void Resource::setSerializedCachedMetadata(const char* data, size_t size) 486 void Resource::setSerializedCachedMetadata(const char* data, size_t size)
467 { 487 {
468 // We only expect to receive cached metadata from the platform once. 488 // We only expect to receive cached metadata from the platform once.
469 // If this triggers, it indicates an efficiency problem which is most 489 // If this triggers, it indicates an efficiency problem which is most
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 529
510 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() 530 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr()
511 { 531 {
512 #if ENABLE(OILPAN) 532 #if ENABLE(OILPAN)
513 return this; 533 return this;
514 #else 534 #else
515 return m_weakPtrFactory.createWeakPtr(); 535 return m_weakPtrFactory.createWeakPtr();
516 #endif 536 #endif
517 } 537 }
518 538
539 bool Resource::isMultipartImage() const
540 {
541 return m_multipartParser;
542 }
543
544 void Resource::didReceiveResponse(const ResourceResponse& response)
545 {
546 ASSERT(isMultipartImage());
547 responseReceived(response, nullptr);
548 if (response.isMultipartPayload()) {
549 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once.
550 // After the first multipart section is complete, signal to delegates th at this load is "finished"
551 m_loader->fetcher()->subresourceLoaderFinishedLoadingOnePart(m_loader);
Nate Chapin 2016/02/25 22:07:53 Instead of Exposing ResourceLoader::fetcher(), can
yhirano 2016/02/27 01:27:45 Done.
552 if (m_loader)
553 m_loader->didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEnc odedDataLength);
554 }
555 }
556
557 void Resource::didReceiveData(const char* bytes, size_t size)
Nate Chapin 2016/02/25 22:07:53 I agree with hiroshige's comment on https://codere
yhirano 2016/02/27 01:27:45 Done.
558 {
559 ASSERT(isMultipartImage());
560 appendDataInternal(bytes, size);
561 }
562
519 String Resource::reasonNotDeletable() const 563 String Resource::reasonNotDeletable() const
520 { 564 {
521 StringBuilder builder; 565 StringBuilder builder;
522 if (hasClients()) { 566 if (hasClients()) {
523 builder.append("hasClients("); 567 builder.append("hasClients(");
524 builder.appendNumber(m_clients.size()); 568 builder.appendNumber(m_clients.size());
525 if (!m_clientsAwaitingCallback.isEmpty()) { 569 if (!m_clientsAwaitingCallback.isEmpty()) {
526 builder.append(", AwaitingCallback="); 570 builder.append(", AwaitingCallback=");
527 builder.appendNumber(m_clientsAwaitingCallback.size()); 571 builder.appendNumber(m_clientsAwaitingCallback.size());
528 } 572 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 706
663 void Resource::allClientsRemoved() 707 void Resource::allClientsRemoved()
664 { 708 {
665 if (!m_loader) 709 if (!m_loader)
666 return; 710 return;
667 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this )) 711 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this ))
668 cancelTimerFired(&m_cancelTimer); 712 cancelTimerFired(&m_cancelTimer);
669 else if (!m_cancelTimer.isActive()) 713 else if (!m_cancelTimer.isActive())
670 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); 714 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE);
671 715
716 if (m_multipartParser)
717 m_multipartParser->cancel();
672 unlock(); 718 unlock();
673 } 719 }
674 720
675 void Resource::cancelTimerFired(Timer<Resource>* timer) 721 void Resource::cancelTimerFired(Timer<Resource>* timer)
676 { 722 {
677 ASSERT_UNUSED(timer, timer == &m_cancelTimer); 723 ASSERT_UNUSED(timer, timer == &m_cancelTimer);
678 if (hasClients() || !m_loader) 724 if (hasClients() || !m_loader)
679 return; 725 return;
680 RefPtrWillBeRawPtr<Resource> protect(this); 726 RefPtrWillBeRawPtr<Resource> protect(this);
681 m_loader->cancelIfNotFinishing(); 727 m_loader->cancelIfNotFinishing();
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 case Resource::Media: 1157 case Resource::Media:
1112 return "Media"; 1158 return "Media";
1113 case Resource::Manifest: 1159 case Resource::Manifest:
1114 return "Manifest"; 1160 return "Manifest";
1115 } 1161 }
1116 ASSERT_NOT_REACHED(); 1162 ASSERT_NOT_REACHED();
1117 return "Unknown"; 1163 return "Unknown";
1118 } 1164 }
1119 1165
1120 } // namespace blink 1166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698