Chromium Code Reviews| 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/location.h" | 10 #include "base/location.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 return; | 55 return; |
| 56 started_cb.Run(item, interrupt_reason); | 56 started_cb.Run(item, interrupt_reason); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Static function in order to prevent any accidental accesses to | 59 // Static function in order to prevent any accidental accesses to |
| 60 // DownloadResourceHandler members from the UI thread. | 60 // DownloadResourceHandler members from the UI thread. |
| 61 static void StartOnUIThread( | 61 static void StartOnUIThread( |
| 62 scoped_ptr<DownloadCreateInfo> info, | 62 scoped_ptr<DownloadCreateInfo> info, |
| 63 scoped_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info, | 63 scoped_ptr<DownloadResourceHandler::DownloadTabInfo> tab_info, |
| 64 scoped_ptr<ByteStreamReader> stream, | 64 scoped_ptr<ByteStreamReader> stream, |
| 65 DownloadManager* parent_download_manager, | |
| 65 const DownloadUrlParameters::OnStartedCallback& started_cb) { | 66 const DownloadUrlParameters::OnStartedCallback& started_cb) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 67 | 68 |
| 68 DownloadManager* download_manager = info->request_handle.GetDownloadManager(); | 69 DownloadManager* download_manager = info->request_handle.GetDownloadManager(); |
| 70 if (!download_manager) | |
| 71 download_manager = parent_download_manager; | |
|
asanka
2015/11/20 19:57:46
I'd do this the other way. I.e. if parent_download
svaldez
2015/11/23 15:18:56
Done.
| |
| 69 if (!download_manager) { | 72 if (!download_manager) { |
| 70 // NULL in unittests or if the page closed right after starting the | 73 // NULL in unittests or if the page closed right after starting the |
| 71 // download. | 74 // download. |
| 72 if (!started_cb.is_null()) | 75 if (!started_cb.is_null()) |
| 73 started_cb.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); | 76 started_cb.Run(NULL, DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); |
| 74 | 77 |
| 75 // |stream| gets deleted on non-FILE thread, but it's ok since | 78 // |stream| gets deleted on non-FILE thread, but it's ok since |
| 76 // we're not using stream_writer_ yet. | 79 // we're not using stream_writer_ yet. |
| 77 | 80 |
| 78 return; | 81 return; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 if (info->url_chain.size() > 1 && | 248 if (info->url_chain.size() > 1 && |
| 246 info->url_chain.front().GetOrigin() != info->url_chain.back().GetOrigin()) | 249 info->url_chain.front().GetOrigin() != info->url_chain.back().GetOrigin()) |
| 247 info->save_info->suggested_name.clear(); | 250 info->save_info->suggested_name.clear(); |
| 248 | 251 |
| 249 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
| 250 BrowserThread::UI, FROM_HERE, | 253 BrowserThread::UI, FROM_HERE, |
| 251 base::Bind(&StartOnUIThread, | 254 base::Bind(&StartOnUIThread, |
| 252 base::Passed(&info), | 255 base::Passed(&info), |
| 253 base::Passed(&tab_info_), | 256 base::Passed(&tab_info_), |
| 254 base::Passed(&stream_reader), | 257 base::Passed(&stream_reader), |
| 258 parent_download_manager_, | |
| 255 // Pass to StartOnUIThread so that variable | 259 // Pass to StartOnUIThread so that variable |
| 256 // access is always on IO thread but function | 260 // access is always on IO thread but function |
| 257 // is called on UI thread. | 261 // is called on UI thread. |
| 258 started_cb_)); | 262 started_cb_)); |
| 259 // Guaranteed to be called in StartOnUIThread | 263 // Guaranteed to be called in StartOnUIThread |
| 260 started_cb_.Reset(); | 264 started_cb_.Reset(); |
| 261 | 265 |
| 262 return true; | 266 return true; |
| 263 } | 267 } |
| 264 | 268 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 BrowserThread::PostTask( | 546 BrowserThread::PostTask( |
| 543 BrowserThread::UI, FROM_HERE, | 547 BrowserThread::UI, FROM_HERE, |
| 544 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); | 548 base::Bind(&DeleteOnUIThread, base::Passed(&tab_info_))); |
| 545 } | 549 } |
| 546 | 550 |
| 547 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 551 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
| 548 base::TimeTicks::Now() - download_start_time_); | 552 base::TimeTicks::Now() - download_start_time_); |
| 549 } | 553 } |
| 550 | 554 |
| 551 } // namespace content | 555 } // namespace content |
| OLD | NEW |