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

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 737763002: Properly handle defers loading in WebURLLoaderImpl for data uris (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge.
6 6
7 #include "content/child/web_url_loader_impl.h" 7 #include "content/child/web_url_loader_impl.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 347 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
348 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 348 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
349 scoped_ptr<ResourceLoaderBridge> completed_bridge_; 349 scoped_ptr<ResourceLoaderBridge> completed_bridge_;
350 scoped_ptr<StreamOverrideParameters> stream_override_; 350 scoped_ptr<StreamOverrideParameters> stream_override_;
351 mojo::ScopedDataPipeProducerHandle body_stream_writer_; 351 mojo::ScopedDataPipeProducerHandle body_stream_writer_;
352 mojo::common::HandleWatcher body_stream_writer_watcher_; 352 mojo::common::HandleWatcher body_stream_writer_watcher_;
353 // TODO(yhirano): Delete this buffer after implementing the back-pressure 353 // TODO(yhirano): Delete this buffer after implementing the back-pressure
354 // mechanism. 354 // mechanism.
355 std::deque<char> body_stream_buffer_; 355 std::deque<char> body_stream_buffer_;
356 bool got_all_stream_body_data_; 356 bool got_all_stream_body_data_;
357 enum {NO_DEFER, DEFERS, DEFERED_DATA} defers_loading_;
davidben 2014/11/18 21:02:29 Nit: I ended up pausing a bit to check whether we
jochen (gone - plz use gerrit) 2014/11/19 08:54:06 it also doesn't look clang-formatted.
João Eiras 2014/11/21 15:25:31 Done. (I did find deferring and deferred_data to s
357 }; 358 };
358 359
359 WebURLLoaderImpl::Context::Context( 360 WebURLLoaderImpl::Context::Context(
360 WebURLLoaderImpl* loader, 361 WebURLLoaderImpl* loader,
361 ResourceDispatcher* resource_dispatcher, 362 ResourceDispatcher* resource_dispatcher,
362 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 363 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
363 : loader_(loader), 364 : loader_(loader),
364 client_(NULL), 365 client_(NULL),
365 resource_dispatcher_(resource_dispatcher), 366 resource_dispatcher_(resource_dispatcher),
366 task_runner_(task_runner), 367 task_runner_(task_runner),
367 referrer_policy_(blink::WebReferrerPolicyDefault), 368 referrer_policy_(blink::WebReferrerPolicyDefault),
368 got_all_stream_body_data_(false) { 369 got_all_stream_body_data_(false),
370 defers_loading_(NO_DEFER) {
369 } 371 }
370 372
371 void WebURLLoaderImpl::Context::Cancel() { 373 void WebURLLoaderImpl::Context::Cancel() {
372 if (bridge_) { 374 if (bridge_) {
373 bridge_->Cancel(); 375 bridge_->Cancel();
374 bridge_.reset(); 376 bridge_.reset();
375 } 377 }
376 378
377 // Ensure that we do not notify the multipart delegate anymore as it has 379 // Ensure that we do not notify the multipart delegate anymore as it has
378 // its own pointer to the client. 380 // its own pointer to the client.
379 if (multipart_delegate_) 381 if (multipart_delegate_)
380 multipart_delegate_->Cancel(); 382 multipart_delegate_->Cancel();
381 // Ditto for the ftp delegate. 383 // Ditto for the ftp delegate.
382 if (ftp_listing_delegate_) 384 if (ftp_listing_delegate_)
383 ftp_listing_delegate_->Cancel(); 385 ftp_listing_delegate_->Cancel();
384 386
385 // Do not make any further calls to the client. 387 // Do not make any further calls to the client.
386 client_ = NULL; 388 client_ = NULL;
387 loader_ = NULL; 389 loader_ = NULL;
388 } 390 }
389 391
390 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 392 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
391 if (bridge_) 393 if (bridge_)
392 bridge_->SetDefersLoading(value); 394 bridge_->SetDefersLoading(value);
395
396 if (value) {
397 DCHECK_EQ(defers_loading_, NO_DEFER);
davidben 2014/11/18 21:02:29 Nit: I'd do DCHECK_EQ(NO_DEFER, defers_loading_) t
João Eiras 2014/11/21 15:25:31 done
398 defers_loading_ = DEFERS;
399 } else {
400 DCHECK_NE(defers_loading_, NO_DEFER);
401 if (defers_loading_ == DEFERED_DATA)
davidben 2014/11/18 21:02:29 Nit: curly braces since the body is multiple lines
João Eiras 2014/11/21 15:25:31 done
402 base::MessageLoop::current()->PostTask(
davidben 2014/11/18 21:02:29 I believe base::MessageLoop::current() should be t
João Eiras 2014/11/21 15:25:31 done
403 FROM_HERE, base::Bind(&Context::HandleDataURL, this));
404 defers_loading_ = NO_DEFER;
405 }
393 } 406 }
394 407
395 void WebURLLoaderImpl::Context::DidChangePriority( 408 void WebURLLoaderImpl::Context::DidChangePriority(
396 WebURLRequest::Priority new_priority, int intra_priority_value) { 409 WebURLRequest::Priority new_priority, int intra_priority_value) {
397 if (bridge_) 410 if (bridge_)
398 bridge_->DidChangePriority( 411 bridge_->DidChangePriority(
399 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); 412 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value);
400 } 413 }
401 414
402 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver( 415 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver(
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 842
830 std::string mime_type, unused_charset; 843 std::string mime_type, unused_charset;
831 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && 844 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) &&
832 net::IsSupportedMimeType(mime_type)) 845 net::IsSupportedMimeType(mime_type))
833 return true; 846 return true;
834 847
835 return false; 848 return false;
836 } 849 }
837 850
838 void WebURLLoaderImpl::Context::HandleDataURL() { 851 void WebURLLoaderImpl::Context::HandleDataURL() {
852 if (defers_loading_ != NO_DEFER) {
jochen (gone - plz use gerrit) 2014/11/19 08:54:06 deferes_loading_ should be "DEFERS" if it's != NO_
João Eiras 2014/11/21 15:25:31 It should. Added an assert.
853 defers_loading_ = DEFERED_DATA;
854 return;
855 }
856
839 ResourceResponseInfo info; 857 ResourceResponseInfo info;
840 std::string data; 858 std::string data;
841 859
842 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); 860 int error_code = GetInfoFromDataURL(request_.url(), &info, &data);
843 861
844 if (error_code == net::OK) { 862 if (error_code == net::OK) {
845 OnReceivedResponse(info); 863 OnReceivedResponse(info);
846 if (!data.empty()) 864 if (!data.empty())
847 OnReceivedData(data.data(), data.size(), 0); 865 OnReceivedData(data.data(), data.size(), 0);
848 } 866 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 int intra_priority_value) { 1172 int intra_priority_value) {
1155 context_->DidChangePriority(new_priority, intra_priority_value); 1173 context_->DidChangePriority(new_priority, intra_priority_value);
1156 } 1174 }
1157 1175
1158 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1176 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1159 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1177 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1160 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1178 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1161 } 1179 }
1162 1180
1163 } // namespace content 1181 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698