Commit bbf7f34c authored by asanka's avatar asanka Committed by Commit bot

Ensure that FileSelectHelper is destroyed on the UI thread.

R=sky
BUG=563932

Review URL: https://codereview.chromium.org/1616563002

Cr-Commit-Position: refs/heads/master@{#370787}
parent 04350657
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -39,12 +40,17 @@ struct SelectedFileInfo; ...@@ -39,12 +40,17 @@ struct SelectedFileInfo;
// This class handles file-selection requests coming from WebUI elements // This class handles file-selection requests coming from WebUI elements
// (via the extensions::ExtensionHost class). It implements both the // (via the extensions::ExtensionHost class). It implements both the
// initialisation and listener functions for file-selection dialogs. // initialisation and listener functions for file-selection dialogs.
class FileSelectHelper : public base::RefCountedThreadSafe<FileSelectHelper>, //
// Since FileSelectHelper has-a NotificationRegistrar, it needs to live on and
// be destroyed on the UI thread. References to FileSelectHelper may be passed
// on to other threads.
class FileSelectHelper : public base::RefCountedThreadSafe<
FileSelectHelper,
content::BrowserThread::DeleteOnUIThread>,
public ui::SelectFileDialog::Listener, public ui::SelectFileDialog::Listener,
public content::WebContentsObserver, public content::WebContentsObserver,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
// Show the file chooser dialog. // Show the file chooser dialog.
static void RunFileChooser(content::WebContents* tab, static void RunFileChooser(content::WebContents* tab,
const content::FileChooserParams& params); const content::FileChooserParams& params);
...@@ -56,6 +62,10 @@ class FileSelectHelper : public base::RefCountedThreadSafe<FileSelectHelper>, ...@@ -56,6 +62,10 @@ class FileSelectHelper : public base::RefCountedThreadSafe<FileSelectHelper>,
private: private:
friend class base::RefCountedThreadSafe<FileSelectHelper>; friend class base::RefCountedThreadSafe<FileSelectHelper>;
friend class base::DeleteHelper<FileSelectHelper>;
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid); FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid);
FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, ZipPackage); FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, ZipPackage);
FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, GetSanitizedFileName); FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, GetSanitizedFileName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment