Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: content/browser/download/download_file_manager.cc

Issue 10950015: Shift "commit point" for when a download will no longer accept cancels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Done here on Windows so that anti-virus scanners invoked by
151 // the attachment service actually see the data; see 118 // the attachment service actually see the data; see
152 // http://crbug.com/127999. 119 // http://crbug.com/127999.
153 // Done here for mac because we only want to do this once; see 120 // Done here for mac because we only want to do this once; see
154 // http://crbug.com/13120 for details. 121 // http://crbug.com/13120 for details.
155 // Other platforms don't currently do source annotation. 122 // Other platforms don't currently do source annotation.
156 download_file->AnnotateWithSourceInformation(); 123 download_file->AnnotateWithSourceInformation();
asanka 2012/09/20 18:42:15 DownloadFileImpl::Detach() also does this.
Randy Smith (Not in Mondays) 2012/09/21 21:58:01 Ooops; thanks. Deleted.
157 124
158 download_file->Detach(); 125 download_file->Detach(callback);
159 126
160 EraseDownload(global_id); 127 EraseDownload(global_id);
161
162 // Notify our caller we've let it go.
163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
164 } 128 }
165 129
166 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { 130 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
168 DCHECK(manager); 132 DCHECK(manager);
169 133
170 std::set<DownloadFile*> to_remove; 134 std::set<DownloadFile*> to_remove;
171 135
172 for (DownloadFileMap::iterator i = downloads_.begin(); 136 for (DownloadFileMap::iterator i = downloads_.begin();
173 i != downloads_.end(); ++i) { 137 i != downloads_.end(); ++i) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DownloadFile* download_file = downloads_[global_id]; 182 DownloadFile* download_file = downloads_[global_id];
219 183
220 VLOG(20) << " " << __FUNCTION__ << "()" 184 VLOG(20) << " " << __FUNCTION__ << "()"
221 << " id = " << global_id 185 << " id = " << global_id
222 << " download_file = " << download_file->DebugString(); 186 << " download_file = " << download_file->DebugString();
223 187
224 downloads_.erase(global_id); 188 downloads_.erase(global_id);
225 189
226 delete download_file; 190 delete download_file;
227 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698