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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchBlobDataConsumerHandle.cpp

Issue 1264453002: Split the constructor of ThreadableLoader into two methods (ctor and start()) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed pipes around non-variables in a comment Created 4 years, 10 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 5 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
6 6
7 #include "core/dom/ExecutionContext.h" 7 #include "core/dom/ExecutionContext.h"
8 #include "core/fetch/FetchInitiatorTypeNames.h" 8 #include "core/fetch/FetchInitiatorTypeNames.h"
9 #include "core/loader/ThreadableLoaderClient.h" 9 #include "core/loader/ThreadableLoaderClient.h"
10 #include "modules/fetch/CompositeDataConsumerHandle.h" 10 #include "modules/fetch/CompositeDataConsumerHandle.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 m_loader->cancel(); 76 m_loader->cancel();
77 m_loader.clear(); 77 m_loader.clear();
78 } 78 }
79 } 79 }
80 80
81 void start(ExecutionContext* executionContext) override 81 void start(ExecutionContext* executionContext) override
82 { 82 {
83 ASSERT(executionContext->isContextThread()); 83 ASSERT(executionContext->isContextThread());
84 ASSERT(!m_loader); 84 ASSERT(!m_loader);
85 85
86 KURL url = BlobURL::createPublicURL(executionContext->securityOrigin());
87 if (url.isEmpty()) {
88 m_updater->update(createUnexpectedErrorDataConsumerHandle());
89 return;
90 }
91 BlobRegistry::registerPublicBlobURL(executionContext->securityOrigin(), url, m_blobDataHandle);
92
86 m_loader = createLoader(executionContext, this); 93 m_loader = createLoader(executionContext, this);
87 if (!m_loader) 94 ASSERT(m_loader);
88 m_updater->update(createUnexpectedErrorDataConsumerHandle()); 95
96 ResourceRequest request(url);
97 request.setRequestContext(WebURLRequest::RequestContextInternal);
98 request.setUseStreamOnResponse(true);
99 m_loader->start(request);
89 } 100 }
90 101
91 private: 102 private:
92 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext , ThreadableLoaderClient* client) const 103 PassRefPtr<ThreadableLoader> createLoader(ExecutionContext* executionContext , ThreadableLoaderClient* client) const
93 { 104 {
94 KURL url = BlobURL::createPublicURL(executionContext->securityOrigin());
95 if (url.isEmpty()) {
96 return nullptr;
97 }
98 BlobRegistry::registerPublicBlobURL(executionContext->securityOrigin(), url, m_blobDataHandle);
99
100 ResourceRequest request(url);
101 request.setRequestContext(WebURLRequest::RequestContextInternal);
102 request.setUseStreamOnResponse(true);
103
104 ThreadableLoaderOptions options; 105 ThreadableLoaderOptions options;
105 options.preflightPolicy = ConsiderPreflight; 106 options.preflightPolicy = ConsiderPreflight;
106 options.crossOriginRequestPolicy = DenyCrossOriginRequests; 107 options.crossOriginRequestPolicy = DenyCrossOriginRequests;
107 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo licy; 108 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPo licy;
108 options.initiator = FetchInitiatorTypeNames::internal; 109 options.initiator = FetchInitiatorTypeNames::internal;
109 110
110 ResourceLoaderOptions resourceLoaderOptions; 111 ResourceLoaderOptions resourceLoaderOptions;
111 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; 112 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData;
112 113
113 return m_loaderFactory->create(*executionContext, client, request, optio ns, resourceLoaderOptions); 114 return m_loaderFactory->create(*executionContext, client, options, resou rceLoaderOptions);
114 } 115 }
115 116
116 // ThreadableLoaderClient 117 // ThreadableLoaderClient
117 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle> handle) override 118 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle> handle) override
118 { 119 {
119 ASSERT(!m_receivedResponse); 120 ASSERT(!m_receivedResponse);
120 m_receivedResponse = true; 121 m_receivedResponse = true;
121 if (!handle) { 122 if (!handle) {
122 // Here we assume WebURLLoader must return the response body as 123 // Here we assume WebURLLoader must return the response body as
123 // |WebDataConsumerHandle| since we call 124 // |WebDataConsumerHandle| since we call
(...skipping 29 matching lines...) Expand all
153 RefPtr<ThreadableLoader> m_loader; 154 RefPtr<ThreadableLoader> m_loader;
154 155
155 bool m_receivedResponse; 156 bool m_receivedResponse;
156 }; 157 };
157 158
158 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac tory { 159 class DefaultLoaderFactory final : public FetchBlobDataConsumerHandle::LoaderFac tory {
159 public: 160 public:
160 PassRefPtr<ThreadableLoader> create( 161 PassRefPtr<ThreadableLoader> create(
161 ExecutionContext& executionContext, 162 ExecutionContext& executionContext,
162 ThreadableLoaderClient* client, 163 ThreadableLoaderClient* client,
163 const ResourceRequest& request,
164 const ThreadableLoaderOptions& options, 164 const ThreadableLoaderOptions& options,
165 const ResourceLoaderOptions& resourceLoaderOptions) override 165 const ResourceLoaderOptions& resourceLoaderOptions) override
166 { 166 {
167 return ThreadableLoader::create(executionContext, client, request, optio ns, resourceLoaderOptions); 167 return ThreadableLoader::create(executionContext, client, options, resou rceLoaderOptions);
168 } 168 }
169 }; 169 };
170 170
171 } // namespace 171 } // namespace
172 172
173 // ReaderContext is referenced from FetchBlobDataConsumerHandle and 173 // ReaderContext is referenced from FetchBlobDataConsumerHandle and
174 // ReaderContext::ReaderImpl. 174 // ReaderContext::ReaderImpl.
175 // All functions/members must be called/accessed only on the reader thread, 175 // All functions/members must be called/accessed only on the reader thread,
176 // except for constructor, destructor, and obtainReader(). 176 // except for constructor, destructor, and obtainReader().
177 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou nted<ReaderContext> { 177 class FetchBlobDataConsumerHandle::ReaderContext final : public ThreadSafeRefCou nted<ReaderContext> {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa ndle, new DefaultLoaderFactory)); 305 return adoptPtr(new FetchBlobDataConsumerHandle(executionContext, blobDataHa ndle, new DefaultLoaderFactory));
306 } 306 }
307 307
308 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern al(Client* client) 308 FetchDataConsumerHandle::Reader* FetchBlobDataConsumerHandle::obtainReaderIntern al(Client* client)
309 { 309 {
310 return m_readerContext->obtainReader(client).leakPtr(); 310 return m_readerContext->obtainReader(client).leakPtr();
311 } 311 }
312 312
313 } // namespace blink 313 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698