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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/prefs/pref_member.h" | 25 #include "chrome/browser/prefs/pref_member.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/extensions/user_script.h" | 33 #include "chrome/common/extensions/user_script.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "content/browser/download/download_file.h" | |
36 #include "content/browser/download/download_status_updater.h" | 35 #include "content/browser/download/download_status_updater.h" |
37 #include "content/public/browser/download_item.h" | 36 #include "content/public/browser/download_item.h" |
38 #include "content/public/browser/download_manager.h" | 37 #include "content/public/browser/download_manager.h" |
39 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
41 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
42 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
43 | 42 |
44 using content::BrowserThread; | 43 using content::BrowserThread; |
45 using content::DownloadFile; | |
46 using content::DownloadId; | 44 using content::DownloadId; |
47 using content::DownloadItem; | 45 using content::DownloadItem; |
48 using content::DownloadManager; | 46 using content::DownloadManager; |
49 using content::WebContents; | 47 using content::WebContents; |
50 using safe_browsing::DownloadProtectionService; | 48 using safe_browsing::DownloadProtectionService; |
51 | 49 |
52 namespace { | 50 namespace { |
53 | 51 |
54 // String pointer used for identifying safebrowing data associated with | 52 // String pointer used for identifying safebrowing data associated with |
55 // a download item. | 53 // a download item. |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 state.suggested_path = path; | 517 state.suggested_path = path; |
520 } else { | 518 } else { |
521 // Do not add the path uniquifier if we are saving to a specific path as in | 519 // Do not add the path uniquifier if we are saving to a specific path as in |
522 // the drag-out case. | 520 // the drag-out case. |
523 if (state.force_file_name.empty()) { | 521 if (state.force_file_name.empty()) { |
524 state.path_uniquifier = download_util::GetUniquePathNumberWithCrDownload( | 522 state.path_uniquifier = download_util::GetUniquePathNumberWithCrDownload( |
525 state.suggested_path); | 523 state.suggested_path); |
526 } | 524 } |
527 // We know the final path, build it if necessary. | 525 // We know the final path, build it if necessary. |
528 if (state.path_uniquifier > 0) { | 526 if (state.path_uniquifier > 0) { |
529 DownloadFile::AppendNumberToPath(&(state.suggested_path), | 527 state.suggested_path = state.suggested_path.InsertBeforeExtensionASCII( |
530 state.path_uniquifier); | 528 StringPrintf(" (%d)", state.path_uniquifier)); |
531 // Setting path_uniquifier to 0 to make sure we don't try to unique it | 529 // Setting path_uniquifier to 0 to make sure we don't try to unique it |
532 // later on. | 530 // later on. |
533 state.path_uniquifier = 0; | 531 state.path_uniquifier = 0; |
534 } else if (state.path_uniquifier == -1) { | 532 } else if (state.path_uniquifier == -1) { |
535 // We failed to find a unique path. We have to prompt the user. | 533 // We failed to find a unique path. We have to prompt the user. |
536 VLOG(1) << "Unable to find a unique path for suggested path \"" | 534 VLOG(1) << "Unable to find a unique path for suggested path \"" |
537 << state.suggested_path.value() << "\""; | 535 << state.suggested_path.value() << "\""; |
538 state.prompt_user_for_save_location = true; | 536 state.prompt_user_for_save_location = true; |
539 } | 537 } |
540 } | 538 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 int32 download_id, int64 db_handle) { | 604 int32 download_id, int64 db_handle) { |
607 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 605 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
608 // call this function with an invalid |db_handle|. For instance, this can | 606 // call this function with an invalid |db_handle|. For instance, this can |
609 // happen when the history database is offline. We cannot have multiple | 607 // happen when the history database is offline. We cannot have multiple |
610 // DownloadItems with the same invalid db_handle, so we need to assign a | 608 // DownloadItems with the same invalid db_handle, so we need to assign a |
611 // unique |db_handle| here. | 609 // unique |db_handle| here. |
612 if (db_handle == DownloadItem::kUninitializedHandle) | 610 if (db_handle == DownloadItem::kUninitializedHandle) |
613 db_handle = download_history_->GetNextFakeDbHandle(); | 611 db_handle = download_history_->GetNextFakeDbHandle(); |
614 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 612 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
615 } | 613 } |
OLD | NEW |