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

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: 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
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 26 matching lines...) Expand all
37 #include "core/platform/SharedBuffer.h" 37 #include "core/platform/SharedBuffer.h"
38 #include "core/platform/chromium/support/WrappedResourceRequest.h" 38 #include "core/platform/chromium/support/WrappedResourceRequest.h"
39 #include "core/platform/chromium/support/WrappedResourceResponse.h" 39 #include "core/platform/chromium/support/WrappedResourceResponse.h"
40 #include "core/platform/network/ResourceError.h" 40 #include "core/platform/network/ResourceError.h"
41 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
42 #include "public/platform/WebData.h" 42 #include "public/platform/WebData.h"
43 #include "public/platform/WebURLError.h" 43 #include "public/platform/WebURLError.h"
44 #include "public/platform/WebURLRequest.h" 44 #include "public/platform/WebURLRequest.h"
45 #include "public/platform/WebURLResponse.h" 45 #include "public/platform/WebURLResponse.h"
46 #include "wtf/Assertions.h" 46 #include "wtf/Assertions.h"
47 #include "wtf/CurrentTime.h"
abarth-chromium 2013/09/13 23:48:28 Is this still needed?
47 48
48 namespace WebCore { 49 namespace WebCore {
49 50
50 ResourceLoader::RequestCountTracker::RequestCountTracker(ResourceLoaderHost* hos t, Resource* resource) 51 ResourceLoader::RequestCountTracker::RequestCountTracker(ResourceLoaderHost* hos t, Resource* resource)
51 : m_host(host) 52 : m_host(host)
52 , m_resource(resource) 53 , m_resource(resource)
53 { 54 {
54 m_host->incrementRequestCount(m_resource); 55 m_host->incrementRequestCount(m_resource);
55 } 56 }
56 57
57 ResourceLoader::RequestCountTracker::~RequestCountTracker() 58 ResourceLoader::RequestCountTracker::~RequestCountTracker()
58 { 59 {
59 m_host->decrementRequestCount(m_resource); 60 m_host->decrementRequestCount(m_resource);
60 } 61 }
61 62
62 PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost* host, Reso urce* resource, const ResourceRequest& request, const ResourceLoaderOptions& opt ions) 63 PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderHost* host, Reso urce* resource, const ResourceRequest& request, const ResourceLoaderOptions& opt ions)
63 { 64 {
64 RefPtr<ResourceLoader> loader(adoptRef(new ResourceLoader(host, resource, op tions))); 65 RefPtr<ResourceLoader> loader(adoptRef(new ResourceLoader(host, resource, op tions)));
65 loader->init(request); 66 loader->init(request);
66 loader->start();
Nate Chapin 2013/09/12 23:28:46 This is moved to Resource.cpp so that Resource::m_
67 return loader.release(); 67 return loader.release();
68 } 68 }
69 69
70 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options) 70 ResourceLoader::ResourceLoader(ResourceLoaderHost* host, Resource* resource, con st ResourceLoaderOptions& options)
71 : m_host(host) 71 : m_host(host)
72 , m_notifiedLoadComplete(false) 72 , m_notifiedLoadComplete(false)
73 , m_defersLoading(host->defersLoading()) 73 , m_defersLoading(host->defersLoading())
74 , m_options(options) 74 , m_options(options)
75 , m_resource(resource) 75 , m_resource(resource)
76 , m_state(Initialized) 76 , m_state(Initialized)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 void ResourceLoader::start() 127 void ResourceLoader::start()
128 { 128 {
129 ASSERT(!m_loader); 129 ASSERT(!m_loader);
130 ASSERT(!m_request.isNull()); 130 ASSERT(!m_request.isNull());
131 ASSERT(m_deferredRequest.isNull()); 131 ASSERT(m_deferredRequest.isNull());
132 132
133 m_host->willStartLoadingResource(m_request); 133 m_host->willStartLoadingResource(m_request);
134 134
135 if (m_options.synchronousPolicy == RequestSynchronously) {
136 requestSynchronously();
137 return;
138 }
139
135 if (m_defersLoading) { 140 if (m_defersLoading) {
136 m_deferredRequest = m_request; 141 m_deferredRequest = m_request;
137 return; 142 return;
138 } 143 }
139 144
140 if (m_state == Terminated) 145 if (m_state == Terminated)
141 return; 146 return;
142 147
143 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); 148 RELEASE_ASSERT(m_connectionState == ConnectionStateNew);
144 m_connectionState = ConnectionStateStarted; 149 m_connectionState = ConnectionStateStarted;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 386 }
382 387
383 releaseResources(); 388 releaseResources();
384 } 389 }
385 390
386 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const 391 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const
387 { 392 {
388 return m_host->isLoadedBy(loader); 393 return m_host->isLoadedBy(loader);
389 } 394 }
390 395
391 void ResourceLoader::loadResourceSynchronously(const ResourceRequest& request, S toredCredentials storedCredentials, ResourceError& error, ResourceResponse& resp onse, Vector<char>& data) 396 void ResourceLoader::requestSynchronously()
392 { 397 {
393 OwnPtr<WebKit::WebURLLoader> loader = adoptPtr(WebKit::Platform::current()-> createURLLoader()); 398 OwnPtr<WebKit::WebURLLoader> loader = adoptPtr(WebKit::Platform::current()-> createURLLoader());
394 ASSERT(loader); 399 ASSERT(loader);
395 400
396 WebKit::WrappedResourceRequest requestIn(request); 401 RELEASE_ASSERT(m_connectionState == ConnectionStateNew);
397 requestIn.setAllowStoredCredentials(storedCredentials == AllowStoredCredenti als); 402 m_connectionState = ConnectionStateStarted;
398 WebKit::WrappedResourceResponse responseOut(response); 403
404 WebKit::WrappedResourceRequest requestIn(m_request);
405 requestIn.setAllowStoredCredentials(m_options.allowCredentials == AllowStore dCredentials);
406 WebKit::WebURLResponse responseOut;
407 responseOut.initialize();
399 WebKit::WebURLError errorOut; 408 WebKit::WebURLError errorOut;
400 WebKit::WebData dataOut; 409 WebKit::WebData dataOut;
401
402 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); 410 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut);
403 411 if (errorOut.reason) {
404 error = errorOut; 412 didFail(0, errorOut);
405 data.clear(); 413 return;
406 RefPtr<SharedBuffer> buffer = dataOut; 414 }
407 if (buffer) 415 didReceiveResponse(0, responseOut);
408 buffer->moveTo(data); 416 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo();
417 didReceiveData(0, dataOut.data(), dataOut.size(), resourceLoadInfo ? resourc eLoadInfo->encodedDataLength : -1);
abarth-chromium 2013/09/13 23:48:28 Does this introduce a memcpy? Previously, we were
Nate Chapin 2013/09/16 20:32:50 Yeah, I think it will memcpy. I guess we could exp
418 didFinishLoading(0, monotonicallyIncreasingTime());
409 } 419 }
410 420
411 } 421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698