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/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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/task_scheduler/post_task.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/platform_util.h" | 22 #include "chrome/browser/platform_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/chrome_select_file_policy.h" | 27 #include "chrome/browser/ui/chrome_select_file_policy.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { | 193 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { |
193 StartNewEnumeration(path, kFileSelectEnumerationId, | 194 StartNewEnumeration(path, kFileSelectEnumerationId, |
194 render_frame_host_->GetRenderViewHost()); | 195 render_frame_host_->GetRenderViewHost()); |
195 return; | 196 return; |
196 } | 197 } |
197 | 198 |
198 std::vector<ui::SelectedFileInfo> files; | 199 std::vector<ui::SelectedFileInfo> files; |
199 files.push_back(file); | 200 files.push_back(file); |
200 | 201 |
201 #if defined(OS_MACOSX) | 202 #if defined(OS_MACOSX) |
202 content::BrowserThread::PostTask( | 203 base::PostTaskWithTraits( |
203 content::BrowserThread::FILE_USER_BLOCKING, | 204 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( |
204 FROM_HERE, | 205 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
205 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); | 206 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); |
206 #else | 207 #else |
207 NotifyRenderFrameHostAndEnd(files); | 208 NotifyRenderFrameHostAndEnd(files); |
208 #endif // defined(OS_MACOSX) | 209 #endif // defined(OS_MACOSX) |
209 } | 210 } |
210 | 211 |
211 void FileSelectHelper::MultiFilesSelected( | 212 void FileSelectHelper::MultiFilesSelected( |
212 const std::vector<base::FilePath>& files, | 213 const std::vector<base::FilePath>& files, |
213 void* params) { | 214 void* params) { |
214 std::vector<ui::SelectedFileInfo> selected_files = | 215 std::vector<ui::SelectedFileInfo> selected_files = |
215 FilePathListToSelectedFileInfoList(files); | 216 FilePathListToSelectedFileInfoList(files); |
216 | 217 |
217 MultiFilesSelectedWithExtraInfo(selected_files, params); | 218 MultiFilesSelectedWithExtraInfo(selected_files, params); |
218 } | 219 } |
219 | 220 |
220 void FileSelectHelper::MultiFilesSelectedWithExtraInfo( | 221 void FileSelectHelper::MultiFilesSelectedWithExtraInfo( |
221 const std::vector<ui::SelectedFileInfo>& files, | 222 const std::vector<ui::SelectedFileInfo>& files, |
222 void* params) { | 223 void* params) { |
223 if (!files.empty() && IsValidProfile(profile_)) { | 224 if (!files.empty() && IsValidProfile(profile_)) { |
224 base::FilePath path = files[0].file_path; | 225 base::FilePath path = files[0].file_path; |
225 if (dialog_mode_ != FileChooserParams::UploadFolder) | 226 if (dialog_mode_ != FileChooserParams::UploadFolder) |
226 path = path.DirName(); | 227 path = path.DirName(); |
227 profile_->set_last_selected_directory(path); | 228 profile_->set_last_selected_directory(path); |
228 } | 229 } |
229 #if defined(OS_MACOSX) | 230 #if defined(OS_MACOSX) |
230 content::BrowserThread::PostTask( | 231 base::PostTaskWithTraits( |
231 content::BrowserThread::FILE_USER_BLOCKING, | 232 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior( |
232 FROM_HERE, | 233 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
233 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); | 234 base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); |
234 #else | 235 #else |
235 NotifyRenderFrameHostAndEnd(files); | 236 NotifyRenderFrameHostAndEnd(files); |
236 #endif // defined(OS_MACOSX) | 237 #endif // defined(OS_MACOSX) |
237 } | 238 } |
238 | 239 |
239 void FileSelectHelper::FileSelectionCanceled(void* params) { | 240 void FileSelectHelper::FileSelectionCanceled(void* params) { |
240 NotifyRenderFrameHostAndEnd(std::vector<ui::SelectedFileInfo>()); | 241 NotifyRenderFrameHostAndEnd(std::vector<ui::SelectedFileInfo>()); |
241 } | 242 } |
242 | 243 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 | 693 |
693 // static | 694 // static |
694 base::FilePath FileSelectHelper::GetSanitizedFileName( | 695 base::FilePath FileSelectHelper::GetSanitizedFileName( |
695 const base::FilePath& suggested_filename) { | 696 const base::FilePath& suggested_filename) { |
696 if (suggested_filename.empty()) | 697 if (suggested_filename.empty()) |
697 return base::FilePath(); | 698 return base::FilePath(); |
698 return net::GenerateFileName( | 699 return net::GenerateFileName( |
699 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), | 700 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), |
700 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 701 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
701 } | 702 } |
OLD | NEW |