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

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

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r148594 to and resolve conflicts with r148576 Created 8 years, 4 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 "chrome/browser/download/download_file_picker.h" 5 #include "chrome/browser/download/download_file_picker.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (suggested_path.DirName() != actual_path.DirName()) 51 if (suggested_path.DirName() != actual_path.DirName())
52 return FILE_PICKER_DIFFERENT_DIR; 52 return FILE_PICKER_DIFFERENT_DIR;
53 return FILE_PICKER_DIFFERENT_NAME; 53 return FILE_PICKER_DIFFERENT_NAME;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 DownloadFilePicker::DownloadFilePicker() : download_id_(0) { 58 DownloadFilePicker::DownloadFilePicker() : download_id_(0) {
59 } 59 }
60 60
61 void DownloadFilePicker::Init(DownloadManager* download_manager, 61 void DownloadFilePicker::Init(
62 DownloadItem* item) { 62 DownloadManager* download_manager,
63 DownloadItem* item,
64 const FilePath& suggested_path,
65 const ChromeDownloadManagerDelegate::FileSelectedCallback& callback) {
63 download_manager_ = download_manager; 66 download_manager_ = download_manager;
64 download_id_ = item->GetId(); 67 download_id_ = item->GetId();
65 InitSuggestedPath(item); 68 file_selected_callback_ = callback;
69 InitSuggestedPath(item, suggested_path);
66 70
67 DCHECK(download_manager_); 71 DCHECK(download_manager_);
68 WebContents* web_contents = item->GetWebContents(); 72 WebContents* web_contents = item->GetWebContents();
69 select_file_dialog_ = SelectFileDialog::Create( 73 select_file_dialog_ = SelectFileDialog::Create(
70 this, new ChromeSelectFilePolicy(web_contents)); 74 this, new ChromeSelectFilePolicy(web_contents));
71 SelectFileDialog::FileTypeInfo file_type_info; 75 SelectFileDialog::FileTypeInfo file_type_info;
72 FilePath::StringType extension = suggested_path_.Extension(); 76 FilePath::StringType extension = suggested_path_.Extension();
73 if (!extension.empty()) { 77 if (!extension.empty()) {
74 extension.erase(extension.begin()); // drop the . 78 extension.erase(extension.begin()); // drop the .
75 file_type_info.extensions.resize(1); 79 file_type_info.extensions.resize(1);
(...skipping 10 matching lines...) Expand all
86 &file_type_info, 90 &file_type_info,
87 0, 91 0,
88 FILE_PATH_LITERAL(""), 92 FILE_PATH_LITERAL(""),
89 owning_window, 93 owning_window,
90 NULL); 94 NULL);
91 } 95 }
92 96
93 DownloadFilePicker::~DownloadFilePicker() { 97 DownloadFilePicker::~DownloadFilePicker() {
94 } 98 }
95 99
96 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item) { 100 void DownloadFilePicker::InitSuggestedPath(DownloadItem* item,
97 set_suggested_path(item->GetTargetFilePath()); 101 const FilePath& suggested_path) {
102 set_suggested_path(suggested_path);
103 }
104
105 void DownloadFilePicker::OnFileSelected(const FilePath& path) {
106 file_selected_callback_.Run(path);
107 delete this;
98 } 108 }
99 109
100 void DownloadFilePicker::RecordFileSelected(const FilePath& path) { 110 void DownloadFilePicker::RecordFileSelected(const FilePath& path) {
101 FilePickerResult result = ComparePaths(suggested_path_, path); 111 FilePickerResult result = ComparePaths(suggested_path_, path);
102 RecordFilePickerResult(download_manager_, result); 112 RecordFilePickerResult(download_manager_, result);
103 } 113 }
104 114
105 void DownloadFilePicker::FileSelected(const FilePath& path, 115 void DownloadFilePicker::FileSelected(const FilePath& path,
106 int index, 116 int index,
107 void* params) { 117 void* params) {
108 RecordFileSelected(path); 118 RecordFileSelected(path);
109 119 OnFileSelected(path);
110 if (download_manager_) 120 // Deletes |this|
111 download_manager_->FileSelected(path, download_id_);
112 delete this;
113 } 121 }
114 122
115 void DownloadFilePicker::FileSelectionCanceled(void* params) { 123 void DownloadFilePicker::FileSelectionCanceled(void* params) {
116 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL); 124 RecordFilePickerResult(download_manager_, FILE_PICKER_CANCEL);
117 if (download_manager_) 125 OnFileSelected(FilePath());
118 download_manager_->FileSelectionCanceled(download_id_); 126 // Deletes |this|
119 delete this;
120 } 127 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file_picker.h ('k') | chrome/browser/download/download_file_picker_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698