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

Side by Side Diff: mojo/services/network/url_loader_impl.cc

Issue 1241553003: Update implementation following changes to URLRequest cache mode. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Follow review Created 5 years, 5 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
« no previous file with comments | « DEPS ('k') | 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 #include "mojo/services/network/url_loader_impl.h" 5 #include "mojo/services/network/url_loader_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 private: 89 private:
90 ScopedDataPipeConsumerHandle pipe_; 90 ScopedDataPipeConsumerHandle pipe_;
91 uint32_t num_bytes_; 91 uint32_t num_bytes_;
92 uint32_t offset_; 92 uint32_t offset_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(UploadDataPipeElementReader); 94 DISALLOW_COPY_AND_ASSIGN(UploadDataPipeElementReader);
95 }; 95 };
96 96
97 bool IsValidCacheMode(int cache_mode) {
98 switch (cache_mode) {
99 case URLRequest::CACHE_MODE_DEFAULT:
100 case URLRequest::CACHE_MODE_BYPASS_CACHE:
101 case URLRequest::CACHE_MODE_ONLY_FROM_CACHE:
102 return true;
103 }
104 return false;
105 }
106
97 } // namespace 107 } // namespace
98 108
99 // Each body fetcher takes ownership of a net::URLRequest and stream its data 109 // Each body fetcher takes ownership of a net::URLRequest and stream its data
100 // to a data pipe. It is owned by an URLLoaderImpl and will notify its owner 110 // to a data pipe. It is owned by an URLLoaderImpl and will notify its owner
101 // when either the data pipe is closed or the request is finished. 111 // when either the data pipe is closed or the request is finished.
102 class URLLoaderImpl::BodyFetcher : public net::URLRequest::Delegate { 112 class URLLoaderImpl::BodyFetcher : public net::URLRequest::Delegate {
103 public: 113 public:
104 BodyFetcher(URLLoaderImpl* loader, 114 BodyFetcher(URLLoaderImpl* loader,
105 uint32_t id, 115 uint32_t id,
106 scoped_ptr<net::URLRequest> url_request, 116 scoped_ptr<net::URLRequest> url_request,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 interceptor_index_ = 0; 498 interceptor_index_ = 0;
489 redirect_info_.reset(); 499 redirect_info_.reset();
490 // TODO(darin): Verify that it makes sense to call FollowDeferredRedirect. 500 // TODO(darin): Verify that it makes sense to call FollowDeferredRedirect.
491 url_request_->FollowDeferredRedirect(); 501 url_request_->FollowDeferredRedirect();
492 } 502 }
493 503
494 void URLLoaderImpl::StartInternal(URLRequestPtr request) { 504 void URLLoaderImpl::StartInternal(URLRequestPtr request) {
495 DCHECK(!url_request_); 505 DCHECK(!url_request_);
496 DCHECK(!redirect_info_); 506 DCHECK(!redirect_info_);
497 507
508 if (!IsValidCacheMode(request->cache_mode)) {
509 // Unknown cache mode. The request must fail.
510 delete this;
511 return;
512 }
513
498 if (interceptor_index_ >= 0 && 514 if (interceptor_index_ >= 0 &&
499 interceptor_index_ < static_cast<int>(interceptors_.size())) { 515 interceptor_index_ < static_cast<int>(interceptors_.size())) {
500 interceptors_[interceptor_index_]->InterceptRequest( 516 interceptors_[interceptor_index_]->InterceptRequest(
501 request.Pass(), base::Bind(&URLLoaderImpl::OnIntercept, 517 request.Pass(), base::Bind(&URLLoaderImpl::OnIntercept,
502 base::Unretained(this))); 518 base::Unretained(this)));
503 return; 519 return;
504 } 520 }
505 521
506 DCHECK(interceptor_index_ == -1); 522 DCHECK(interceptor_index_ == -1);
507 interceptor_index_ = 0; 523 interceptor_index_ = 0;
(...skipping 22 matching lines...) Expand all
530 if (request->body) { 546 if (request->body) {
531 ScopedVector<net::UploadElementReader> element_readers; 547 ScopedVector<net::UploadElementReader> element_readers;
532 for (size_t i = 0; i < request->body.size(); ++i) { 548 for (size_t i = 0; i < request->body.size(); ++i) {
533 element_readers.push_back( 549 element_readers.push_back(
534 new UploadDataPipeElementReader(request->body[i].Pass())); 550 new UploadDataPipeElementReader(request->body[i].Pass()));
535 } 551 }
536 url_request_->set_upload(make_scoped_ptr<net::UploadDataStream>( 552 url_request_->set_upload(make_scoped_ptr<net::UploadDataStream>(
537 new net::ElementsUploadDataStream(element_readers.Pass(), 0))); 553 new net::ElementsUploadDataStream(element_readers.Pass(), 0)));
538 } 554 }
539 int load_flags = 0; 555 int load_flags = 0;
540 if (request->bypass_cache) 556 switch (request->cache_mode) {
541 load_flags |= net::LOAD_BYPASS_CACHE; 557 case URLRequest::CACHE_MODE_DEFAULT:
542 if (request->only_from_cache) 558 break;
543 load_flags |= net::LOAD_ONLY_FROM_CACHE; 559 case URLRequest::CACHE_MODE_BYPASS_CACHE:
560 load_flags |= net::LOAD_BYPASS_CACHE;
561 case URLRequest::CACHE_MODE_ONLY_FROM_CACHE:
562 load_flags |= net::LOAD_ONLY_FROM_CACHE;
563 break;
564 }
544 if (load_flags) 565 if (load_flags)
545 url_request_->SetLoadFlags(load_flags); 566 url_request_->SetLoadFlags(load_flags);
546 567
547 response_body_buffer_size_ = request->response_body_buffer_size; 568 response_body_buffer_size_ = request->response_body_buffer_size;
548 auto_follow_redirects_ = request->auto_follow_redirects; 569 auto_follow_redirects_ = request->auto_follow_redirects;
549 570
550 url_request_->Start(); 571 url_request_->Start();
551 } 572 }
552 573
553 void URLLoaderImpl::SendResponse(URLResponsePtr response) { 574 void URLLoaderImpl::SendResponse(URLResponsePtr response) {
(...skipping 22 matching lines...) Expand all
576 if ((*it)->id() == current_fetcher_id_) { 597 if ((*it)->id() == current_fetcher_id_) {
577 last_status_ = fetcher->QueryStatus(); 598 last_status_ = fetcher->QueryStatus();
578 last_status_->is_loading = false; 599 last_status_->is_loading = false;
579 } 600 }
580 body_fetchers_.erase(it); 601 body_fetchers_.erase(it);
581 if (body_fetchers_.empty() and !binding_.is_bound()) 602 if (body_fetchers_.empty() and !binding_.is_bound())
582 delete this; 603 delete this;
583 } 604 }
584 605
585 } // namespace mojo 606 } // namespace mojo
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698