OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 // responsible for providing external dependencies and prompting the user if | 45 // responsible for providing external dependencies and prompting the user if |
46 // necessary. | 46 // necessary. |
47 // | 47 // |
48 // The only public entrypoint is the static Start() method which creates an | 48 // The only public entrypoint is the static Start() method which creates an |
49 // instance of DownloadTargetDeterminer. | 49 // instance of DownloadTargetDeterminer. |
50 class DownloadTargetDeterminer | 50 class DownloadTargetDeterminer |
51 : public content::DownloadItem::Observer { | 51 : public content::DownloadItem::Observer { |
52 public: | 52 public: |
53 // Start the process of determing the target of |download|. | 53 // Start the process of determing the target of |download|. |
54 // | 54 // |
55 // |initial_virtual_path| if non-empty, defines the initial virtual path for | |
56 // the target determination process. If one isn't specified, one will be | |
57 // generated based on the response data specified in |download| and the | |
58 // users' downloads directory. | |
59 // Note: |initial_virtual_path| is only used if download has prompted the | |
60 // user before and doesn't have a forced path. | |
55 // |download_prefs| is required and must outlive |download|. It is used for | 61 // |download_prefs| is required and must outlive |download|. It is used for |
56 // determining the user's preferences regarding the default downloads | 62 // determining the user's preferences regarding the default downloads |
57 // directory, prompting and auto-open behavior. | 63 // directory, prompting and auto-open behavior. |
58 // |last_selected_directory| is the most recent directory that was chosen by | 64 // |last_selected_directory| is the most recent directory that was chosen by |
59 // the user. If the user needs to be prompted, then this directory will be | 65 // the user. If the user needs to be prompted, then this directory will be |
60 // used as the directory for the download instead of the user's default | 66 // used as the directory for the download instead of the user's default |
61 // downloads directory. | 67 // downloads directory. |
62 // |delegate| is required and must live until |callback| is invoked. | 68 // |delegate| is required and must live until |callback| is invoked. |
63 // |callback| will be scheduled asynchronously on the UI thread after download | 69 // |callback| will be scheduled asynchronously on the UI thread after download |
64 // determination is complete or after |download| is destroyed. | 70 // determination is complete or after |download| is destroyed. |
65 // | 71 // |
66 // Start() should be called on the UI thread. | 72 // Start() should be called on the UI thread. |
67 static void Start(content::DownloadItem* download, | 73 static void Start(content::DownloadItem* download, |
74 const base::FilePath& initial_virtual_path, | |
68 DownloadPrefs* download_prefs, | 75 DownloadPrefs* download_prefs, |
69 const base::FilePath& last_selected_directory, | 76 const base::FilePath& last_selected_directory, |
70 DownloadTargetDeterminerDelegate* delegate, | 77 DownloadTargetDeterminerDelegate* delegate, |
71 const content::DownloadTargetCallback& callback); | 78 const content::DownloadTargetCallback& callback); |
72 | 79 |
73 // Returns a .crdownload intermediate path for the |suggested_path|. | 80 // Returns a .crdownload intermediate path for the |suggested_path|. |
74 static base::FilePath GetCrDownloadPath(const base::FilePath& suggested_path); | 81 static base::FilePath GetCrDownloadPath(const base::FilePath& suggested_path); |
75 | 82 |
76 private: | 83 private: |
77 // The main workflow is controlled via a set of state transitions. Each state | 84 // The main workflow is controlled via a set of state transitions. Each state |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // referrer URL for the download prior to today. | 119 // referrer URL for the download prior to today. |
113 enum PriorVisitsToReferrer { | 120 enum PriorVisitsToReferrer { |
114 NO_VISITS_TO_REFERRER, | 121 NO_VISITS_TO_REFERRER, |
115 VISITED_REFERRER, | 122 VISITED_REFERRER, |
116 }; | 123 }; |
117 | 124 |
118 // Construct a DownloadTargetDeterminer object. Constraints on the arguments | 125 // Construct a DownloadTargetDeterminer object. Constraints on the arguments |
119 // are as per Start() above. | 126 // are as per Start() above. |
120 DownloadTargetDeterminer( | 127 DownloadTargetDeterminer( |
121 content::DownloadItem* download, | 128 content::DownloadItem* download, |
129 const base::FilePath& initial_virtual_path, | |
122 DownloadPrefs* download_prefs, | 130 DownloadPrefs* download_prefs, |
123 const base::FilePath& last_selected_directory, | 131 const base::FilePath& last_selected_directory, |
124 DownloadTargetDeterminerDelegate* delegate, | 132 DownloadTargetDeterminerDelegate* delegate, |
125 const content::DownloadTargetCallback& callback); | 133 const content::DownloadTargetCallback& callback); |
126 | 134 |
127 virtual ~DownloadTargetDeterminer(); | 135 virtual ~DownloadTargetDeterminer(); |
128 | 136 |
129 // Invoke each successive handler until a handler returns QUIT_DOLOOP or | 137 // Invoke each successive handler until a handler returns QUIT_DOLOOP or |
130 // COMPLETE. Note that as a result, this object might be deleted. So |this| | 138 // COMPLETE. Note that as a result, this object might be deleted. So |this| |
131 // should not be accessed after calling DoLoop(). | 139 // should not be accessed after calling DoLoop(). |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 // === End of main workflow === | 221 // === End of main workflow === |
214 | 222 |
215 // Utilities: | 223 // Utilities: |
216 | 224 |
217 void ScheduleCallbackAndDeleteSelf(); | 225 void ScheduleCallbackAndDeleteSelf(); |
218 | 226 |
219 void CancelOnFailureAndDeleteSelf(); | 227 void CancelOnFailureAndDeleteSelf(); |
220 | 228 |
221 Profile* GetProfile(); | 229 Profile* GetProfile(); |
222 | 230 |
223 bool ShouldPromptForDownload(const base::FilePath& filename); | 231 bool ShouldPromptForDownload(const base::FilePath& filename) const; |
232 | |
233 // Returns true if the user has been prompted for this download at least once. | |
234 // Can return true for resumed downloads that have prompted the user | |
235 // previously even if no prompting happened during the current run of | |
236 // DownloadTargetDeterminer. | |
Randy Smith (Not in Mondays)
2013/05/24 01:53:55
If I read the code right, this will return true af
asanka
2013/05/29 22:30:11
Done.
| |
237 bool HasPromptedForPath() const; | |
224 | 238 |
225 // Returns true if this download should show the "dangerous file" warning. | 239 // Returns true if this download should show the "dangerous file" warning. |
226 // Various factors are considered, such as the type of the file, whether a | 240 // Various factors are considered, such as the type of the file, whether a |
227 // user action initiated the download, and whether the user has explicitly | 241 // user action initiated the download, and whether the user has explicitly |
228 // marked the file type as "auto open". Protected virtual for testing. | 242 // marked the file type as "auto open". Protected virtual for testing. |
229 bool IsDangerousFile(PriorVisitsToReferrer visits); | 243 bool IsDangerousFile(PriorVisitsToReferrer visits); |
230 | 244 |
231 // content::DownloadItem::Observer | 245 // content::DownloadItem::Observer |
232 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | 246 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; |
233 | 247 |
234 // state | 248 // state |
235 State next_state_; | 249 State next_state_; |
236 bool should_prompt_; | 250 bool should_prompt_; |
251 bool should_notify_extensions_; | |
237 bool create_directory_; | 252 bool create_directory_; |
238 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; | 253 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; |
239 content::DownloadDangerType danger_type_; | 254 content::DownloadDangerType danger_type_; |
240 base::FilePath virtual_path_; | 255 base::FilePath virtual_path_; |
241 base::FilePath local_path_; | 256 base::FilePath local_path_; |
242 base::FilePath intermediate_path_; | 257 base::FilePath intermediate_path_; |
243 | 258 |
244 content::DownloadItem* download_; | 259 content::DownloadItem* download_; |
260 const bool is_resumption_; | |
245 DownloadPrefs* download_prefs_; | 261 DownloadPrefs* download_prefs_; |
246 DownloadTargetDeterminerDelegate* delegate_; | 262 DownloadTargetDeterminerDelegate* delegate_; |
247 base::FilePath last_selected_directory_; | 263 const base::FilePath last_selected_directory_; |
248 content::DownloadTargetCallback completion_callback_; | 264 content::DownloadTargetCallback completion_callback_; |
249 CancelableRequestConsumer history_consumer_; | 265 CancelableRequestConsumer history_consumer_; |
250 | 266 |
251 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; | 267 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; |
252 | 268 |
253 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); | 269 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); |
254 }; | 270 }; |
255 | 271 |
256 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ | 272 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ |
OLD | NEW |