| 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/download_file_picker.h" | 5 #include "chrome/browser/download/download_file_picker.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/platform_util.h" | 9 #include "chrome/browser/platform_util.h" |
| 10 #include "chrome/browser/ui/chrome_select_file_policy.h" | 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 else | 42 else |
| 43 result = FILE_PICKER_DIFFERENT_NAME; | 43 result = FILE_PICKER_DIFFERENT_NAME; |
| 44 | 44 |
| 45 UMA_HISTOGRAM_ENUMERATION("Download.FilePickerResult", | 45 UMA_HISTOGRAM_ENUMERATION("Download.FilePickerResult", |
| 46 result, | 46 result, |
| 47 FILE_PICKER_MAX); | 47 FILE_PICKER_MAX); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 DownloadFilePicker::DownloadFilePicker( | 52 DownloadFilePicker::DownloadFilePicker(DownloadItem* item, |
| 53 DownloadItem* item, | 53 const base::FilePath& suggested_path, |
| 54 const base::FilePath& suggested_path, | 54 const ConfirmationCallback& callback) |
| 55 const FileSelectedCallback& callback) | |
| 56 : suggested_path_(suggested_path), | 55 : suggested_path_(suggested_path), |
| 57 file_selected_callback_(callback), | 56 file_selected_callback_(callback), |
| 58 should_record_file_picker_result_(false) { | 57 should_record_file_picker_result_(false) { |
| 59 const DownloadPrefs* prefs = | 58 const DownloadPrefs* prefs = |
| 60 DownloadPrefs::FromBrowserContext(item->GetBrowserContext()); | 59 DownloadPrefs::FromBrowserContext(item->GetBrowserContext()); |
| 61 DCHECK(prefs); | 60 DCHECK(prefs); |
| 62 // Only record UMA if we aren't prompting the user for all downloads. | 61 // Only record UMA if we aren't prompting the user for all downloads. |
| 63 should_record_file_picker_result_ = !prefs->PromptForDownload(); | 62 should_record_file_picker_result_ = !prefs->PromptForDownload(); |
| 64 | 63 |
| 65 WebContents* web_contents = item->GetWebContents(); | 64 WebContents* web_contents = item->GetWebContents(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 owning_window, | 96 owning_window, |
| 98 NULL); | 97 NULL); |
| 99 } | 98 } |
| 100 | 99 |
| 101 DownloadFilePicker::~DownloadFilePicker() { | 100 DownloadFilePicker::~DownloadFilePicker() { |
| 102 } | 101 } |
| 103 | 102 |
| 104 void DownloadFilePicker::OnFileSelected(const base::FilePath& path) { | 103 void DownloadFilePicker::OnFileSelected(const base::FilePath& path) { |
| 105 if (should_record_file_picker_result_) | 104 if (should_record_file_picker_result_) |
| 106 RecordFilePickerResult(suggested_path_, path); | 105 RecordFilePickerResult(suggested_path_, path); |
| 107 file_selected_callback_.Run(path); | 106 file_selected_callback_.Run(path.empty() |
| 107 ? DownloadConfirmationResult::CANCELED |
| 108 : DownloadConfirmationResult::CONFIRMED, |
| 109 path); |
| 108 delete this; | 110 delete this; |
| 109 } | 111 } |
| 110 | 112 |
| 111 void DownloadFilePicker::FileSelected(const base::FilePath& path, | 113 void DownloadFilePicker::FileSelected(const base::FilePath& path, |
| 112 int index, | 114 int index, |
| 113 void* params) { | 115 void* params) { |
| 114 OnFileSelected(path); | 116 OnFileSelected(path); |
| 115 // Deletes |this| | 117 // Deletes |this| |
| 116 } | 118 } |
| 117 | 119 |
| 118 void DownloadFilePicker::FileSelectionCanceled(void* params) { | 120 void DownloadFilePicker::FileSelectionCanceled(void* params) { |
| 119 OnFileSelected(base::FilePath()); | 121 OnFileSelected(base::FilePath()); |
| 120 // Deletes |this| | 122 // Deletes |this| |
| 121 } | 123 } |
| 122 | 124 |
| 123 // static | 125 // static |
| 124 void DownloadFilePicker::ShowFilePicker(DownloadItem* item, | 126 void DownloadFilePicker::ShowFilePicker(DownloadItem* item, |
| 125 const base::FilePath& suggested_path, | 127 const base::FilePath& suggested_path, |
| 126 const FileSelectedCallback& callback) { | 128 const ConfirmationCallback& callback) { |
| 127 new DownloadFilePicker(item, suggested_path, callback); | 129 new DownloadFilePicker(item, suggested_path, callback); |
| 128 // DownloadFilePicker deletes itself. | 130 // DownloadFilePicker deletes itself. |
| 129 } | 131 } |
| OLD | NEW |