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

Unified Diff: chrome/browser/file_select_helper.cc

Issue 1132163004: Remove NOTIFICATION_RENDER_VIEW_HOST_CHANGED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments #1 Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
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.
« no previous file with comments | « chrome/browser/file_select_helper.h ('k') | chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698