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 "content/browser/download/download_file_manager.h" | 5 #include "content/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.h" | 9 #include "base/stl_util.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Life of |info| ends here. No more references to it after this method. | 60 // Life of |info| ends here. No more references to it after this method. |
61 scoped_ptr<DownloadCreateInfo> infop(info); | 61 scoped_ptr<DownloadCreateInfo> infop(info); |
62 | 62 |
63 scoped_ptr<DownloadFile> | 63 scoped_ptr<DownloadFile> |
64 download_file(new DownloadFile(info, request_handle, download_manager)); | 64 download_file(new DownloadFile(info, request_handle, download_manager)); |
65 if (net::OK != download_file->Initialize(get_hash)) { | 65 if (net::OK != download_file->Initialize(get_hash)) { |
66 request_handle.CancelRequest(); | 66 request_handle.CancelRequest(); |
67 return; | 67 return; |
68 } | 68 } |
69 | 69 |
70 DownloadId global_id(download_manager, info->download_id); | 70 DCHECK(GetDownloadFile(info->download_id) == NULL); |
71 DCHECK(GetDownloadFile(global_id) == NULL); | 71 downloads_[info->download_id] = download_file.release(); |
72 downloads_[global_id] = download_file.release(); | |
73 | 72 |
74 // The file is now ready, we can un-pause the request and start saving data. | 73 // The file is now ready, we can un-pause the request and start saving data. |
75 request_handle.ResumeRequest(); | 74 request_handle.ResumeRequest(); |
76 | 75 |
77 StartUpdateTimer(); | 76 StartUpdateTimer(); |
78 | 77 |
79 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
80 BrowserThread::UI, FROM_HERE, | 79 BrowserThread::UI, FROM_HERE, |
81 NewRunnableMethod(download_manager, | 80 NewRunnableMethod(download_manager, |
82 &DownloadManager::StartDownload, info->download_id)); | 81 &DownloadManager::StartDownload, |
| 82 info->download_id.local())); |
83 } | 83 } |
84 | 84 |
85 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { | 85 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { |
86 DownloadFileMap::iterator it = downloads_.find(global_id); | 86 DownloadFileMap::iterator it = downloads_.find(global_id); |
87 return it == downloads_.end() ? NULL : it->second; | 87 return it == downloads_.end() ? NULL : it->second; |
88 } | 88 } |
89 | 89 |
90 void DownloadFileManager::StartUpdateTimer() { | 90 void DownloadFileManager::StartUpdateTimer() { |
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
92 if (!update_timer_.IsRunning()) { | 92 if (!update_timer_.IsRunning()) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 i != downloads_.end(); ++i) { | 283 i != downloads_.end(); ++i) { |
284 DownloadFile* download_file = i->second; | 284 DownloadFile* download_file = i->second; |
285 if (download_file->GetDownloadManager() == manager) { | 285 if (download_file->GetDownloadManager() == manager) { |
286 download_file->CancelDownloadRequest(); | 286 download_file->CancelDownloadRequest(); |
287 to_remove.insert(download_file); | 287 to_remove.insert(download_file); |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); | 291 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); |
292 i != to_remove.end(); ++i) { | 292 i != to_remove.end(); ++i) { |
293 downloads_.erase(DownloadId((*i)->GetDownloadManager(), (*i)->id())); | 293 downloads_.erase((*i)->global_id()); |
294 delete *i; | 294 delete *i; |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 // Actions from the UI thread and run on the download thread | 298 // Actions from the UI thread and run on the download thread |
299 | 299 |
300 // The DownloadManager in the UI thread has provided an intermediate .crdownload | 300 // The DownloadManager in the UI thread has provided an intermediate .crdownload |
301 // name for the download specified by 'id'. Rename the in progress download. | 301 // name for the download specified by 'id'. Rename the in progress download. |
302 // | 302 // |
303 // There are 2 possible rename cases where this method can be called: | 303 // There are 2 possible rename cases where this method can be called: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 << " id = " << global_id | 430 << " id = " << global_id |
431 << " download_file = " << download_file->DebugString(); | 431 << " download_file = " << download_file->DebugString(); |
432 | 432 |
433 downloads_.erase(global_id); | 433 downloads_.erase(global_id); |
434 | 434 |
435 delete download_file; | 435 delete download_file; |
436 | 436 |
437 if (downloads_.empty()) | 437 if (downloads_.empty()) |
438 StopUpdateTimer(); | 438 StopUpdateTimer(); |
439 } | 439 } |
OLD | NEW |