| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 if (started_cb.is_null()) | 43 if (started_cb.is_null()) |
| 44 return; | 44 return; |
| 45 started_cb.Run(item, error); | 45 started_cb.Run(item, error); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Static function in order to prevent any accidental accesses to | 48 // Static function in order to prevent any accidental accesses to |
| 49 // DownloadResourceHandler members from the UI thread. | 49 // DownloadResourceHandler members from the UI thread. |
| 50 static void StartOnUIThread( | 50 static void StartOnUIThread( |
| 51 scoped_ptr<DownloadCreateInfo> info, | 51 scoped_ptr<DownloadCreateInfo> info, |
| 52 scoped_ptr<ByteStreamReader> stream, | 52 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
| 53 const DownloadUrlParameters::OnStartedCallback& started_cb) { | 53 const DownloadUrlParameters::OnStartedCallback& started_cb) { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 55 | 55 |
| 56 DownloadManager* download_manager = info->request_handle.GetDownloadManager(); | 56 DownloadManager* download_manager = info->request_handle.GetDownloadManager(); |
| 57 if (!download_manager) { | 57 if (!download_manager) { |
| 58 // NULL in unittests or if the page closed right after starting the | 58 // NULL in unittests or if the page closed right after starting the |
| 59 // download. | 59 // download. |
| 60 if (!started_cb.is_null()) | 60 if (!started_cb.is_null()) |
| 61 started_cb.Run(NULL, net::ERR_ACCESS_DENIED); | 61 started_cb.Run(NULL, net::ERR_ACCESS_DENIED); |
| 62 return; | 62 return; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const ResourceRequestInfoImpl* request_info = | 136 const ResourceRequestInfoImpl* request_info = |
| 137 ResourceRequestInfoImpl::ForRequest(request_); | 137 ResourceRequestInfoImpl::ForRequest(request_); |
| 138 | 138 |
| 139 // Deleted in DownloadManager. | 139 // Deleted in DownloadManager. |
| 140 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( | 140 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( |
| 141 base::Time::Now(), content_length_, | 141 base::Time::Now(), content_length_, |
| 142 request_->net_log(), request_info->HasUserGesture(), | 142 request_->net_log(), request_info->HasUserGesture(), |
| 143 request_info->GetPageTransition())); | 143 request_info->GetPageTransition())); |
| 144 | 144 |
| 145 // Create the ByteStream for sending data to the download sink. | 145 // Create the ByteStream for sending data to the download sink. |
| 146 scoped_ptr<ByteStreamReader> stream_reader; | 146 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream_reader; |
| 147 CreateByteStream( | 147 CreateByteStream<DownloadInterruptReason>( |
| 148 base::MessageLoopProxy::current(), | 148 base::MessageLoopProxy::current(), |
| 149 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 149 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 150 kDownloadByteStreamSize, &stream_writer_, &stream_reader); | 150 kDownloadByteStreamSize, &stream_writer_, &stream_reader); |
| 151 stream_writer_->RegisterCallback( | 151 stream_writer_->RegisterCallback( |
| 152 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); | 152 base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); |
| 153 | 153 |
| 154 info->download_id = download_id_; | 154 info->download_id = download_id_; |
| 155 info->url_chain = request_->url_chain(); | 155 info->url_chain = request_->url_chain(); |
| 156 info->referrer_url = GURL(request_->referrer()); | 156 info->referrer_url = GURL(request_->referrer()); |
| 157 info->start_time = base::Time::Now(); | 157 info->start_time = base::Time::Now(); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 482 |
| 483 // Remove output stream callback if a stream exists. | 483 // Remove output stream callback if a stream exists. |
| 484 if (stream_writer_) | 484 if (stream_writer_) |
| 485 stream_writer_->RegisterCallback(base::Closure()); | 485 stream_writer_->RegisterCallback(base::Closure()); |
| 486 | 486 |
| 487 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 487 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
| 488 base::TimeTicks::Now() - download_start_time_); | 488 base::TimeTicks::Now() - download_start_time_); |
| 489 } | 489 } |
| 490 | 490 |
| 491 } // namespace content | 491 } // namespace content |
| OLD | NEW |