Index: chrome/browser/file_select_helper.cc |
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc |
index 22a8fb4a866605ad216f8e3ba34418afeaa4f3cf..c5c617d2f30e6d6a9d7d4b6cf1b806fdc55b2238 100644 |
--- a/chrome/browser/file_select_helper.cc |
+++ b/chrome/browser/file_select_helper.cc |
@@ -85,7 +85,8 @@ struct FileSelectHelper::ActiveDirectoryEnumeration { |
}; |
FileSelectHelper::FileSelectHelper(Profile* profile) |
- : profile_(profile), |
+ : content::WebContentsObserver(), |
Lei Zhang
2015/05/11 19:52:58
Is this necessary?
lazyboy
2015/05/11 20:41:55
It's not, I've removed invoking default constructo
|
+ profile_(profile), |
render_view_host_(NULL), |
web_contents_(NULL), |
select_file_dialog_(), |
@@ -292,6 +293,16 @@ void FileSelectHelper::DeleteTemporaryFiles() { |
temporary_files_.clear(); |
} |
+void FileSelectHelper::CleanUpOnRenderViewHostChange() { |
+ 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(); |
+ } |
+} |
+ |
scoped_ptr<ui::SelectFileDialog::FileTypeInfo> |
FileSelectHelper::GetFileTypesFromAcceptType( |
const std::vector<base::string16>& accept_types) { |
@@ -390,16 +401,11 @@ void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host, |
render_view_host_ = render_view_host; |
web_contents_ = web_contents; |
notification_registrar_.RemoveAll(); |
- notification_registrar_.Add(this, |
- content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
- content::Source<WebContents>(web_contents_)); |
+ content::WebContentsObserver::Observe(web_contents_); |
notification_registrar_.Add( |
this, |
content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
content::Source<RenderWidgetHost>(render_view_host_)); |
- notification_registrar_.Add( |
- this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
- content::Source<WebContents>(web_contents_)); |
BrowserThread::PostTask( |
BrowserThread::FILE, FROM_HERE, |
@@ -534,29 +540,21 @@ void FileSelectHelper::Observe(int type, |
render_view_host_ = NULL; |
break; |
} |
- |
- case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
- DCHECK(content::Source<WebContents>(source).ptr() == web_contents_); |
- web_contents_ = NULL; |
- } |
- |
- // Intentional fall through. |
- case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: |
- 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(); |
- } |
- |
- break; |
- |
default: |
NOTREACHED(); |
} |
} |
+void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host, |
+ RenderViewHost* new_host) { |
+ CleanUpOnRenderViewHostChange(); |
+} |
+ |
+void FileSelectHelper::WebContentsDestroyed() { |
+ web_contents_ = nullptr; |
+ CleanUpOnRenderViewHostChange(); |
+} |
+ |
// static |
bool FileSelectHelper::IsAcceptTypeValid(const std::string& accept_type) { |
// TODO(raymes): This only does some basic checks, extend to test more cases. |