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/download/download_resource_handler.h" | 5 #include "content/browser/download/download_resource_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 BrowserThread::PostTask( | 122 BrowserThread::PostTask( |
123 BrowserThread::UI, FROM_HERE, | 123 BrowserThread::UI, FROM_HERE, |
124 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); | 124 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 bool DownloadResourceHandler::OnRequestRedirected( | 128 bool DownloadResourceHandler::OnRequestRedirected( |
129 const net::RedirectInfo& redirect_info, | 129 const net::RedirectInfo& redirect_info, |
130 ResourceResponse* response, | 130 ResourceResponse* response, |
131 bool* defer) { | 131 bool* defer) { |
132 return true; | 132 DownloadInterruptReason result = core_.OnRequestRedirected(redirect_info); |
| 133 if (result == DOWNLOAD_INTERRUPT_REASON_NONE) |
| 134 return true; |
| 135 |
| 136 // Allow the interrupt reason to propagate up the stack before we receive the |
| 137 // OnResponseCompleted() call. The ResourceLoader will treat this as an ABORT, |
| 138 // hence OnResponseCompleted() may conclude a more generic interrupt reason. |
| 139 // We want the specific interrupt reason to be dispatched instead. |
| 140 CallStartedCB(result); |
| 141 return false; |
133 } | 142 } |
134 | 143 |
135 // Send the download creation information to the download thread. | 144 // Send the download creation information to the download thread. |
136 bool DownloadResourceHandler::OnResponseStarted( | 145 bool DownloadResourceHandler::OnResponseStarted( |
137 ResourceResponse* response, | 146 ResourceResponse* response, |
138 bool* defer) { | 147 bool* defer) { |
139 scoped_ptr<DownloadCreateInfo> create_info; | 148 scoped_ptr<DownloadCreateInfo> create_info; |
140 scoped_ptr<ByteStreamReader> stream_reader; | 149 scoped_ptr<ByteStreamReader> stream_reader; |
141 | 150 |
142 core_.OnResponseStarted(&create_info, &stream_reader); | 151 DownloadInterruptReason result = |
| 152 core_.OnResponseStarted(&create_info, &stream_reader); |
| 153 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 154 CallStartedCB(result); |
| 155 return false; |
| 156 } |
143 | 157 |
144 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); | 158 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); |
145 create_info->download_id = download_id_; | 159 create_info->download_id = download_id_; |
146 create_info->has_user_gesture = request_info->HasUserGesture(); | 160 create_info->has_user_gesture = request_info->HasUserGesture(); |
147 create_info->transition_type = request_info->GetPageTransition(); | 161 create_info->transition_type = request_info->GetPageTransition(); |
148 create_info->request_handle.reset(new DownloadRequestHandle( | 162 create_info->request_handle.reset(new DownloadRequestHandle( |
149 AsWeakPtr(), request_info->GetChildID(), request_info->GetRouteID(), | 163 AsWeakPtr(), request_info->GetChildID(), request_info->GetRouteID(), |
150 request_info->GetRequestID(), request_info->frame_tree_node_id())); | 164 request_info->GetRequestID(), request_info->frame_tree_node_id())); |
151 | 165 |
152 // The MIME type in ResourceResponse is the product of | 166 // The MIME type in ResourceResponse is the product of |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 " }", | 254 " }", |
241 request() ? | 255 request() ? |
242 request()->url().spec().c_str() : | 256 request()->url().spec().c_str() : |
243 "<NULL request>", | 257 "<NULL request>", |
244 info->GetChildID(), | 258 info->GetChildID(), |
245 info->GetRequestID(), | 259 info->GetRequestID(), |
246 info->GetRouteID()); | 260 info->GetRouteID()); |
247 } | 261 } |
248 | 262 |
249 } // namespace content | 263 } // namespace content |
OLD | NEW |