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

Side by Side Diff: Source/core/fetch/ResourceLoader.cpp

Issue 414423003: Oilpan: Prepare to move ResourceLoader and ResourceLoaderSet to Oilpan heap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: FINAL Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 m_host->decrementRequestCount(m_resource); 61 m_host->decrementRequestCount(m_resource);
62 } 62 }
63 63
64 ResourceLoader::RequestCountTracker::RequestCountTracker(const RequestCountTrack er& other) 64 ResourceLoader::RequestCountTracker::RequestCountTracker(const RequestCountTrack er& other)
65 { 65 {
66 m_host = other.m_host; 66 m_host = other.m_host;
67 m_resource = other.m_resource; 67 m_resource = other.m_resource;
68 m_host->incrementRequestCount(m_resource); 68 m_host->incrementRequestCount(m_resource);
69 } 69 }
70 70
71 PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost* host, Reso urce* resource, const ResourceRequest& request, const ResourceLoaderOptions& opt ions) 71 PassRefPtrWillBeRawPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost * host, Resource* resource, const ResourceRequest& request, const ResourceLoader Options& options)
72 { 72 {
73 RefPtr<ResourceLoader> loader(adoptRef(new ResourceLoader(host, resource, op tions))); 73 RefPtrWillBeRawPtr<ResourceLoader> loader(adoptRefWillBeNoop(new ResourceLoa der(host, resource, options)));
74 loader->init(request); 74 loader->init(request);
75 return loader.release(); 75 return loader.release();
76 } 76 }
77 77
78 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options) 78 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options)
79 : m_host(host) 79 : m_host(host)
80 , m_notifiedLoadComplete(false) 80 , m_notifiedLoadComplete(false)
81 , m_defersLoading(host->defersLoading()) 81 , m_defersLoading(host->defersLoading())
82 , m_options(options) 82 , m_options(options)
83 , m_resource(resource) 83 , m_resource(resource)
84 , m_state(Initialized) 84 , m_state(Initialized)
85 , m_connectionState(ConnectionStateNew) 85 , m_connectionState(ConnectionStateNew)
86 , m_requestCountTracker(adoptPtr(new RequestCountTracker(host, resource))) 86 , m_requestCountTracker(adoptPtr(new RequestCountTracker(host, resource)))
87 { 87 {
88 } 88 }
89 89
90 ResourceLoader::~ResourceLoader() 90 ResourceLoader::~ResourceLoader()
91 { 91 {
92 ASSERT(m_state == Terminated); 92 ASSERT(m_state == Terminated);
93 } 93 }
94 94
95 void ResourceLoader::trace(Visitor* visitor)
96 {
97 visitor->trace(m_host);
98 visitor->trace(m_resource);
99 }
100
95 void ResourceLoader::releaseResources() 101 void ResourceLoader::releaseResources()
96 { 102 {
97 ASSERT(m_state != Terminated); 103 ASSERT(m_state != Terminated);
98 ASSERT(m_notifiedLoadComplete); 104 ASSERT(m_notifiedLoadComplete);
99 m_requestCountTracker.clear(); 105 m_requestCountTracker.clear();
100 m_host->didLoadResource(m_resource); 106 m_host->didLoadResource(m_resource);
101 if (m_state == Terminated) 107 if (m_state == Terminated)
102 return; 108 return;
103 m_resource->clearLoader(); 109 m_resource->clearLoader();
104 m_host->willTerminateResourceLoader(this); 110 m_host->willTerminateResourceLoader(this);
105 111
106 ASSERT(m_state != Terminated); 112 ASSERT(m_state != Terminated);
107 113
108 // It's possible that when we release the loader, it will be 114 // It's possible that when we release the loader, it will be
109 // deallocated and release the last reference to this object. 115 // deallocated and release the last reference to this object.
110 // We need to retain to avoid accessing the object after it 116 // We need to retain to avoid accessing the object after it
111 // has been deallocated and also to avoid reentering this method. 117 // has been deallocated and also to avoid reentering this method.
112 RefPtr<ResourceLoader> protector(this); 118 RefPtrWillBeRawPtr<ResourceLoader> protector(this);
113 119
114 m_host.clear(); 120 m_host.clear();
115 m_state = Terminated; 121 m_state = Terminated;
116 122
117 if (m_loader) { 123 if (m_loader) {
118 m_loader->cancel(); 124 m_loader->cancel();
119 m_loader.clear(); 125 m_loader.clear();
120 } 126 }
121 127
122 m_deferredRequest = ResourceRequest(); 128 m_deferredRequest = ResourceRequest();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // threaded data receiver if it signals that it got successfully 199 // threaded data receiver if it signals that it got successfully
194 // attached. 200 // attached.
195 blink::WebThreadedDataReceiver* rawThreadedDataReceiver = threadedDataRe ceiver.leakPtr(); 201 blink::WebThreadedDataReceiver* rawThreadedDataReceiver = threadedDataRe ceiver.leakPtr();
196 if (!m_loader->attachThreadedDataReceiver(rawThreadedDataReceiver)) 202 if (!m_loader->attachThreadedDataReceiver(rawThreadedDataReceiver))
197 delete rawThreadedDataReceiver; 203 delete rawThreadedDataReceiver;
198 } 204 }
199 } 205 }
200 206
201 void ResourceLoader::didDownloadData(blink::WebURLLoader*, int length, int encod edDataLength) 207 void ResourceLoader::didDownloadData(blink::WebURLLoader*, int length, int encod edDataLength)
202 { 208 {
203 RefPtr<ResourceLoader> protect(this); 209 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
204 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); 210 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse);
205 m_host->didDownloadData(m_resource, length, encodedDataLength); 211 m_host->didDownloadData(m_resource, length, encodedDataLength);
206 m_resource->didDownloadData(length); 212 m_resource->didDownloadData(length);
207 } 213 }
208 214
209 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64 encodedDat aLength) 215 void ResourceLoader::didFinishLoadingOnePart(double finishTime, int64 encodedDat aLength)
210 { 216 {
211 // If load has been cancelled after finishing (which could happen with a 217 // If load has been cancelled after finishing (which could happen with a
212 // JavaScript that changes the window location), do nothing. 218 // JavaScript that changes the window location), do nothing.
213 if (m_state == Terminated) 219 if (m_state == Terminated)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return; 252 return;
247 if (m_state == Finishing) { 253 if (m_state == Finishing) {
248 releaseResources(); 254 releaseResources();
249 return; 255 return;
250 } 256 }
251 257
252 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_request.url()) : error; 258 ResourceError nonNullError = error.isNull() ? ResourceError::cancelledError( m_request.url()) : error;
253 259
254 // This function calls out to clients at several points that might do 260 // This function calls out to clients at several points that might do
255 // something that causes the last reference to this object to go away. 261 // something that causes the last reference to this object to go away.
256 RefPtr<ResourceLoader> protector(this); 262 RefPtrWillBeRawPtr<ResourceLoader> protector(this);
257 263
258 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().stri ng().latin1().data()); 264 WTF_LOG(ResourceLoading, "Cancelled load of '%s'.\n", m_resource->url().stri ng().latin1().data());
259 if (m_state == Initialized) 265 if (m_state == Initialized)
260 m_state = Finishing; 266 m_state = Finishing;
261 m_resource->setResourceError(nonNullError); 267 m_resource->setResourceError(nonNullError);
262 268
263 if (m_loader) { 269 if (m_loader) {
264 m_connectionState = ConnectionStateCanceled; 270 m_connectionState = ConnectionStateCanceled;
265 m_loader->cancel(); 271 m_loader->cancel();
266 m_loader.clear(); 272 m_loader.clear();
267 } 273 }
268 274
269 if (!m_notifiedLoadComplete) { 275 if (!m_notifiedLoadComplete) {
270 m_notifiedLoadComplete = true; 276 m_notifiedLoadComplete = true;
271 m_host->didFailLoading(m_resource, nonNullError); 277 m_host->didFailLoading(m_resource, nonNullError);
272 } 278 }
273 279
274 if (m_state == Finishing) 280 if (m_state == Finishing)
275 m_resource->error(Resource::LoadError); 281 m_resource->error(Resource::LoadError);
276 if (m_state != Terminated) 282 if (m_state != Terminated)
277 releaseResources(); 283 releaseResources();
278 } 284 }
279 285
280 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedRequest, const blink::WebURLResponse& passedRedirectResponse) 286 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest& passedRequest, const blink::WebURLResponse& passedRedirectResponse)
281 { 287 {
282 RefPtr<ResourceLoader> protect(this); 288 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
283 289
284 ResourceRequest& request(applyOptions(passedRequest.toMutableResourceRequest ())); 290 ResourceRequest& request(applyOptions(passedRequest.toMutableResourceRequest ()));
285 291
286 // FIXME: We should have a real context for redirect requests. Currently, we don't: see WebURLLoaderImpl::Context::OnReceivedRedirect in content/. 292 // FIXME: We should have a real context for redirect requests. Currently, we don't: see WebURLLoaderImpl::Context::OnReceivedRedirect in content/.
287 request.setRequestContext(blink::WebURLRequest::RequestContextInternal); 293 request.setRequestContext(blink::WebURLRequest::RequestContextInternal);
288 294
289 ASSERT(!request.isNull()); 295 ASSERT(!request.isNull());
290 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse()); 296 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe sponse());
291 ASSERT(!redirectResponse.isNull()); 297 ASSERT(!redirectResponse.isNull());
292 if (!m_host->canAccessRedirect(m_resource, request, redirectResponse, m_opti ons)) { 298 if (!m_host->canAccessRedirect(m_resource, request, redirectResponse, m_opti ons)) {
(...skipping 16 matching lines...) Expand all
309 void ResourceLoader::didReceiveCachedMetadata(blink::WebURLLoader*, const char* data, int length) 315 void ResourceLoader::didReceiveCachedMetadata(blink::WebURLLoader*, const char* data, int length)
310 { 316 {
311 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); 317 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData);
312 ASSERT(m_state == Initialized); 318 ASSERT(m_state == Initialized);
313 m_resource->setSerializedCachedMetadata(data, length); 319 m_resource->setSerializedCachedMetadata(data, length);
314 } 320 }
315 321
316 void ResourceLoader::didSendData(blink::WebURLLoader*, unsigned long long bytesS ent, unsigned long long totalBytesToBeSent) 322 void ResourceLoader::didSendData(blink::WebURLLoader*, unsigned long long bytesS ent, unsigned long long totalBytesToBeSent)
317 { 323 {
318 ASSERT(m_state == Initialized); 324 ASSERT(m_state == Initialized);
319 RefPtr<ResourceLoader> protect(this); 325 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
320 m_resource->didSendData(bytesSent, totalBytesToBeSent); 326 m_resource->didSendData(bytesSent, totalBytesToBeSent);
321 } 327 }
322 328
323 bool ResourceLoader::responseNeedsAccessControlCheck() const 329 bool ResourceLoader::responseNeedsAccessControlCheck() const
324 { 330 {
325 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required. 331 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required.
326 return m_options.corsEnabled == IsCORSEnabled; 332 return m_options.corsEnabled == IsCORSEnabled;
327 } 333 }
328 334
329 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR LResponse& response) 335 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR LResponse& response)
(...skipping 20 matching lines...) Expand all
350 m_resource->setResponse(resourceResponse); 356 m_resource->setResponse(resourceResponse);
351 if (!m_host->canAccessResource(resource, m_options.securityOrigin.get(), response.url())) { 357 if (!m_host->canAccessResource(resource, m_options.securityOrigin.get(), response.url())) {
352 m_host->didReceiveResponse(m_resource, resourceResponse); 358 m_host->didReceiveResponse(m_resource, resourceResponse);
353 cancel(); 359 cancel();
354 return; 360 return;
355 } 361 }
356 } 362 }
357 363
358 // Reference the object in this method since the additional processing can d o 364 // Reference the object in this method since the additional processing can d o
359 // anything including removing the last reference to this object. 365 // anything including removing the last reference to this object.
360 RefPtr<ResourceLoader> protect(this); 366 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
361 m_resource->responseReceived(resourceResponse); 367 m_resource->responseReceived(resourceResponse);
362 if (m_state == Terminated) 368 if (m_state == Terminated)
363 return; 369 return;
364 370
365 m_host->didReceiveResponse(m_resource, resourceResponse); 371 m_host->didReceiveResponse(m_resource, resourceResponse);
366 372
367 if (response.toResourceResponse().isMultipart()) { 373 if (response.toResourceResponse().isMultipart()) {
368 // We don't count multiParts in a ResourceFetcher's request count 374 // We don't count multiParts in a ResourceFetcher's request count
369 m_requestCountTracker.clear(); 375 m_requestCountTracker.clear();
370 if (!m_resource->isImage()) { 376 if (!m_resource->isImage()) {
(...skipping 26 matching lines...) Expand all
397 m_connectionState = ConnectionStateReceivingData; 403 m_connectionState = ConnectionStateReceivingData;
398 404
399 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message 405 // It is possible to receive data on uninitialized resources if it had an er ror status code, and we are running a nested message
400 // loop. When this occurs, ignoring the data is the correct action. 406 // loop. When this occurs, ignoring the data is the correct action.
401 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn oreHTTPStatusCodeErrors()) 407 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn oreHTTPStatusCodeErrors())
402 return; 408 return;
403 ASSERT(m_state == Initialized); 409 ASSERT(m_state == Initialized);
404 410
405 // Reference the object in this method since the additional processing can d o 411 // Reference the object in this method since the additional processing can d o
406 // anything including removing the last reference to this object. 412 // anything including removing the last reference to this object.
407 RefPtr<ResourceLoader> protect(this); 413 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
408 414
409 // FIXME: If we get a resource with more than 2B bytes, this code won't do t he right thing. 415 // FIXME: If we get a resource with more than 2B bytes, this code won't do t he right thing.
410 // However, with today's computers and networking speeds, this won't happen in practice. 416 // However, with today's computers and networking speeds, this won't happen in practice.
411 // Could be an issue with a giant local file. 417 // Could be an issue with a giant local file.
412 m_host->didReceiveData(m_resource, data, length, encodedDataLength); 418 m_host->didReceiveData(m_resource, data, length, encodedDataLength);
413 m_resource->appendData(data, length); 419 m_resource->appendData(data, length);
414 } 420 }
415 421
416 void ResourceLoader::didFinishLoading(blink::WebURLLoader*, double finishTime, i nt64 encodedDataLength) 422 void ResourceLoader::didFinishLoading(blink::WebURLLoader*, double finishTime, i nt64 encodedDataLength)
417 { 423 {
418 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData); 424 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con nectionState == ConnectionStateReceivingData);
419 m_connectionState = ConnectionStateFinishedLoading; 425 m_connectionState = ConnectionStateFinishedLoading;
420 if (m_state != Initialized) 426 if (m_state != Initialized)
421 return; 427 return;
422 ASSERT(m_state != Terminated); 428 ASSERT(m_state != Terminated);
423 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data()); 429 WTF_LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1 ().data());
424 430
425 RefPtr<ResourceLoader> protect(this); 431 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
426 ResourcePtr<Resource> protectResource(m_resource); 432 ResourcePtr<Resource> protectResource(m_resource);
427 m_state = Finishing; 433 m_state = Finishing;
428 didFinishLoadingOnePart(finishTime, encodedDataLength); 434 didFinishLoadingOnePart(finishTime, encodedDataLength);
429 m_resource->finish(finishTime); 435 m_resource->finish(finishTime);
430 436
431 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release 437 // If the load has been cancelled by a delegate in response to didFinishLoad (), do not release
432 // the resources a second time, they have been released by cancel. 438 // the resources a second time, they have been released by cancel.
433 if (m_state == Terminated) 439 if (m_state == Terminated)
434 return; 440 return;
435 releaseResources(); 441 releaseResources();
436 } 442 }
437 443
438 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or) 444 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err or)
439 { 445 {
440 m_connectionState = ConnectionStateFailed; 446 m_connectionState = ConnectionStateFailed;
441 ASSERT(m_state != Terminated); 447 ASSERT(m_state != Terminated);
442 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data()); 448 WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string( ).latin1().data());
443 449
444 RefPtr<ResourceLoader> protect(this); 450 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
445 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); 451 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get());
446 ResourcePtr<Resource> protectResource(m_resource); 452 ResourcePtr<Resource> protectResource(m_resource);
447 m_state = Finishing; 453 m_state = Finishing;
448 m_resource->setResourceError(error); 454 m_resource->setResourceError(error);
449 455
450 if (!m_notifiedLoadComplete) { 456 if (!m_notifiedLoadComplete) {
451 m_notifiedLoadComplete = true; 457 m_notifiedLoadComplete = true;
452 m_host->didFailLoading(m_resource, error); 458 m_host->didFailLoading(m_resource, error);
453 } 459 }
454 460
(...skipping 11 matching lines...) Expand all
466 } 472 }
467 473
468 void ResourceLoader::requestSynchronously() 474 void ResourceLoader::requestSynchronously()
469 { 475 {
470 OwnPtr<blink::WebURLLoader> loader = adoptPtr(blink::Platform::current()->cr eateURLLoader()); 476 OwnPtr<blink::WebURLLoader> loader = adoptPtr(blink::Platform::current()->cr eateURLLoader());
471 ASSERT(loader); 477 ASSERT(loader);
472 478
473 // downloadToFile is not supported for synchronous requests. 479 // downloadToFile is not supported for synchronous requests.
474 ASSERT(!m_request.downloadToFile()); 480 ASSERT(!m_request.downloadToFile());
475 481
476 RefPtr<ResourceLoader> protect(this); 482 RefPtrWillBeRawPtr<ResourceLoader> protect(this);
477 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); 483 RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get());
478 ResourcePtr<Resource> protectResource(m_resource); 484 ResourcePtr<Resource> protectResource(m_resource);
479 485
480 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); 486 RELEASE_ASSERT(m_connectionState == ConnectionStateNew);
481 m_connectionState = ConnectionStateStarted; 487 m_connectionState = ConnectionStateStarted;
482 488
483 blink::WrappedResourceRequest requestIn(m_request); 489 blink::WrappedResourceRequest requestIn(m_request);
484 blink::WebURLResponse responseOut; 490 blink::WebURLResponse responseOut;
485 responseOut.initialize(); 491 responseOut.initialize();
486 blink::WebURLError errorOut; 492 blink::WebURLError errorOut;
(...skipping 13 matching lines...) Expand all
500 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 506 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
501 } 507 }
502 508
503 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const 509 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const
504 { 510 {
505 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 511 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
506 return request; 512 return request;
507 } 513 }
508 514
509 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698