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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Life of |info| ends here. No more references to it after this method. | 63 // Life of |info| ends here. No more references to it after this method. |
64 scoped_ptr<DownloadCreateInfo> infop(info); | 64 scoped_ptr<DownloadCreateInfo> infop(info); |
65 | 65 |
66 scoped_ptr<DownloadFile> | 66 scoped_ptr<DownloadFile> |
67 download_file(new DownloadFile(info, request_handle, download_manager)); | 67 download_file(new DownloadFile(info, request_handle, download_manager)); |
68 if (net::OK != download_file->Initialize(get_hash)) { | 68 if (net::OK != download_file->Initialize(get_hash)) { |
69 request_handle.CancelRequest(); | 69 request_handle.CancelRequest(); |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 DownloadId global_id(download_manager, info->download_id); | 73 DCHECK(GetDownloadFile(info->download_id) == NULL); |
74 DCHECK(GetDownloadFile(global_id) == NULL); | 74 downloads_[info->download_id] = download_file.release(); |
75 downloads_[global_id] = download_file.release(); | |
76 | 75 |
77 // The file is now ready, we can un-pause the request and start saving data. | 76 // The file is now ready, we can un-pause the request and start saving data. |
78 request_handle.ResumeRequest(); | 77 request_handle.ResumeRequest(); |
79 | 78 |
80 StartUpdateTimer(); | 79 StartUpdateTimer(); |
81 | 80 |
82 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
83 BrowserThread::UI, FROM_HERE, | 82 BrowserThread::UI, FROM_HERE, |
84 base::Bind(&DownloadManager::StartDownload, download_manager, | 83 base::Bind(&DownloadManager::StartDownload, download_manager, |
85 info->download_id)); | 84 info->download_id.local())); |
86 } | 85 } |
87 | 86 |
88 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { | 87 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { |
89 DownloadFileMap::iterator it = downloads_.find(global_id); | 88 DownloadFileMap::iterator it = downloads_.find(global_id); |
90 return it == downloads_.end() ? NULL : it->second; | 89 return it == downloads_.end() ? NULL : it->second; |
91 } | 90 } |
92 | 91 |
93 void DownloadFileManager::StartUpdateTimer() { | 92 void DownloadFileManager::StartUpdateTimer() { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
95 if (!update_timer_.IsRunning()) { | 94 if (!update_timer_.IsRunning()) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 i != downloads_.end(); ++i) { | 272 i != downloads_.end(); ++i) { |
274 DownloadFile* download_file = i->second; | 273 DownloadFile* download_file = i->second; |
275 if (download_file->GetDownloadManager() == manager) { | 274 if (download_file->GetDownloadManager() == manager) { |
276 download_file->CancelDownloadRequest(); | 275 download_file->CancelDownloadRequest(); |
277 to_remove.insert(download_file); | 276 to_remove.insert(download_file); |
278 } | 277 } |
279 } | 278 } |
280 | 279 |
281 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); | 280 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); |
282 i != to_remove.end(); ++i) { | 281 i != to_remove.end(); ++i) { |
283 downloads_.erase(DownloadId((*i)->GetDownloadManager(), (*i)->id())); | 282 downloads_.erase((*i)->global_id()); |
284 delete *i; | 283 delete *i; |
285 } | 284 } |
286 } | 285 } |
287 | 286 |
288 // Actions from the UI thread and run on the download thread | 287 // Actions from the UI thread and run on the download thread |
289 | 288 |
290 // The DownloadManager in the UI thread has provided an intermediate .crdownload | 289 // The DownloadManager in the UI thread has provided an intermediate .crdownload |
291 // name for the download specified by 'id'. Rename the in progress download. | 290 // name for the download specified by 'id'. Rename the in progress download. |
292 // | 291 // |
293 // There are 2 possible rename cases where this method can be called: | 292 // There are 2 possible rename cases where this method can be called: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 << " id = " << global_id | 416 << " id = " << global_id |
418 << " download_file = " << download_file->DebugString(); | 417 << " download_file = " << download_file->DebugString(); |
419 | 418 |
420 downloads_.erase(global_id); | 419 downloads_.erase(global_id); |
421 | 420 |
422 delete download_file; | 421 delete download_file; |
423 | 422 |
424 if (downloads_.empty()) | 423 if (downloads_.empty()) |
425 StopUpdateTimer(); | 424 StopUpdateTimer(); |
426 } | 425 } |
OLD | NEW |