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

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

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merged db_handle, id; onCreated, onErased Created 9 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
« no previous file with comments | « no previous file | chrome/browser/download/download_history.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/download/download_file_manager.h" 5 #include "chrome/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-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/task.h" 10 #include "base/task.h"
(...skipping 17 matching lines...) Expand all
28 28
29 namespace { 29 namespace {
30 30
31 // Throttle updates to the UI thread so that a fast moving download doesn't 31 // Throttle updates to the UI thread so that a fast moving download doesn't
32 // cause it to become unresponsive (in milliseconds). 32 // cause it to become unresponsive (in milliseconds).
33 const int kUpdatePeriodMs = 500; 33 const int kUpdatePeriodMs = 500;
34 34
35 } // namespace 35 } // namespace
36 36
37 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) 37 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh)
38 : next_id_(0), 38 : resource_dispatcher_host_(rdh) {
39 resource_dispatcher_host_(rdh) {
40 } 39 }
41 40
42 DownloadFileManager::~DownloadFileManager() { 41 DownloadFileManager::~DownloadFileManager() {
43 DCHECK(downloads_.empty()); 42 DCHECK(downloads_.empty());
44 } 43 }
45 44
46 void DownloadFileManager::Shutdown() { 45 void DownloadFileManager::Shutdown() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 BrowserThread::PostTask( 47 BrowserThread::PostTask(
49 BrowserThread::FILE, FROM_HERE, 48 BrowserThread::FILE, FROM_HERE,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DownloadFile* download_file = it->second; 226 DownloadFile* download_file = it->second;
228 VLOG(20) << __FUNCTION__ << "()" 227 VLOG(20) << __FUNCTION__ << "()"
229 << " download_file = " << download_file->DebugString(); 228 << " download_file = " << download_file->DebugString();
230 download_file->Cancel(); 229 download_file->Cancel();
231 230
232 EraseDownload(id); 231 EraseDownload(id);
233 } 232 }
234 233
235 void DownloadFileManager::CompleteDownload(int id) { 234 void DownloadFileManager::CompleteDownload(int id) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
236 DVLOG(1) << __FUNCTION__ << " " << id;
237 237
238 if (!ContainsKey(downloads_, id)) 238 if (!ContainsKey(downloads_, id))
239 return; 239 return;
240 240
241 DownloadFile* download_file = downloads_[id]; 241 DownloadFile* download_file = downloads_[id];
242 242
243 VLOG(20) << " " << __FUNCTION__ << "()" 243 DVLOG(1) << " " << __FUNCTION__ << "()"
244 << " id = " << id 244 << " id = " << id
245 << " download_file = " << download_file->DebugString(); 245 << " download_file = " << download_file->DebugString();
246 246
247 download_file->Detach(); 247 download_file->Detach();
248 248
249 EraseDownload(id); 249 EraseDownload(id);
250 } 250 }
251 251
252 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) { 252 void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 28 matching lines...) Expand all
282 void DownloadFileManager::RenameInProgressDownloadFile( 282 void DownloadFileManager::RenameInProgressDownloadFile(
283 int id, const FilePath& full_path) { 283 int id, const FilePath& full_path) {
284 VLOG(20) << __FUNCTION__ << "()" << " id = " << id 284 VLOG(20) << __FUNCTION__ << "()" << " id = " << id
285 << " full_path = \"" << full_path.value() << "\""; 285 << " full_path = \"" << full_path.value() << "\"";
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
287 287
288 DownloadFile* download_file = GetDownloadFile(id); 288 DownloadFile* download_file = GetDownloadFile(id);
289 if (!download_file) 289 if (!download_file)
290 return; 290 return;
291 291
292 VLOG(20) << __FUNCTION__ << "()" 292 DVLOG(1) << __FUNCTION__ << "()"
293 << " download_file = " << download_file->DebugString(); 293 << " download_file = " << download_file->DebugString();
294 294
295 if (!download_file->Rename(full_path)) { 295 if (!download_file->Rename(full_path)) {
296 DVLOG(1) << __FUNCTION__ << " " << id;
296 // Error. Between the time the UI thread generated 'full_path' to the time 297 // Error. Between the time the UI thread generated 'full_path' to the time
297 // this code runs, something happened that prevents us from renaming. 298 // this code runs, something happened that prevents us from renaming.
298 CancelDownloadOnRename(id); 299 CancelDownloadOnRename(id);
299 } 300 }
300 } 301 }
301 302
302 // The DownloadManager in the UI thread has provided a final name for the 303 // The DownloadManager in the UI thread has provided a final name for the
303 // download specified by 'id'. Rename the download that's in the process 304 // download specified by 'id'. Rename the download that's in the process
304 // of completing. 305 // of completing.
305 // 306 //
306 // There are 2 possible rename cases where this method can be called: 307 // There are 2 possible rename cases where this method can be called:
307 // 1. foo.crdownload -> foo (final, safe) 308 // 1. foo.crdownload -> foo (final, safe)
308 // 2. Unconfirmed.xxx.crdownload -> xxx (final, validated) 309 // 2. Unconfirmed.xxx.crdownload -> xxx (final, validated)
309 void DownloadFileManager::RenameCompletingDownloadFile( 310 void DownloadFileManager::RenameCompletingDownloadFile(
310 int id, const FilePath& full_path, bool overwrite_existing_file) { 311 int id, const FilePath& full_path, bool overwrite_existing_file) {
311 VLOG(20) << __FUNCTION__ << "()" << " id = " << id 312 DVLOG(1) << __FUNCTION__ << "()" << " id = " << id
312 << " overwrite_existing_file = " << overwrite_existing_file 313 << " overwrite_existing_file = " << overwrite_existing_file
313 << " full_path = \"" << full_path.value() << "\""; 314 << " full_path = \"" << full_path.value() << "\"";
314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
315 316
316 DownloadFile* download_file = GetDownloadFile(id); 317 DownloadFile* download_file = GetDownloadFile(id);
318 DVLOG(1) << __FUNCTION__ << " " << download_file;
317 if (!download_file) 319 if (!download_file)
318 return; 320 return;
319 321
320 DCHECK(download_file->GetDownloadManager()); 322 DCHECK(download_file->GetDownloadManager());
321 DownloadManager* download_manager = download_file->GetDownloadManager(); 323 DownloadManager* download_manager = download_file->GetDownloadManager();
322 324
323 VLOG(20) << __FUNCTION__ << "()" 325 VLOG(20) << __FUNCTION__ << "()"
324 << " download_file = " << download_file->DebugString(); 326 << " download_file = " << download_file->DebugString();
325 327
326 int uniquifier = 0; 328 int uniquifier = 0;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 << " id = " << id 398 << " id = " << id
397 << " download_file = " << download_file->DebugString(); 399 << " download_file = " << download_file->DebugString();
398 400
399 downloads_.erase(id); 401 downloads_.erase(id);
400 402
401 delete download_file; 403 delete download_file;
402 404
403 if (downloads_.empty()) 405 if (downloads_.empty())
404 StopUpdateTimer(); 406 StopUpdateTimer();
405 } 407 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_history.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698