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

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

Issue 23702040: Send synchronous loads through the cache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 7 years, 3 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
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderOptions.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) 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 ResourceLoader::RequestCountTracker::~RequestCountTracker() 57 ResourceLoader::RequestCountTracker::~RequestCountTracker()
58 { 58 {
59 m_host->decrementRequestCount(m_resource); 59 m_host->decrementRequestCount(m_resource);
60 } 60 }
61 61
62 PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost* host, Reso urce* resource, const ResourceRequest& request, const ResourceLoaderOptions& opt ions) 62 PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost* host, Reso urce* resource, const ResourceRequest& request, const ResourceLoaderOptions& opt ions)
63 { 63 {
64 RefPtr<ResourceLoader> loader(adoptRef(new ResourceLoader(host, resource, op tions))); 64 RefPtr<ResourceLoader> loader(adoptRef(new ResourceLoader(host, resource, op tions)));
65 loader->init(request); 65 loader->init(request);
66 loader->start();
67 return loader.release(); 66 return loader.release();
68 } 67 }
69 68
70 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options) 69 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options)
71 : m_host(host) 70 : m_host(host)
72 , m_notifiedLoadComplete(false) 71 , m_notifiedLoadComplete(false)
73 , m_defersLoading(host->defersLoading()) 72 , m_defersLoading(host->defersLoading())
74 , m_options(options) 73 , m_options(options)
75 , m_resource(resource) 74 , m_resource(resource)
76 , m_state(Initialized) 75 , m_state(Initialized)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 124 }
126 125
127 void ResourceLoader::start() 126 void ResourceLoader::start()
128 { 127 {
129 ASSERT(!m_loader); 128 ASSERT(!m_loader);
130 ASSERT(!m_request.isNull()); 129 ASSERT(!m_request.isNull());
131 ASSERT(m_deferredRequest.isNull()); 130 ASSERT(m_deferredRequest.isNull());
132 131
133 m_host->willStartLoadingResource(m_request); 132 m_host->willStartLoadingResource(m_request);
134 133
134 if (m_options.synchronousPolicy == RequestSynchronously) {
135 requestSynchronously();
136 return;
137 }
138
135 if (m_defersLoading) { 139 if (m_defersLoading) {
136 m_deferredRequest = m_request; 140 m_deferredRequest = m_request;
137 return; 141 return;
138 } 142 }
139 143
140 if (m_state == Terminated) 144 if (m_state == Terminated)
141 return; 145 return;
142 146
143 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); 147 RELEASE_ASSERT(m_connectionState == ConnectionStateNew);
144 m_connectionState = ConnectionStateStarted; 148 m_connectionState = ConnectionStateStarted;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 385 }
382 386
383 releaseResources(); 387 releaseResources();
384 } 388 }
385 389
386 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const 390 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const
387 { 391 {
388 return m_host->isLoadedBy(loader); 392 return m_host->isLoadedBy(loader);
389 } 393 }
390 394
391 void ResourceLoader::loadResourceSynchronously(const ResourceRequest& request, S toredCredentials storedCredentials, ResourceError& error, ResourceResponse& resp onse, Vector<char>& data) 395 void ResourceLoader::requestSynchronously()
392 { 396 {
393 OwnPtr<WebKit::WebURLLoader> loader = adoptPtr(WebKit::Platform::current()-> createURLLoader()); 397 OwnPtr<WebKit::WebURLLoader> loader = adoptPtr(WebKit::Platform::current()-> createURLLoader());
394 ASSERT(loader); 398 ASSERT(loader);
395 399
396 WebKit::WrappedResourceRequest requestIn(request); 400 RELEASE_ASSERT(m_connectionState == ConnectionStateNew);
397 requestIn.setAllowStoredCredentials(storedCredentials == AllowStoredCredenti als); 401 m_connectionState = ConnectionStateStarted;
398 WebKit::WrappedResourceResponse responseOut(response); 402
403 WebKit::WrappedResourceRequest requestIn(m_request);
404 requestIn.setAllowStoredCredentials(m_options.allowCredentials == AllowStore dCredentials);
405 WebKit::WebURLResponse responseOut;
406 responseOut.initialize();
399 WebKit::WebURLError errorOut; 407 WebKit::WebURLError errorOut;
400 WebKit::WebData dataOut; 408 WebKit::WebData dataOut;
401
402 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); 409 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut);
403 410 if (errorOut.reason) {
404 error = errorOut; 411 didFail(0, errorOut);
405 data.clear(); 412 return;
406 RefPtr<SharedBuffer> buffer = dataOut; 413 }
407 if (buffer) 414 didReceiveResponse(0, responseOut);
408 buffer->moveTo(data); 415 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo();
416 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL oadInfo ? resourceLoadInfo->encodedDataLength : -1, m_options);
417 m_resource->setResourceBuffer(dataOut);
418 didFinishLoading(0, responseOut.responseTime());
409 } 419 }
410 420
411 } 421 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderOptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698