Index: chrome/browser/file_select_helper.cc |
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc |
index fa0004ccb2edabad900f27e883d9b98fbe83c6a6..6cf478d7c3212ed9715e969310f3c076fa489ac7 100644 |
--- a/chrome/browser/file_select_helper.cc |
+++ b/chrome/browser/file_select_helper.cc |
@@ -61,6 +61,11 @@ std::vector<ui::SelectedFileInfo> FilePathListToSelectedFileInfoList( |
return selected_files; |
} |
+void DeleteFiles(const std::vector<base::FilePath>& paths) { |
+ for (base::FilePath file_path : paths) |
Avi (use Gerrit)
2014/10/08 00:17:32
auto& perhaps?
erikchen
2014/10/08 20:14:43
Done.
|
+ base::DeleteFile(file_path, true); |
+} |
+ |
} // namespace |
struct FileSelectHelper::ActiveDirectoryEnumeration { |
@@ -117,11 +122,13 @@ void FileSelectHelper::FileSelectedWithExtraInfo( |
const ui::SelectedFileInfo& file, |
int index, |
void* params) { |
- if (!render_view_host_) |
- return; |
- |
profile_->set_last_selected_directory(file.file_path.DirName()); |
+ if (!render_view_host_) { |
+ RunFileChooserEnd(); |
+ return; |
+ } |
+ |
const base::FilePath& path = file.local_path; |
if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { |
StartNewEnumeration(path, kFileSelectEnumerationId, render_view_host_); |
@@ -130,10 +137,16 @@ void FileSelectHelper::FileSelectedWithExtraInfo( |
std::vector<ui::SelectedFileInfo> files; |
files.push_back(file); |
- NotifyRenderViewHost(render_view_host_, files, dialog_mode_); |
- // No members should be accessed from here on. |
- RunFileChooserEnd(); |
+#if defined(OS_MACOSX) && !defined(OS_IOS) |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE_USER_BLOCKING, |
+ FROM_HERE, |
+ base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); |
+ return; |
+#endif // defined(OS_MACOSX) && !defined(OS_IOS) |
+ |
+ NotifyRenderViewHostAndEnd(files); |
} |
void FileSelectHelper::MultiFilesSelected( |
@@ -150,27 +163,20 @@ void FileSelectHelper::MultiFilesSelectedWithExtraInfo( |
void* params) { |
if (!files.empty()) |
profile_->set_last_selected_directory(files[0].file_path.DirName()); |
- if (!render_view_host_) |
- return; |
- NotifyRenderViewHost(render_view_host_, files, dialog_mode_); |
+#if defined(OS_MACOSX) && !defined(OS_IOS) |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE_USER_BLOCKING, |
+ FROM_HERE, |
+ base::Bind(&FileSelectHelper::ProcessSelectedFilesMac, this, files)); |
+ return; |
+#endif // defined(OS_MACOSX) && !defined(OS_IOS) |
- // No members should be accessed from here on. |
- RunFileChooserEnd(); |
+ NotifyRenderViewHostAndEnd(files); |
Avi (use Gerrit)
2014/10/08 00:17:32
Might as well put this into an #else.
erikchen
2014/10/08 20:14:43
Done.
|
} |
void FileSelectHelper::FileSelectionCanceled(void* params) { |
- if (!render_view_host_) |
- return; |
- |
- // If the user cancels choosing a file to upload we pass back an |
- // empty vector. |
- NotifyRenderViewHost( |
- render_view_host_, std::vector<ui::SelectedFileInfo>(), |
- dialog_mode_); |
- |
- // No members should be accessed from here on. |
- RunFileChooserEnd(); |
+ NotifyRenderViewHostAndEnd(std::vector<ui::SelectedFileInfo>()); |
} |
void FileSelectHelper::StartNewEnumeration(const base::FilePath& path, |
@@ -228,6 +234,22 @@ void FileSelectHelper::OnListDone(int id, int error) { |
EnumerateDirectoryEnd(); |
} |
+void FileSelectHelper::NotifyRenderViewHostAndEnd( |
+ const std::vector<ui::SelectedFileInfo>& files) { |
+ if (render_view_host_) |
+ NotifyRenderViewHost(render_view_host_, files, dialog_mode_); |
+ |
+ // No members should be accessed from here on. |
+ RunFileChooserEnd(); |
+} |
+ |
+void FileSelectHelper::DeleteTemporaryFiles() { |
+ BrowserThread::PostTask(BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind(&DeleteFiles, temporary_files_)); |
+ temporary_files_.clear(); |
+} |
+ |
scoped_ptr<ui::SelectFileDialog::FileTypeInfo> |
FileSelectHelper::GetFileTypesFromAcceptType( |
const std::vector<base::string16>& accept_types) { |
@@ -424,6 +446,12 @@ void FileSelectHelper::RunFileChooserOnUIThread( |
// chooser dialog. Perform any cleanup and release the reference we added |
// in RunFileChooser(). |
void FileSelectHelper::RunFileChooserEnd() { |
+ // If there are temporary files, then this instance needs to stick around |
+ // until web_contents_ is destroyed, so that this instance can delete the |
+ // temporary files. |
+ if (!temporary_files_.empty()) |
+ return; |
+ |
render_view_host_ = NULL; |
web_contents_ = NULL; |
Release(); |
@@ -463,6 +491,15 @@ void FileSelectHelper::Observe(int type, |
case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
DCHECK(content::Source<WebContents>(source).ptr() == web_contents_); |
web_contents_ = NULL; |
+ |
+ if (!temporary_files_.empty()) { |
+ DeleteTemporaryFiles(); |
+ |
+ // Now that the temporary files have been scheduled for deletion, there |
+ // is no longer any reason to keep this instance around. |
+ Release(); |
+ } |
Avi (use Gerrit)
2014/10/08 00:17:32
So if there was zipping that happened, those tempo
erikchen
2014/10/08 20:14:43
Sure. In the updated CL, the notification NOTIFICA
|
+ |
break; |
} |