OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/loader/layered_resource_handler.h" | 5 #include "content/browser/loader/layered_resource_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" |
| 12 #include "net/url_request/url_request.h" |
10 | 13 |
11 namespace content { | 14 namespace content { |
12 | 15 |
13 LayeredResourceHandler::LayeredResourceHandler( | 16 LayeredResourceHandler::LayeredResourceHandler( |
14 net::URLRequest* request, | 17 net::URLRequest* request, |
15 std::unique_ptr<ResourceHandler> next_handler) | 18 std::unique_ptr<ResourceHandler> next_handler) |
16 : ResourceHandler(request), next_handler_(std::move(next_handler)) {} | 19 : ResourceHandler(request), next_handler_(std::move(next_handler)) {} |
17 | 20 |
18 LayeredResourceHandler::~LayeredResourceHandler() { | 21 LayeredResourceHandler::~LayeredResourceHandler() { |
19 } | 22 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 bool* defer) { | 76 bool* defer) { |
74 DCHECK(next_handler_.get()); | 77 DCHECK(next_handler_.get()); |
75 next_handler_->OnResponseCompleted(status, security_info, defer); | 78 next_handler_->OnResponseCompleted(status, security_info, defer); |
76 } | 79 } |
77 | 80 |
78 void LayeredResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 81 void LayeredResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
79 DCHECK(next_handler_.get()); | 82 DCHECK(next_handler_.get()); |
80 next_handler_->OnDataDownloaded(bytes_downloaded); | 83 next_handler_->OnDataDownloaded(bytes_downloaded); |
81 } | 84 } |
82 | 85 |
| 86 bool LayeredResourceHandler::IsLeafHandler() const { |
| 87 return false; |
| 88 } |
| 89 |
| 90 void LayeredResourceHandler::InstallNewLeafHandler( |
| 91 std::unique_ptr<ResourceHandler> new_handler, |
| 92 const std::string& payload_for_old_handler) { |
| 93 if (!next_handler_->IsLeafHandler()) { |
| 94 next_handler_->InstallNewLeafHandler(std::move(new_handler), |
| 95 payload_for_old_handler); |
| 96 return; |
| 97 } |
| 98 |
| 99 // Simulate a read of payload_for_old_handler and the end of the response on |
| 100 // the next handler. |
| 101 bool defer_ignored = false; |
| 102 if (payload_for_old_handler.empty()) { |
| 103 net::URLRequestStatus status(net::URLRequestStatus::CANCELED, |
| 104 net::ERR_ABORTED); |
| 105 next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored); |
| 106 DCHECK(!defer_ignored); |
| 107 } else { |
| 108 scoped_refptr<net::IOBuffer> buf; |
| 109 int size = 0; |
| 110 |
| 111 next_handler_->OnWillRead(&buf, &size, -1); |
| 112 CHECK_GE(size, static_cast<int>(payload_for_old_handler.length())); |
| 113 |
| 114 memcpy(buf->data(), payload_for_old_handler.c_str(), |
| 115 payload_for_old_handler.length()); |
| 116 |
| 117 next_handler_->OnReadCompleted(payload_for_old_handler.length(), |
| 118 &defer_ignored); |
| 119 DCHECK(!defer_ignored); |
| 120 |
| 121 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 122 next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored); |
| 123 DCHECK(!defer_ignored); |
| 124 } |
| 125 |
| 126 next_handler_ = std::move(new_handler); |
| 127 next_handler_->SetController(controller()); |
| 128 } |
| 129 |
83 } // namespace content | 130 } // namespace content |
OLD | NEW |