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

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

Issue 10696043: Shifted DownloadFile to exporting DownloadInterruptReasons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to TOT. Created 8 years, 5 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const net::BoundNetLog& bound_net_log, 93 const net::BoundNetLog& bound_net_log,
94 const CreateDownloadFileCallback& callback) { 94 const CreateDownloadFileCallback& callback) {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
96 DCHECK(info.get()); 96 DCHECK(info.get());
97 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); 97 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString();
98 98
99 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile( 99 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile(
100 info.get(), stream.Pass(), download_manager, get_hash, bound_net_log)); 100 info.get(), stream.Pass(), download_manager, get_hash, bound_net_log));
101 101
102 content::DownloadInterruptReason interrupt_reason( 102 content::DownloadInterruptReason interrupt_reason(
103 content::ConvertNetErrorToInterruptReason( 103 download_file->Initialize());
104 download_file->Initialize(), content::DOWNLOAD_INTERRUPT_FROM_DISK));
105 if (interrupt_reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) { 104 if (interrupt_reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) {
106 DCHECK(GetDownloadFile(info->download_id) == NULL); 105 DCHECK(GetDownloadFile(info->download_id) == NULL);
107 downloads_[info->download_id] = download_file.release(); 106 downloads_[info->download_id] = download_file.release();
108 } 107 }
109 108
110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
111 base::Bind(callback, interrupt_reason)); 110 base::Bind(callback, interrupt_reason));
112 } 111 }
113 112
114 DownloadFile* DownloadFileManager::GetDownloadFile( 113 DownloadFile* DownloadFileManager::GetDownloadFile(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Make the file unique if requested. 205 // Make the file unique if requested.
207 int uniquifier = 206 int uniquifier =
208 file_util::GetUniquePathNumber(new_path, FILE_PATH_LITERAL("")); 207 file_util::GetUniquePathNumber(new_path, FILE_PATH_LITERAL(""));
209 if (uniquifier > 0) { 208 if (uniquifier > 0) {
210 new_path = new_path.InsertBeforeExtensionASCII( 209 new_path = new_path.InsertBeforeExtensionASCII(
211 StringPrintf(" (%d)", uniquifier)); 210 StringPrintf(" (%d)", uniquifier));
212 } 211 }
213 } 212 }
214 213
215 // Do the actual rename 214 // Do the actual rename
216 net::Error rename_error = download_file->Rename(new_path); 215 content::DownloadInterruptReason rename_error =
217 if (net::OK != rename_error) { 216 download_file->Rename(new_path);
217 if (content::DOWNLOAD_INTERRUPT_REASON_NONE != rename_error) {
218 DownloadManager* download_manager = download_file->GetDownloadManager(); 218 DownloadManager* download_manager = download_file->GetDownloadManager();
219 DCHECK(download_manager); 219 DCHECK(download_manager);
220 220
221 BrowserThread::PostTask( 221 BrowserThread::PostTask(
222 BrowserThread::UI, FROM_HERE, 222 BrowserThread::UI, FROM_HERE,
223 base::Bind(&DownloadManager::OnDownloadInterrupted, 223 base::Bind(&DownloadManager::OnDownloadInterrupted,
224 download_manager, 224 download_manager,
225 global_id.local(), 225 global_id.local(),
226 download_file->BytesSoFar(), 226 download_file->BytesSoFar(),
227 download_file->GetHashState(), 227 download_file->GetHashState(),
228 content::ConvertNetErrorToInterruptReason( 228 rename_error));
229 rename_error,
230 content::DOWNLOAD_INTERRUPT_FROM_DISK)));
231 229
232 new_path.clear(); 230 new_path.clear();
233 } 231 }
234 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 232 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
235 base::Bind(callback, new_path)); 233 base::Bind(callback, new_path));
236 } 234 }
237 235
238 int DownloadFileManager::NumberOfActiveDownloads() const { 236 int DownloadFileManager::NumberOfActiveDownloads() const {
239 return downloads_.size(); 237 return downloads_.size();
240 } 238 }
241 239
242 void DownloadFileManager::EraseDownload(DownloadId global_id) { 240 void DownloadFileManager::EraseDownload(DownloadId global_id) {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
244 242
245 if (!ContainsKey(downloads_, global_id)) 243 if (!ContainsKey(downloads_, global_id))
246 return; 244 return;
247 245
248 DownloadFile* download_file = downloads_[global_id]; 246 DownloadFile* download_file = downloads_[global_id];
249 247
250 VLOG(20) << " " << __FUNCTION__ << "()" 248 VLOG(20) << " " << __FUNCTION__ << "()"
251 << " id = " << global_id 249 << " id = " << global_id
252 << " download_file = " << download_file->DebugString(); 250 << " download_file = " << download_file->DebugString();
253 251
254 downloads_.erase(global_id); 252 downloads_.erase(global_id);
255 253
256 delete download_file; 254 delete download_file;
257 } 255 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file_impl.cc ('k') | content/browser/download/download_file_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698