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_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 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/download_manager.h" | 24 #include "content/public/browser/download_manager.h" |
25 #include "content/public/browser/download_manager_delegate.h" | 25 #include "content/public/browser/download_manager_delegate.h" |
26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
27 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::DownloadFile; | 30 using content::DownloadFile; |
31 using content::DownloadId; | 31 using content::DownloadId; |
32 using content::DownloadManager; | 32 using content::DownloadManager; |
33 | 33 |
34 namespace { | 34 DownloadFileManager::DownloadFileManager(content::DownloadFileFactory* factory) |
35 | |
36 class DownloadFileFactoryImpl | |
37 : public DownloadFileManager::DownloadFileFactory { | |
38 public: | |
39 DownloadFileFactoryImpl() {} | |
40 | |
41 virtual content::DownloadFile* CreateFile( | |
42 DownloadCreateInfo* info, | |
43 scoped_ptr<content::ByteStreamReader> stream, | |
44 DownloadManager* download_manager, | |
45 bool calculate_hash, | |
46 const net::BoundNetLog& bound_net_log) OVERRIDE; | |
47 }; | |
48 | |
49 DownloadFile* DownloadFileFactoryImpl::CreateFile( | |
50 DownloadCreateInfo* info, | |
51 scoped_ptr<content::ByteStreamReader> stream, | |
52 DownloadManager* download_manager, | |
53 bool calculate_hash, | |
54 const net::BoundNetLog& bound_net_log) { | |
55 return new DownloadFileImpl( | |
56 info, stream.Pass(), new DownloadRequestHandle(info->request_handle), | |
57 download_manager, calculate_hash, | |
58 scoped_ptr<content::PowerSaveBlocker>( | |
59 new content::PowerSaveBlocker( | |
60 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
61 "Download in progress")).Pass(), | |
62 bound_net_log); | |
63 } | |
64 | |
65 } // namespace | |
66 | |
67 DownloadFileManager::DownloadFileManager(DownloadFileFactory* factory) | |
68 : download_file_factory_(factory) { | 35 : download_file_factory_(factory) { |
69 if (download_file_factory_ == NULL) | 36 if (download_file_factory_ == NULL) |
70 download_file_factory_.reset(new DownloadFileFactoryImpl); | 37 download_file_factory_.reset(new content::DownloadFileFactory); |
71 } | 38 } |
72 | 39 |
73 DownloadFileManager::~DownloadFileManager() { | 40 DownloadFileManager::~DownloadFileManager() { |
74 DCHECK(downloads_.empty()); | 41 DCHECK(downloads_.empty()); |
75 } | 42 } |
76 | 43 |
77 void DownloadFileManager::Shutdown() { | 44 void DownloadFileManager::Shutdown() { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
79 BrowserThread::PostTask( | 46 BrowserThread::PostTask( |
80 BrowserThread::FILE, FROM_HERE, | 47 BrowserThread::FILE, FROM_HERE, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 107 |
141 if (!ContainsKey(downloads_, global_id)) | 108 if (!ContainsKey(downloads_, global_id)) |
142 return; | 109 return; |
143 | 110 |
144 DownloadFile* download_file = downloads_[global_id]; | 111 DownloadFile* download_file = downloads_[global_id]; |
145 | 112 |
146 VLOG(20) << " " << __FUNCTION__ << "()" | 113 VLOG(20) << " " << __FUNCTION__ << "()" |
147 << " id = " << global_id | 114 << " id = " << global_id |
148 << " download_file = " << download_file->DebugString(); | 115 << " download_file = " << download_file->DebugString(); |
149 | 116 |
150 // Done here on Windows so that anti-virus scanners invoked by | 117 download_file->Detach(callback); |
151 // the attachment service actually see the data; see | |
152 // http://crbug.com/127999. | |
153 // Done here for mac because we only want to do this once; see | |
154 // http://crbug.com/13120 for details. | |
155 // Other platforms don't currently do source annotation. | |
156 download_file->AnnotateWithSourceInformation(); | |
157 | |
158 download_file->Detach(); | |
159 | 118 |
160 EraseDownload(global_id); | 119 EraseDownload(global_id); |
161 | |
162 // Notify our caller we've let it go. | |
163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
164 } | 120 } |
165 | 121 |
166 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { | 122 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
168 DCHECK(manager); | 124 DCHECK(manager); |
169 | 125 |
170 std::set<DownloadFile*> to_remove; | 126 std::set<DownloadFile*> to_remove; |
171 | 127 |
172 for (DownloadFileMap::iterator i = downloads_.begin(); | 128 for (DownloadFileMap::iterator i = downloads_.begin(); |
173 i != downloads_.end(); ++i) { | 129 i != downloads_.end(); ++i) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 DownloadFile* download_file = downloads_[global_id]; | 174 DownloadFile* download_file = downloads_[global_id]; |
219 | 175 |
220 VLOG(20) << " " << __FUNCTION__ << "()" | 176 VLOG(20) << " " << __FUNCTION__ << "()" |
221 << " id = " << global_id | 177 << " id = " << global_id |
222 << " download_file = " << download_file->DebugString(); | 178 << " download_file = " << download_file->DebugString(); |
223 | 179 |
224 downloads_.erase(global_id); | 180 downloads_.erase(global_id); |
225 | 181 |
226 delete download_file; | 182 delete download_file; |
227 } | 183 } |
OLD | NEW |