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

Side by Side Diff: chrome/browser/file_select_helper.cc

Issue 2450543002: Directory upload: remember the last directory chosen, not its parent (Closed)
Patch Set: Tweak test file paths Created 4 years, 1 month 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/file_select_helper.h ('k') | chrome/browser/file_select_helper_unittest.cc » ('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) 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/file_select_helper.h" 5 #include "chrome/browser/file_select_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return selected_files; 78 return selected_files;
79 } 79 }
80 80
81 void DeleteFiles(const std::vector<base::FilePath>& paths) { 81 void DeleteFiles(const std::vector<base::FilePath>& paths) {
82 for (auto& file_path : paths) 82 for (auto& file_path : paths)
83 base::DeleteFile(file_path, false); 83 base::DeleteFile(file_path, false);
84 } 84 }
85 85
86 bool IsValidProfile(Profile* profile) { 86 bool IsValidProfile(Profile* profile) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 // No profile manager in unit tests.
89 if (!g_browser_process->profile_manager())
90 return true;
88 return g_browser_process->profile_manager()->IsValidProfile(profile); 91 return g_browser_process->profile_manager()->IsValidProfile(profile);
89 } 92 }
90 93
91 #if defined(FULL_SAFE_BROWSING) 94 #if defined(FULL_SAFE_BROWSING)
92 95
93 bool IsDownloadAllowedBySafeBrowsing( 96 bool IsDownloadAllowedBySafeBrowsing(
94 safe_browsing::DownloadProtectionService::DownloadCheckResult result) { 97 safe_browsing::DownloadProtectionService::DownloadCheckResult result) {
95 using Result = safe_browsing::DownloadProtectionService::DownloadCheckResult; 98 using Result = safe_browsing::DownloadProtectionService::DownloadCheckResult;
96 switch (result) { 99 switch (result) {
97 // Only allow downloads that are marked as SAFE or UNKNOWN by SafeBrowsing. 100 // Only allow downloads that are marked as SAFE or UNKNOWN by SafeBrowsing.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 170
168 void FileSelectHelper::FileSelected(const base::FilePath& path, 171 void FileSelectHelper::FileSelected(const base::FilePath& path,
169 int index, void* params) { 172 int index, void* params) {
170 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); 173 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params);
171 } 174 }
172 175
173 void FileSelectHelper::FileSelectedWithExtraInfo( 176 void FileSelectHelper::FileSelectedWithExtraInfo(
174 const ui::SelectedFileInfo& file, 177 const ui::SelectedFileInfo& file,
175 int index, 178 int index,
176 void* params) { 179 void* params) {
177 if (IsValidProfile(profile_)) 180 if (IsValidProfile(profile_)) {
178 profile_->set_last_selected_directory(file.file_path.DirName()); 181 base::FilePath path = file.file_path;
182 if (dialog_mode_ != FileChooserParams::UploadFolder)
183 path = path.DirName();
184 profile_->set_last_selected_directory(path);
185 }
179 186
180 if (!render_frame_host_) { 187 if (!render_frame_host_) {
181 RunFileChooserEnd(); 188 RunFileChooserEnd();
182 return; 189 return;
183 } 190 }
184 191
185 const base::FilePath& path = file.local_path; 192 const base::FilePath& path = file.local_path;
186 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { 193 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) {
187 StartNewEnumeration(path, kFileSelectEnumerationId, 194 StartNewEnumeration(path, kFileSelectEnumerationId,
188 render_frame_host_->GetRenderViewHost()); 195 render_frame_host_->GetRenderViewHost());
(...skipping 18 matching lines...) Expand all
207 void* params) { 214 void* params) {
208 std::vector<ui::SelectedFileInfo> selected_files = 215 std::vector<ui::SelectedFileInfo> selected_files =
209 FilePathListToSelectedFileInfoList(files); 216 FilePathListToSelectedFileInfoList(files);
210 217
211 MultiFilesSelectedWithExtraInfo(selected_files, params); 218 MultiFilesSelectedWithExtraInfo(selected_files, params);
212 } 219 }
213 220
214 void FileSelectHelper::MultiFilesSelectedWithExtraInfo( 221 void FileSelectHelper::MultiFilesSelectedWithExtraInfo(
215 const std::vector<ui::SelectedFileInfo>& files, 222 const std::vector<ui::SelectedFileInfo>& files,
216 void* params) { 223 void* params) {
217 if (!files.empty() && IsValidProfile(profile_)) 224 if (!files.empty() && IsValidProfile(profile_)) {
218 profile_->set_last_selected_directory(files[0].file_path.DirName()); 225 base::FilePath path = files[0].file_path;
219 226 if (dialog_mode_ != FileChooserParams::UploadFolder)
227 path = path.DirName();
228 profile_->set_last_selected_directory(path);
229 }
220 #if defined(OS_MACOSX) 230 #if defined(OS_MACOSX)
221 content::BrowserThread::PostTask( 231 content::BrowserThread::PostTask(
222 content::BrowserThread::FILE_USER_BLOCKING, 232 content::BrowserThread::FILE_USER_BLOCKING,
223 FROM_HERE, 233 FROM_HERE,
224 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); 234 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files));
225 #else 235 #else
226 NotifyRenderFrameHostAndEnd(files); 236 NotifyRenderFrameHostAndEnd(files);
227 #endif // defined(OS_MACOSX) 237 #endif // defined(OS_MACOSX)
228 } 238 }
229 239
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 697
688 // static 698 // static
689 base::FilePath FileSelectHelper::GetSanitizedFileName( 699 base::FilePath FileSelectHelper::GetSanitizedFileName(
690 const base::FilePath& suggested_filename) { 700 const base::FilePath& suggested_filename) {
691 if (suggested_filename.empty()) 701 if (suggested_filename.empty())
692 return base::FilePath(); 702 return base::FilePath();
693 return net::GenerateFileName( 703 return net::GenerateFileName(
694 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), 704 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(),
695 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 705 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
696 } 706 }
OLDNEW
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/file_select_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698