[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 5 | #include "content/browser/loader/layered_resource_handler.h" |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 6 | |
[email protected] | 62b4a96 | 2012-01-18 22:53:16 | [diff] [blame] | 7 | #include "base/logging.h" |
| 8 | |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 9 | namespace content { |
| 10 | |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 11 | LayeredResourceHandler::LayeredResourceHandler( |
[email protected] | ef5306e | 2013-10-15 19:38:18 | [diff] [blame] | 12 | net::URLRequest* request, |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 13 | scoped_ptr<ResourceHandler> next_handler) |
[email protected] | ef5306e | 2013-10-15 19:38:18 | [diff] [blame] | 14 | : ResourceHandler(request), |
| 15 | next_handler_(next_handler.Pass()) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | LayeredResourceHandler::~LayeredResourceHandler() { |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 19 | } |
| 20 | |
[email protected] | 56f0b08 | 2012-06-14 07:12:32 | [diff] [blame] | 21 | void LayeredResourceHandler::SetController(ResourceController* controller) { |
| 22 | ResourceHandler::SetController(controller); |
| 23 | |
| 24 | // Pass the controller down to the next handler. This method is intended to |
| 25 | // be overriden by subclasses of LayeredResourceHandler that need to insert a |
| 26 | // different ResourceController. |
| 27 | |
| 28 | DCHECK(next_handler_.get()); |
| 29 | next_handler_->SetController(controller); |
| 30 | } |
| 31 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 32 | bool LayeredResourceHandler::OnUploadProgress(uint64 position, |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 33 | uint64 size) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 34 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 35 | return next_handler_->OnUploadProgress(position, size); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 36 | } |
| 37 | |
[email protected] | cba2464 | 2014-08-15 20:49:59 | [diff] [blame^] | 38 | bool LayeredResourceHandler::OnRequestRedirected( |
| 39 | const net::RedirectInfo& redirect_info, |
| 40 | ResourceResponse* response, |
| 41 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 42 | DCHECK(next_handler_.get()); |
[email protected] | cba2464 | 2014-08-15 20:49:59 | [diff] [blame^] | 43 | return next_handler_->OnRequestRedirected(redirect_info, response, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 44 | } |
| 45 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 46 | bool LayeredResourceHandler::OnResponseStarted(ResourceResponse* response, |
[email protected] | 22b30544 | 2012-05-21 18:02:59 | [diff] [blame] | 47 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 48 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 49 | return next_handler_->OnResponseStarted(response, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 52 | bool LayeredResourceHandler::OnWillStart(const GURL& url, |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 53 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 54 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 55 | return next_handler_->OnWillStart(url, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 58 | bool LayeredResourceHandler::OnBeforeNetworkStart(const GURL& url, |
[email protected] | 5584eab | 2014-01-09 22:16:15 | [diff] [blame] | 59 | bool* defer) { |
| 60 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 61 | return next_handler_->OnBeforeNetworkStart(url, defer); |
[email protected] | 5584eab | 2014-01-09 22:16:15 | [diff] [blame] | 62 | } |
| 63 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 64 | bool LayeredResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
[email protected] | ef5306e | 2013-10-15 19:38:18 | [diff] [blame] | 65 | int* buf_size, |
| 66 | int min_size) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 67 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 68 | return next_handler_->OnWillRead(buf, buf_size, min_size); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 71 | bool LayeredResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 72 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 73 | return next_handler_->OnReadCompleted(bytes_read, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 74 | } |
| 75 | |
[email protected] | 3780874a | 2013-11-18 05:49:03 | [diff] [blame] | 76 | void LayeredResourceHandler::OnResponseCompleted( |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 77 | const net::URLRequestStatus& status, |
[email protected] | 3780874a | 2013-11-18 05:49:03 | [diff] [blame] | 78 | const std::string& security_info, |
| 79 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 80 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 81 | next_handler_->OnResponseCompleted(status, security_info, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 84 | void LayeredResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 85 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 86 | next_handler_->OnDataDownloaded(bytes_downloaded); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 87 | } |
| 88 | |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 89 | } // namespace content |