[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] | cba2464 | 2014-08-15 20:49:59 | [diff] [blame] | 32 | bool LayeredResourceHandler::OnRequestRedirected( |
| 33 | const net::RedirectInfo& redirect_info, |
| 34 | ResourceResponse* response, |
| 35 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 36 | DCHECK(next_handler_.get()); |
[email protected] | cba2464 | 2014-08-15 20:49:59 | [diff] [blame] | 37 | return next_handler_->OnRequestRedirected(redirect_info, response, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 38 | } |
| 39 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 40 | bool LayeredResourceHandler::OnResponseStarted(ResourceResponse* response, |
[email protected] | 22b30544 | 2012-05-21 18:02:59 | [diff] [blame] | 41 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 42 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 43 | return next_handler_->OnResponseStarted(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::OnWillStart(const GURL& url, |
[email protected] | d18720a | 2012-01-06 09:53:55 | [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_->OnWillStart(url, 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::OnBeforeNetworkStart(const GURL& url, |
[email protected] | 5584eab | 2014-01-09 22:16:15 | [diff] [blame] | 53 | bool* defer) { |
| 54 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 55 | return next_handler_->OnBeforeNetworkStart(url, defer); |
[email protected] | 5584eab | 2014-01-09 22:16:15 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 58 | bool LayeredResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
[email protected] | ef5306e | 2013-10-15 19:38:18 | [diff] [blame] | 59 | int* buf_size, |
| 60 | int min_size) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 61 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 62 | return next_handler_->OnWillRead(buf, buf_size, min_size); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 65 | bool LayeredResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 66 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 67 | return next_handler_->OnReadCompleted(bytes_read, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 3780874a | 2013-11-18 05:49:03 | [diff] [blame] | 70 | void LayeredResourceHandler::OnResponseCompleted( |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 71 | const net::URLRequestStatus& status, |
[email protected] | 3780874a | 2013-11-18 05:49:03 | [diff] [blame] | 72 | const std::string& security_info, |
| 73 | bool* defer) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 74 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 75 | next_handler_->OnResponseCompleted(status, security_info, defer); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 78 | void LayeredResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
[email protected] | d651cbc | 2012-05-31 21:33:05 | [diff] [blame] | 79 | DCHECK(next_handler_.get()); |
[email protected] | d22e800e | 2014-05-28 21:55:57 | [diff] [blame] | 80 | next_handler_->OnDataDownloaded(bytes_downloaded); |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | d18720a | 2012-01-06 09:53:55 | [diff] [blame] | 83 | } // namespace content |