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

Side by Side Diff: chrome/browser/renderer_host/download_throttling_resource_handler.cc

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/renderer_host/download_throttling_resource_handler.h" 5 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/download/download_id.h"
8 #include "chrome/browser/download/download_util.h" 9 #include "chrome/browser/download/download_util.h"
9 #include "chrome/browser/renderer_host/download_resource_handler.h" 10 #include "chrome/browser/renderer_host/download_resource_handler.h"
10 #include "content/browser/renderer_host/resource_dispatcher_host.h" 11 #include "content/browser/renderer_host/resource_dispatcher_host.h"
12 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
13 #include "content/browser/resource_context.h"
11 #include "content/common/resource_response.h" 14 #include "content/common/resource_response.h"
12 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
13 #include "net/base/mime_sniffer.h" 16 #include "net/base/mime_sniffer.h"
14 17
15 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler( 18 DownloadThrottlingResourceHandler::DownloadThrottlingResourceHandler(
16 ResourceDispatcherHost* host, 19 ResourceDispatcherHost* host,
17 net::URLRequest* request, 20 net::URLRequest* request,
18 const GURL& url, 21 const GURL& url,
19 int render_process_host_id, 22 int render_process_host_id,
20 int render_view_id, 23 int render_view_id,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 169
167 void DownloadThrottlingResourceHandler::CancelDownload() { 170 void DownloadThrottlingResourceHandler::CancelDownload() {
168 if (!request_closed_) 171 if (!request_closed_)
169 host_->CancelRequest(render_process_host_id_, request_id_, false); 172 host_->CancelRequest(render_process_host_id_, request_id_, false);
170 Release(); // Release the additional reference from constructor. 173 Release(); // Release the additional reference from constructor.
171 } 174 }
172 175
173 void DownloadThrottlingResourceHandler::ContinueDownload() { 176 void DownloadThrottlingResourceHandler::ContinueDownload() {
174 DCHECK(!download_handler_.get()); 177 DCHECK(!download_handler_.get());
175 if (!request_closed_) { 178 if (!request_closed_) {
179 ResourceDispatcherHostRequestInfo* info =
180 ResourceDispatcherHost::InfoForRequest(request_);
181 DownloadId dl_id;
182 void* next_download_id_thunk = info->context()->GetUserData(
Randy Smith (Not in Mondays) 2011/08/03 21:10:29 Will we also be able to clean this up when downloa
benjhayden 2011/08/04 17:15:00 Done.
183 reinterpret_cast<void*>(BASE_HASH_NAMESPACE::hash<std::string>()(
184 "next_download_id_thunk")));
185 if (next_download_id_thunk != NULL) {
186 dl_id = reinterpret_cast<DownloadManager::GetNextIdThunkType*>(
187 next_download_id_thunk)->Run();
188 }
176 download_handler_ = 189 download_handler_ =
177 new DownloadResourceHandler(host_, 190 new DownloadResourceHandler(host_,
178 render_process_host_id_, 191 render_process_host_id_,
179 render_view_id_, 192 render_view_id_,
180 request_id_, 193 request_id_,
181 url_, 194 url_,
195 dl_id,
182 host_->download_file_manager(), 196 host_->download_file_manager(),
183 request_, 197 request_,
184 false, 198 false,
185 DownloadSaveInfo()); 199 DownloadSaveInfo());
186 if (response_.get()) 200 if (response_.get())
187 download_handler_->OnResponseStarted(request_id_, response_.get()); 201 download_handler_->OnResponseStarted(request_id_, response_.get());
188 202
189 if (tmp_buffer_length_) 203 if (tmp_buffer_length_)
190 CopyTmpBufferToDownloadHandler(); 204 CopyTmpBufferToDownloadHandler();
191 205
192 // And let the request continue. 206 // And let the request continue.
193 host_->PauseRequest(render_process_host_id_, request_id_, false); 207 host_->PauseRequest(render_process_host_id_, request_id_, false);
194 } 208 }
195 Release(); // Release the addtional reference from constructor. 209 Release(); // Release the addtional reference from constructor.
196 } 210 }
197 211
198 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() { 212 void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() {
199 // Copy over the tmp buffer. 213 // Copy over the tmp buffer.
200 net::IOBuffer* buffer; 214 net::IOBuffer* buffer;
201 int buf_size; 215 int buf_size;
202 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size, 216 if (download_handler_->OnWillRead(request_id_, &buffer, &buf_size,
203 tmp_buffer_length_)) { 217 tmp_buffer_length_)) {
204 CHECK(buf_size >= tmp_buffer_length_); 218 CHECK(buf_size >= tmp_buffer_length_);
205 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_); 219 memcpy(buffer->data(), tmp_buffer_->data(), tmp_buffer_length_);
206 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_); 220 download_handler_->OnReadCompleted(request_id_, &tmp_buffer_length_);
207 } 221 }
208 tmp_buffer_length_ = 0; 222 tmp_buffer_length_ = 0;
209 tmp_buffer_ = NULL; 223 tmp_buffer_ = NULL;
210 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698