| 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. If the download has a forced path, then |
| 59 // initial_virtual_path must be empty or be the forced path. |
| 55 // |download_prefs| is required and must outlive |download|. It is used for | 60 // |download_prefs| is required and must outlive |download|. It is used for |
| 56 // determining the user's preferences regarding the default downloads | 61 // determining the user's preferences regarding the default downloads |
| 57 // directory, prompting and auto-open behavior. | 62 // directory, prompting and auto-open behavior. |
| 58 // |last_selected_directory| is the most recent directory that was chosen by | 63 // |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 | 64 // 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 | 65 // used as the directory for the download instead of the user's default |
| 61 // downloads directory. | 66 // downloads directory. |
| 62 // |delegate| is required and must live until |callback| is invoked. | 67 // |delegate| is required and must live until |callback| is invoked. |
| 63 // |callback| will be scheduled asynchronously on the UI thread after download | 68 // |callback| will be scheduled asynchronously on the UI thread after download |
| 64 // determination is complete or after |download| is destroyed. | 69 // determination is complete or after |download| is destroyed. |
| 65 // | 70 // |
| 66 // Start() should be called on the UI thread. | 71 // Start() should be called on the UI thread. |
| 67 static void Start(content::DownloadItem* download, | 72 static void Start(content::DownloadItem* download, |
| 73 const base::FilePath& initial_virtual_path, |
| 68 DownloadPrefs* download_prefs, | 74 DownloadPrefs* download_prefs, |
| 69 const base::FilePath& last_selected_directory, | 75 const base::FilePath& last_selected_directory, |
| 70 DownloadTargetDeterminerDelegate* delegate, | 76 DownloadTargetDeterminerDelegate* delegate, |
| 71 const content::DownloadTargetCallback& callback); | 77 const content::DownloadTargetCallback& callback); |
| 72 | 78 |
| 73 // Returns a .crdownload intermediate path for the |suggested_path|. | 79 // Returns a .crdownload intermediate path for the |suggested_path|. |
| 74 static base::FilePath GetCrDownloadPath(const base::FilePath& suggested_path); | 80 static base::FilePath GetCrDownloadPath(const base::FilePath& suggested_path); |
| 75 | 81 |
| 76 private: | 82 private: |
| 77 // The main workflow is controlled via a set of state transitions. Each state | 83 // 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. | 118 // referrer URL for the download prior to today. |
| 113 enum PriorVisitsToReferrer { | 119 enum PriorVisitsToReferrer { |
| 114 NO_VISITS_TO_REFERRER, | 120 NO_VISITS_TO_REFERRER, |
| 115 VISITED_REFERRER, | 121 VISITED_REFERRER, |
| 116 }; | 122 }; |
| 117 | 123 |
| 118 // Construct a DownloadTargetDeterminer object. Constraints on the arguments | 124 // Construct a DownloadTargetDeterminer object. Constraints on the arguments |
| 119 // are as per Start() above. | 125 // are as per Start() above. |
| 120 DownloadTargetDeterminer( | 126 DownloadTargetDeterminer( |
| 121 content::DownloadItem* download, | 127 content::DownloadItem* download, |
| 128 const base::FilePath& initial_virtual_path, |
| 122 DownloadPrefs* download_prefs, | 129 DownloadPrefs* download_prefs, |
| 123 const base::FilePath& last_selected_directory, | 130 const base::FilePath& last_selected_directory, |
| 124 DownloadTargetDeterminerDelegate* delegate, | 131 DownloadTargetDeterminerDelegate* delegate, |
| 125 const content::DownloadTargetCallback& callback); | 132 const content::DownloadTargetCallback& callback); |
| 126 | 133 |
| 127 virtual ~DownloadTargetDeterminer(); | 134 virtual ~DownloadTargetDeterminer(); |
| 128 | 135 |
| 129 // Invoke each successive handler until a handler returns QUIT_DOLOOP or | 136 // 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| | 137 // COMPLETE. Note that as a result, this object might be deleted. So |this| |
| 131 // should not be accessed after calling DoLoop(). | 138 // 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 === | 220 // === End of main workflow === |
| 214 | 221 |
| 215 // Utilities: | 222 // Utilities: |
| 216 | 223 |
| 217 void ScheduleCallbackAndDeleteSelf(); | 224 void ScheduleCallbackAndDeleteSelf(); |
| 218 | 225 |
| 219 void CancelOnFailureAndDeleteSelf(); | 226 void CancelOnFailureAndDeleteSelf(); |
| 220 | 227 |
| 221 Profile* GetProfile(); | 228 Profile* GetProfile(); |
| 222 | 229 |
| 223 bool ShouldPromptForDownload(const base::FilePath& filename); | 230 bool ShouldPromptForDownload(const base::FilePath& filename) const; |
| 231 |
| 232 // Returns true if the user has been prompted for this download at least once. |
| 233 // Can return true for resumed downloads that have prompted the user |
| 234 // previously even if no prompting happened during the current run of |
| 235 // DownloadTargetDeterminer. |
| 236 bool HasPromptedForPath() const; |
| 224 | 237 |
| 225 // Returns true if this download should show the "dangerous file" warning. | 238 // 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 | 239 // 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 | 240 // user action initiated the download, and whether the user has explicitly |
| 228 // marked the file type as "auto open". Protected virtual for testing. | 241 // marked the file type as "auto open". Protected virtual for testing. |
| 229 bool IsDangerousFile(PriorVisitsToReferrer visits); | 242 bool IsDangerousFile(PriorVisitsToReferrer visits); |
| 230 | 243 |
| 231 // content::DownloadItem::Observer | 244 // content::DownloadItem::Observer |
| 232 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; | 245 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; |
| 233 | 246 |
| 234 // state | 247 // state |
| 235 State next_state_; | 248 State next_state_; |
| 236 bool should_prompt_; | 249 bool should_prompt_; |
| 237 bool create_directory_; | 250 bool create_directory_; |
| 238 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; | 251 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; |
| 239 content::DownloadDangerType danger_type_; | 252 content::DownloadDangerType danger_type_; |
| 240 base::FilePath virtual_path_; | 253 base::FilePath virtual_path_; |
| 241 base::FilePath local_path_; | 254 base::FilePath local_path_; |
| 242 base::FilePath intermediate_path_; | 255 base::FilePath intermediate_path_; |
| 243 | 256 |
| 244 content::DownloadItem* download_; | 257 content::DownloadItem* download_; |
| 258 const bool is_resumption_; |
| 245 DownloadPrefs* download_prefs_; | 259 DownloadPrefs* download_prefs_; |
| 246 DownloadTargetDeterminerDelegate* delegate_; | 260 DownloadTargetDeterminerDelegate* delegate_; |
| 247 base::FilePath last_selected_directory_; | 261 const base::FilePath last_selected_directory_; |
| 248 content::DownloadTargetCallback completion_callback_; | 262 content::DownloadTargetCallback completion_callback_; |
| 249 CancelableRequestConsumer history_consumer_; | 263 CancelableRequestConsumer history_consumer_; |
| 250 | 264 |
| 251 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; | 265 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; |
| 252 | 266 |
| 253 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); | 267 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); |
| 254 }; | 268 }; |
| 255 | 269 |
| 256 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ | 270 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ |
| OLD | NEW |