| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 { | 51 { |
| 52 return new ResourceLoader(fetcher, resource); | 52 return new ResourceLoader(fetcher, resource); |
| 53 } | 53 } |
| 54 | 54 |
| 55 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 55 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 56 : m_fetcher(fetcher) | 56 : m_fetcher(fetcher) |
| 57 , m_resource(resource) | 57 , m_resource(resource) |
| 58 { | 58 { |
| 59 ASSERT(m_resource); | 59 ASSERT(m_resource); |
| 60 ASSERT(m_fetcher); | 60 ASSERT(m_fetcher); |
| 61 m_resource->setLoader(this); |
| 61 } | 62 } |
| 62 | 63 |
| 63 ResourceLoader::~ResourceLoader() | 64 ResourceLoader::~ResourceLoader() |
| 64 { | 65 { |
| 65 DCHECK(!m_loader); | 66 DCHECK(!m_loader); |
| 66 } | 67 } |
| 67 | 68 |
| 68 DEFINE_TRACE(ResourceLoader) | 69 DEFINE_TRACE(ResourceLoader) |
| 69 { | 70 { |
| 70 visitor->trace(m_fetcher); | 71 visitor->trace(m_fetcher); |
| 71 visitor->trace(m_resource); | 72 visitor->trace(m_resource); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ResourceLoader::start(ResourceRequest& request) | 75 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) |
| 75 { | 76 { |
| 76 ASSERT(!m_loader); | 77 ASSERT(!m_loader); |
| 78 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { |
| 79 cancel(); |
| 80 return; |
| 81 } |
| 77 | 82 |
| 78 m_fetcher->willStartLoadingResource(m_resource.get(), this, request); | |
| 79 m_loader = adoptPtr(Platform::current()->createURLLoader()); | 83 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 80 m_loader->setDefersLoading(m_fetcher->defersLoading()); | 84 m_loader->setDefersLoading(defersLoading); |
| 81 ASSERT(m_loader); | 85 ASSERT(m_loader); |
| 82 m_loader->setLoadingTaskRunner(m_fetcher->loadingTaskRunner()); | 86 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
| 83 | 87 |
| 84 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 88 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 85 requestSynchronously(request); | 89 requestSynchronously(request); |
| 86 else | 90 else |
| 87 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 91 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void ResourceLoader::setDefersLoading(bool defers) | 94 void ResourceLoader::setDefersLoading(bool defers) |
| 91 { | 95 { |
| 92 ASSERT(m_loader); | 96 ASSERT(m_loader); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 m_loader.reset(); | 213 m_loader.reset(); |
| 210 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); | 214 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); |
| 211 } | 215 } |
| 212 | 216 |
| 213 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) | 217 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) |
| 214 { | 218 { |
| 215 m_loader.reset(); | 219 m_loader.reset(); |
| 216 m_fetcher->didFailLoading(m_resource.get(), error); | 220 m_fetcher->didFailLoading(m_resource.get(), error); |
| 217 } | 221 } |
| 218 | 222 |
| 219 void ResourceLoader::requestSynchronously(ResourceRequest& request) | 223 void ResourceLoader::requestSynchronously(const ResourceRequest& request) |
| 220 { | 224 { |
| 221 // downloadToFile is not supported for synchronous requests. | 225 // downloadToFile is not supported for synchronous requests. |
| 222 ASSERT(!request.downloadToFile()); | 226 ASSERT(!request.downloadToFile()); |
| 223 ASSERT(m_loader); | 227 ASSERT(m_loader); |
| 224 | 228 DCHECK(request.priority() == ResourceLoadPriorityHighest); |
| 225 // Synchronous requests should always be max priority, lest they hang the re
nderer. | |
| 226 request.setPriority(ResourceLoadPriorityHighest); | |
| 227 | |
| 228 if (m_fetcher->defersLoading()) { | |
| 229 cancel(); | |
| 230 return; | |
| 231 } | |
| 232 | 229 |
| 233 WrappedResourceRequest requestIn(request); | 230 WrappedResourceRequest requestIn(request); |
| 234 WebURLResponse responseOut; | 231 WebURLResponse responseOut; |
| 235 responseOut.initialize(); | 232 responseOut.initialize(); |
| 236 WebURLError errorOut; | 233 WebURLError errorOut; |
| 237 WebData dataOut; | 234 WebData dataOut; |
| 238 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); | 235 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); |
| 239 | 236 |
| 240 // A message dispatched while synchronously fetching the resource | 237 // A message dispatched while synchronously fetching the resource |
| 241 // can bring about the cancellation of this load. | 238 // can bring about the cancellation of this load. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 256 // empty buffer is a noop in most cases, but is destructive in the case of | 253 // empty buffer is a noop in most cases, but is destructive in the case of |
| 257 // a 304, where it will overwrite the cached data we should be reusing. | 254 // a 304, where it will overwrite the cached data we should be reusing. |
| 258 if (dataOut.size()) { | 255 if (dataOut.size()) { |
| 259 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 256 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
| 260 m_resource->setResourceBuffer(dataOut); | 257 m_resource->setResourceBuffer(dataOut); |
| 261 } | 258 } |
| 262 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 259 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 263 } | 260 } |
| 264 | 261 |
| 265 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |