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

Side by Side Diff: content/browser/download/download_resource_handler.cc

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. Created 8 years, 2 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) 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/logging.h" 10 #include "base/logging.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 if (!started_cb.is_null()) 76 if (!started_cb.is_null())
77 started_cb.Run(item, net::OK); 77 started_cb.Run(item, net::OK);
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 DownloadResourceHandler::DownloadResourceHandler( 82 DownloadResourceHandler::DownloadResourceHandler(
83 net::URLRequest* request, 83 net::URLRequest* request,
84 const DownloadResourceHandler::OnStartedCallback& started_cb, 84 const DownloadResourceHandler::OnStartedCallback& started_cb,
85 const content::DownloadSaveInfo& save_info) 85 scoped_ptr<content::DownloadSaveInfo> save_info)
86 : render_view_id_(0), // Actually initialized below. 86 : render_view_id_(0), // Actually initialized below.
87 content_length_(0), 87 content_length_(0),
88 request_(request), 88 request_(request),
89 started_cb_(started_cb), 89 started_cb_(started_cb),
90 save_info_(save_info), 90 save_info_(save_info.Pass()),
91 last_buffer_size_(0), 91 last_buffer_size_(0),
92 bytes_read_(0), 92 bytes_read_(0),
93 pause_count_(0), 93 pause_count_(0),
94 was_deferred_(false), 94 was_deferred_(false),
95 on_response_started_called_(false) { 95 on_response_started_called_(false) {
96 ResourceRequestInfoImpl* info(ResourceRequestInfoImpl::ForRequest(request)); 96 ResourceRequestInfoImpl* info(ResourceRequestInfoImpl::ForRequest(request));
97 global_id_ = info->GetGlobalRequestID(); 97 global_id_ = info->GetGlobalRequestID();
98 render_view_id_ = info->GetRouteID(); 98 render_view_id_ = info->GetRouteID();
99 99
100 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT); 100 download_stats::RecordDownloadCount(download_stats::UNTHROTTLED_COUNT);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 CreateByteStream( 152 CreateByteStream(
153 base::MessageLoopProxy::current(), 153 base::MessageLoopProxy::current(),
154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 154 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
155 kDownloadByteStreamSize, &stream_writer_, &stream_reader); 155 kDownloadByteStreamSize, &stream_writer_, &stream_reader);
156 stream_writer_->RegisterCallback( 156 stream_writer_->RegisterCallback(
157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); 157 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr()));
158 158
159 info->url_chain = request_->url_chain(); 159 info->url_chain = request_->url_chain();
160 info->referrer_url = GURL(request_->referrer()); 160 info->referrer_url = GURL(request_->referrer());
161 info->start_time = base::Time::Now(); 161 info->start_time = base::Time::Now();
162 info->received_bytes = save_info_.offset; 162 info->received_bytes = save_info_->offset;
163 info->total_bytes = content_length_; 163 info->total_bytes = content_length_;
164 info->state = DownloadItem::IN_PROGRESS; 164 info->state = DownloadItem::IN_PROGRESS;
165 info->has_user_gesture = request_info->HasUserGesture(); 165 info->has_user_gesture = request_info->HasUserGesture();
166 info->content_disposition = content_disposition_; 166 info->content_disposition = content_disposition_;
167 info->mime_type = response->head.mime_type; 167 info->mime_type = response->head.mime_type;
168 info->remote_address = request_->GetSocketAddress().host(); 168 info->remote_address = request_->GetSocketAddress().host();
169 download_stats::RecordDownloadMimeType(info->mime_type); 169 download_stats::RecordDownloadMimeType(info->mime_type);
170 170
171 info->request_handle = 171 info->request_handle =
172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id, 172 DownloadRequestHandle(AsWeakPtr(), global_id_.child_id,
(...skipping 16 matching lines...) Expand all
189 content_type_header = ""; 189 content_type_header = "";
190 info->original_mime_type = content_type_header; 190 info->original_mime_type = content_type_header;
191 191
192 if (!response->head.headers || 192 if (!response->head.headers ||
193 !response->head.headers->EnumerateHeader( 193 !response->head.headers->EnumerateHeader(
194 NULL, "Accept-Ranges", &accept_ranges_)) { 194 NULL, "Accept-Ranges", &accept_ranges_)) {
195 accept_ranges_ = ""; 195 accept_ranges_ = "";
196 } 196 }
197 197
198 info->prompt_user_for_save_location = 198 info->prompt_user_for_save_location =
199 save_info_.prompt_for_save_location && save_info_.file_path.empty(); 199 save_info_->prompt_for_save_location && save_info_->file_path.empty();
200 info->referrer_charset = request_->context()->referrer_charset(); 200 info->referrer_charset = request_->context()->referrer_charset();
201 info->save_info = save_info_; 201 info->save_info = save_info_.Pass();
202 202
203 BrowserThread::PostTask( 203 BrowserThread::PostTask(
204 BrowserThread::UI, FROM_HERE, 204 BrowserThread::UI, FROM_HERE,
205 base::Bind(&StartOnUIThread, 205 base::Bind(&StartOnUIThread,
206 base::Passed(info.Pass()), 206 base::Passed(info.Pass()),
207 base::Passed(stream_reader.Pass()), 207 base::Passed(stream_reader.Pass()),
208 // Pass to StartOnUIThread so that variable 208 // Pass to StartOnUIThread so that variable
209 // access is always on IO thread but function 209 // access is always on IO thread but function
210 // is called on UI thread. 210 // is called on UI thread.
211 started_cb_)); 211 started_cb_));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 422 }
423 423
424 std::string DownloadResourceHandler::DebugString() const { 424 std::string DownloadResourceHandler::DebugString() const {
425 return base::StringPrintf("{" 425 return base::StringPrintf("{"
426 " url_ = " "\"%s\"" 426 " url_ = " "\"%s\""
427 " global_id_ = {" 427 " global_id_ = {"
428 " child_id = " "%d" 428 " child_id = " "%d"
429 " request_id = " "%d" 429 " request_id = " "%d"
430 " }" 430 " }"
431 " render_view_id_ = " "%d" 431 " render_view_id_ = " "%d"
432 " save_info_.file_path = \"%" PRFilePath "\""
433 " }", 432 " }",
434 request_ ? 433 request_ ?
435 request_->url().spec().c_str() : 434 request_->url().spec().c_str() :
436 "<NULL request>", 435 "<NULL request>",
437 global_id_.child_id, 436 global_id_.child_id,
438 global_id_.request_id, 437 global_id_.request_id,
439 render_view_id_, 438 render_view_id_);
440 save_info_.file_path.value().c_str());
441 } 439 }
442 440
443 DownloadResourceHandler::~DownloadResourceHandler() { 441 DownloadResourceHandler::~DownloadResourceHandler() {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
445 443
446 // This won't do anything if the callback was called before. 444 // This won't do anything if the callback was called before.
447 // If it goes through, it will likely be because OnWillStart() returned 445 // If it goes through, it will likely be because OnWillStart() returned
448 // false somewhere in the chain of resource handlers. 446 // false somewhere in the chain of resource handlers.
449 CallStartedCB(NULL, net::ERR_ACCESS_DENIED); 447 CallStartedCB(NULL, net::ERR_ACCESS_DENIED);
450 448
451 // Remove output stream callback if a stream exists. 449 // Remove output stream callback if a stream exists.
452 if (stream_writer_.get()) 450 if (stream_writer_.get())
453 stream_writer_->RegisterCallback(base::Closure()); 451 stream_writer_->RegisterCallback(base::Closure());
454 452
455 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", 453 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration",
456 base::TimeTicks::Now() - download_start_time_); 454 base::TimeTicks::Now() - download_start_time_);
457 } 455 }
OLDNEW
« no previous file with comments | « content/browser/download/download_resource_handler.h ('k') | content/browser/download/drag_download_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698