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

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

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Bearings Before Woods Created 9 years, 6 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_resource_handler.h" 5 #include "chrome/browser/renderer_host/download_resource_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 15 matching lines...) Expand all
26 26
27 DownloadResourceHandler::DownloadResourceHandler( 27 DownloadResourceHandler::DownloadResourceHandler(
28 ResourceDispatcherHost* rdh, 28 ResourceDispatcherHost* rdh,
29 int render_process_host_id, 29 int render_process_host_id,
30 int render_view_id, 30 int render_view_id,
31 int request_id, 31 int request_id,
32 const GURL& url, 32 const GURL& url,
33 DownloadFileManager* download_file_manager, 33 DownloadFileManager* download_file_manager,
34 net::URLRequest* request, 34 net::URLRequest* request,
35 bool save_as, 35 bool save_as,
36 OnResponseStartedCallback started_cb,
37 OnUnstartableCallback unstartable_cb,
36 const DownloadSaveInfo& save_info) 38 const DownloadSaveInfo& save_info)
37 : download_id_(-1), 39 : download_id_(-1),
38 global_id_(render_process_host_id, request_id), 40 global_id_(render_process_host_id, request_id),
39 render_view_id_(render_view_id), 41 render_view_id_(render_view_id),
40 content_length_(0), 42 content_length_(0),
41 download_file_manager_(download_file_manager), 43 download_file_manager_(download_file_manager),
42 request_(request), 44 request_(request),
43 save_as_(save_as), 45 save_as_(save_as),
46 started_cb_(started_cb),
47 unstartable_cb_(unstartable_cb),
44 save_info_(save_info), 48 save_info_(save_info),
45 buffer_(new DownloadBuffer), 49 buffer_(new DownloadBuffer),
46 rdh_(rdh), 50 rdh_(rdh),
47 is_paused_(false) { 51 is_paused_(false) {
48 download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT); 52 download_util::RecordDownloadCount(download_util::UNTHROTTLED_COUNT);
49 } 53 }
50 54
51 bool DownloadResourceHandler::OnUploadProgress(int request_id, 55 bool DownloadResourceHandler::OnUploadProgress(int request_id,
52 uint64 position, 56 uint64 position,
53 uint64 size) { 57 uint64 size) {
(...skipping 18 matching lines...) Expand all
72 request_->GetResponseHeaderByName("content-disposition", 76 request_->GetResponseHeaderByName("content-disposition",
73 &content_disposition); 77 &content_disposition);
74 set_content_disposition(content_disposition); 78 set_content_disposition(content_disposition);
75 set_content_length(response->response_head.content_length); 79 set_content_length(response->response_head.content_length);
76 80
77 const ResourceDispatcherHostRequestInfo* request_info = 81 const ResourceDispatcherHostRequestInfo* request_info =
78 ResourceDispatcherHost::InfoForRequest(request_); 82 ResourceDispatcherHost::InfoForRequest(request_);
79 83
80 download_id_ = download_file_manager_->GetNextId(); 84 download_id_ = download_file_manager_->GetNextId();
81 85
86 started_cb_.Run(download_id_);
87
82 // Deleted in DownloadManager. 88 // Deleted in DownloadManager.
83 DownloadCreateInfo* info = new DownloadCreateInfo; 89 DownloadCreateInfo* info = new DownloadCreateInfo;
84 info->url_chain = request_->url_chain(); 90 info->url_chain = request_->url_chain();
85 info->referrer_url = GURL(request_->referrer()); 91 info->referrer_url = GURL(request_->referrer());
86 info->start_time = base::Time::Now(); 92 info->start_time = base::Time::Now();
87 info->received_bytes = 0; 93 info->received_bytes = 0;
88 info->total_bytes = content_length_; 94 info->total_bytes = content_length_;
89 info->state = DownloadItem::IN_PROGRESS; 95 info->state = DownloadItem::IN_PROGRESS;
90 info->download_id = download_id_; 96 info->download_id = download_id_;
91 info->has_user_gesture = request_info->has_user_gesture(); 97 info->has_user_gesture = request_info->has_user_gesture();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bool DownloadResourceHandler::OnResponseCompleted( 177 bool DownloadResourceHandler::OnResponseCompleted(
172 int request_id, 178 int request_id,
173 const net::URLRequestStatus& status, 179 const net::URLRequestStatus& status,
174 const std::string& security_info) { 180 const std::string& security_info) {
175 VLOG(20) << __FUNCTION__ << "()" << DebugString() 181 VLOG(20) << __FUNCTION__ << "()" << DebugString()
176 << " request_id = " << request_id 182 << " request_id = " << request_id
177 << " status.status() = " << status.status() 183 << " status.status() = " << status.status()
178 << " status.os_error() = " << status.os_error(); 184 << " status.os_error() = " << status.os_error();
179 int error_code = (status.status() == net::URLRequestStatus::FAILED) ? 185 int error_code = (status.status() == net::URLRequestStatus::FAILED) ?
180 status.os_error() : 0; 186 status.os_error() : 0;
187 if (download_id_ == -1) {
188 unstartable_cb_.Run(error_code);
189 }
181 // We transfer ownership to |DownloadFileManager| to delete |buffer_|, 190 // We transfer ownership to |DownloadFileManager| to delete |buffer_|,
182 // so that any functions queued up on the FILE thread are executed 191 // so that any functions queued up on the FILE thread are executed
183 // before deletion. 192 // before deletion.
184 BrowserThread::PostTask( 193 BrowserThread::PostTask(
185 BrowserThread::FILE, FROM_HERE, 194 BrowserThread::FILE, FROM_HERE,
186 NewRunnableMethod(download_file_manager_, 195 NewRunnableMethod(download_file_manager_,
187 &DownloadFileManager::OnResponseCompleted, 196 &DownloadFileManager::OnResponseCompleted,
188 download_id_, 197 download_id_,
189 buffer_.release(), 198 buffer_.release(),
190 error_code, 199 error_code,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 " render_view_id_ = " "%d" 264 " render_view_id_ = " "%d"
256 " save_info_.file_path = \"%" PRFilePath "\"" 265 " save_info_.file_path = \"%" PRFilePath "\""
257 " }", 266 " }",
258 request_->url().spec().c_str(), 267 request_->url().spec().c_str(),
259 download_id_, 268 download_id_,
260 global_id_.child_id, 269 global_id_.child_id,
261 global_id_.request_id, 270 global_id_.request_id,
262 render_view_id_, 271 render_view_id_,
263 save_info_.file_path.value().c_str()); 272 save_info_.file_path.value().c_str());
264 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698