| OLD | NEW |
| 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/download/download_file_manager.h" | 5 #include "chrome/browser/download/download_file_manager.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Throttle updates to the UI thread so that a fast moving download doesn't | 31 // Throttle updates to the UI thread so that a fast moving download doesn't |
| 32 // cause it to become unresponsive (in milliseconds). | 32 // cause it to become unresponsive (in milliseconds). |
| 33 const int kUpdatePeriodMs = 500; | 33 const int kUpdatePeriodMs = 500; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) | 37 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) |
| 38 : next_id_(0), | 38 : resource_dispatcher_host_(rdh) { |
| 39 resource_dispatcher_host_(rdh) { | |
| 40 } | 39 } |
| 41 | 40 |
| 42 DownloadFileManager::~DownloadFileManager() { | 41 DownloadFileManager::~DownloadFileManager() { |
| 43 DCHECK(downloads_.empty()); | 42 DCHECK(downloads_.empty()); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void DownloadFileManager::Shutdown() { | 45 void DownloadFileManager::Shutdown() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 BrowserThread::PostTask( | 47 BrowserThread::PostTask( |
| 49 BrowserThread::FILE, FROM_HERE, | 48 BrowserThread::FILE, FROM_HERE, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 DownloadFile* download_file = i->second; | 113 DownloadFile* download_file = i->second; |
| 115 DownloadManager* manager = download_file->GetDownloadManager(); | 114 DownloadManager* manager = download_file->GetDownloadManager(); |
| 116 if (manager) { | 115 if (manager) { |
| 117 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 118 NewRunnableMethod(manager, &DownloadManager::UpdateDownload, | 117 NewRunnableMethod(manager, &DownloadManager::UpdateDownload, |
| 119 id, download_file->bytes_so_far())); | 118 id, download_file->bytes_so_far())); |
| 120 } | 119 } |
| 121 } | 120 } |
| 122 } | 121 } |
| 123 | 122 |
| 124 // Called on the IO thread once the ResourceDispatcherHost has decided that a | |
| 125 // request is a download. | |
| 126 int DownloadFileManager::GetNextId() { | |
| 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 128 return next_id_++; | |
| 129 } | |
| 130 | |
| 131 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { | 123 void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { |
| 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 133 DCHECK(info); | 125 DCHECK(info); |
| 134 | 126 |
| 135 DownloadManager* manager = info->request_handle.GetDownloadManager(); | 127 DownloadManager* manager = info->request_handle.GetDownloadManager(); |
| 136 if (!manager) { | 128 if (!manager) { |
| 137 info->request_handle.CancelRequest(); | 129 info->request_handle.CancelRequest(); |
| 138 delete info; | 130 delete info; |
| 139 return; | 131 return; |
| 140 } | 132 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 << " id = " << id | 384 << " id = " << id |
| 393 << " download_file = " << download_file->DebugString(); | 385 << " download_file = " << download_file->DebugString(); |
| 394 | 386 |
| 395 downloads_.erase(id); | 387 downloads_.erase(id); |
| 396 | 388 |
| 397 delete download_file; | 389 delete download_file; |
| 398 | 390 |
| 399 if (downloads_.empty()) | 391 if (downloads_.empty()) |
| 400 StopUpdateTimer(); | 392 StopUpdateTimer(); |
| 401 } | 393 } |
| OLD | NEW |