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

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

Issue 2877008: Rename the download to its final name only after the download is finished (Closed)
Patch Set: rebase Created 10 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
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Download utility implementation 5 // Download utility implementation
6 6
7 #include "chrome/browser/download/download_util.h" 7 #include "chrome/browser/download/download_util.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shobjidl.h> 10 #include <shobjidl.h>
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 context); 541 context);
542 } 542 }
543 543
544 void CancelDownloadRequest(ResourceDispatcherHost* rdh, 544 void CancelDownloadRequest(ResourceDispatcherHost* rdh,
545 int render_process_id, 545 int render_process_id,
546 int request_id) { 546 int request_id) {
547 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 547 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
548 rdh->CancelRequest(render_process_id, request_id, false); 548 rdh->CancelRequest(render_process_id, request_id, false);
549 } 549 }
550 550
551 int GetUniquePathNumberWithCrDownload(const FilePath& path) {
552 const int kMaxAttempts = 100;
553
554 if (!file_util::PathExists(path) &&
555 !file_util::PathExists(GetCrDownloadPath(path)))
556 return 0;
557
558 FilePath new_path;
559 for (int count = 1; count <= kMaxAttempts; ++count) {
560 new_path = FilePath(path);
561 AppendNumberToPath(&new_path, count);
562
563 if (!file_util::PathExists(new_path) &&
564 !file_util::PathExists(GetCrDownloadPath(new_path)))
565 return count;
566 }
567
568 return -1;
569 }
570
571 FilePath GetCrDownloadPath(const FilePath& suggested_path) {
572 FilePath::StringType file_name;
573 SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
574 suggested_path.value().c_str());
575 return FilePath(file_name);
576 }
577
551 } // namespace download_util 578 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698