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

Side by Side Diff: chrome/browser/file_select_helper.h

Issue 1616563002: Ensure that FileSelectHelper is destroyed on the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment describing why FileSelectHelper needs to be destroyed on the UI thread. Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_ 5 #ifndef CHROME_BROWSER_FILE_SELECT_HELPER_H_
6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_ 6 #define CHROME_BROWSER_FILE_SELECT_HELPER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/common/file_chooser_params.h" 20 #include "content/public/common/file_chooser_params.h"
20 #include "net/base/directory_lister.h" 21 #include "net/base/directory_lister.h"
21 #include "ui/shell_dialogs/select_file_dialog.h" 22 #include "ui/shell_dialogs/select_file_dialog.h"
22 23
23 #if defined(FULL_SAFE_BROWSING) 24 #if defined(FULL_SAFE_BROWSING)
24 #include "chrome/browser/safe_browsing/unverified_download_policy.h" 25 #include "chrome/browser/safe_browsing/unverified_download_policy.h"
25 #endif 26 #endif
26 27
27 class Profile; 28 class Profile;
28 29
29 namespace content { 30 namespace content {
30 struct FileChooserFileInfo; 31 struct FileChooserFileInfo;
31 class RenderViewHost; 32 class RenderViewHost;
32 class WebContents; 33 class WebContents;
33 } 34 }
34 35
35 namespace ui { 36 namespace ui {
36 struct SelectedFileInfo; 37 struct SelectedFileInfo;
37 } 38 }
38 39
39 // This class handles file-selection requests coming from WebUI elements 40 // This class handles file-selection requests coming from WebUI elements
40 // (via the extensions::ExtensionHost class). It implements both the 41 // (via the extensions::ExtensionHost class). It implements both the
41 // initialisation and listener functions for file-selection dialogs. 42 // initialisation and listener functions for file-selection dialogs.
42 class FileSelectHelper : public base::RefCountedThreadSafe<FileSelectHelper>, 43 //
44 // Since FileSelectHelper has-a NotificationRegistrar, it needs to live on and
45 // be destroyed on the UI thread. References to FileSelectHelper may be passed
46 // on to other threads.
47 class FileSelectHelper : public base::RefCountedThreadSafe<
48 FileSelectHelper,
49 content::BrowserThread::DeleteOnUIThread>,
43 public ui::SelectFileDialog::Listener, 50 public ui::SelectFileDialog::Listener,
44 public content::WebContentsObserver, 51 public content::WebContentsObserver,
45 public content::NotificationObserver { 52 public content::NotificationObserver {
46 public: 53 public:
47
48 // Show the file chooser dialog. 54 // Show the file chooser dialog.
49 static void RunFileChooser(content::WebContents* tab, 55 static void RunFileChooser(content::WebContents* tab,
50 const content::FileChooserParams& params); 56 const content::FileChooserParams& params);
51 57
52 // Enumerates all the files in directory. 58 // Enumerates all the files in directory.
53 static void EnumerateDirectory(content::WebContents* tab, 59 static void EnumerateDirectory(content::WebContents* tab,
54 int request_id, 60 int request_id,
55 const base::FilePath& path); 61 const base::FilePath& path);
56 62
57 private: 63 private:
58 friend class base::RefCountedThreadSafe<FileSelectHelper>; 64 friend class base::RefCountedThreadSafe<FileSelectHelper>;
65 friend class base::DeleteHelper<FileSelectHelper>;
66 friend struct content::BrowserThread::DeleteOnThread<
67 content::BrowserThread::UI>;
68
59 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid); 69 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, IsAcceptTypeValid);
60 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, ZipPackage); 70 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, ZipPackage);
61 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, GetSanitizedFileName); 71 FRIEND_TEST_ALL_PREFIXES(FileSelectHelperTest, GetSanitizedFileName);
62 explicit FileSelectHelper(Profile* profile); 72 explicit FileSelectHelper(Profile* profile);
63 ~FileSelectHelper() override; 73 ~FileSelectHelper() override;
64 74
65 // Utility class which can listen for directory lister events and relay 75 // Utility class which can listen for directory lister events and relay
66 // them to the main object with the correct tracking id. 76 // them to the main object with the correct tracking id.
67 class DirectoryListerDispatchDelegate 77 class DirectoryListerDispatchDelegate
68 : public net::DirectoryLister::DirectoryListerDelegate { 78 : public net::DirectoryLister::DirectoryListerDelegate {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 content::NotificationRegistrar notification_registrar_; 246 content::NotificationRegistrar notification_registrar_;
237 247
238 // Temporary files only used on OSX. This class is responsible for deleting 248 // Temporary files only used on OSX. This class is responsible for deleting
239 // these files when they are no longer needed. 249 // these files when they are no longer needed.
240 std::vector<base::FilePath> temporary_files_; 250 std::vector<base::FilePath> temporary_files_;
241 251
242 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); 252 DISALLOW_COPY_AND_ASSIGN(FileSelectHelper);
243 }; 253 };
244 254
245 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ 255 #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698