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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // |download_prefs| is required and must outlive |download|. It is used for | 55 // |download_prefs| is required and must outlive |download|. It is used for |
56 // determining the user's preferences regarding the default downloads | 56 // determining the user's preferences regarding the default downloads |
57 // directory, prompting and auto-open behavior. | 57 // directory, prompting and auto-open behavior. |
58 // |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 | |
60 // used as the directory for the download instead of the user's default | |
61 // downloads directory. | |
62 // |delegate| is required and must live until |callback| is invoked. | 58 // |delegate| is required and must live until |callback| is invoked. |
63 // |callback| will be scheduled asynchronously on the UI thread after download | 59 // |callback| will be scheduled asynchronously on the UI thread after download |
64 // determination is complete or after |download| is destroyed. | 60 // determination is complete or after |download| is destroyed. |
65 // | 61 // |
66 // Start() should be called on the UI thread. | 62 // Start() should be called on the UI thread. |
67 static void Start(content::DownloadItem* download, | 63 static void Start(content::DownloadItem* download, |
68 DownloadPrefs* download_prefs, | 64 DownloadPrefs* download_prefs, |
69 const base::FilePath& last_selected_directory, | |
70 DownloadTargetDeterminerDelegate* delegate, | 65 DownloadTargetDeterminerDelegate* delegate, |
71 const content::DownloadTargetCallback& callback); | 66 const content::DownloadTargetCallback& callback); |
72 | 67 |
73 private: | 68 private: |
74 // The main workflow is controlled via a set of state transitions. Each state | 69 // The main workflow is controlled via a set of state transitions. Each state |
75 // has an associated handler. The handler for STATE_FOO is DoFoo. Each handler | 70 // has an associated handler. The handler for STATE_FOO is DoFoo. Each handler |
76 // performs work, determines the next state to transition to and returns a | 71 // performs work, determines the next state to transition to and returns a |
77 // Result indicating how the workflow should proceed. The loop ends when a | 72 // Result indicating how the workflow should proceed. The loop ends when a |
78 // handler returns COMPLETE. | 73 // handler returns COMPLETE. |
79 enum State { | 74 enum State { |
(...skipping 30 matching lines...) Expand all Loading... |
110 enum PriorVisitsToReferrer { | 105 enum PriorVisitsToReferrer { |
111 NO_VISITS_TO_REFERRER, | 106 NO_VISITS_TO_REFERRER, |
112 VISITED_REFERRER, | 107 VISITED_REFERRER, |
113 }; | 108 }; |
114 | 109 |
115 // Construct a DownloadTargetDeterminer object. Constraints on the arguments | 110 // Construct a DownloadTargetDeterminer object. Constraints on the arguments |
116 // are as per Start() above. | 111 // are as per Start() above. |
117 DownloadTargetDeterminer( | 112 DownloadTargetDeterminer( |
118 content::DownloadItem* download, | 113 content::DownloadItem* download, |
119 DownloadPrefs* download_prefs, | 114 DownloadPrefs* download_prefs, |
120 const base::FilePath& last_selected_directory, | |
121 DownloadTargetDeterminerDelegate* delegate, | 115 DownloadTargetDeterminerDelegate* delegate, |
122 const content::DownloadTargetCallback& callback); | 116 const content::DownloadTargetCallback& callback); |
123 | 117 |
124 virtual ~DownloadTargetDeterminer(); | 118 virtual ~DownloadTargetDeterminer(); |
125 | 119 |
126 // Invoke each successive handler until a handler returns QUIT_DOLOOP or | 120 // Invoke each successive handler until a handler returns QUIT_DOLOOP or |
127 // COMPLETE. Note that as a result, this object might be deleted. So |this| | 121 // COMPLETE. Note that as a result, this object might be deleted. So |this| |
128 // should not be accessed after calling DoLoop(). | 122 // should not be accessed after calling DoLoop(). |
129 void DoLoop(); | 123 void DoLoop(); |
130 | 124 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 bool create_directory_; | 228 bool create_directory_; |
235 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; | 229 DownloadPathReservationTracker::FilenameConflictAction conflict_action_; |
236 content::DownloadDangerType danger_type_; | 230 content::DownloadDangerType danger_type_; |
237 base::FilePath virtual_path_; | 231 base::FilePath virtual_path_; |
238 base::FilePath local_path_; | 232 base::FilePath local_path_; |
239 base::FilePath intermediate_path_; | 233 base::FilePath intermediate_path_; |
240 | 234 |
241 content::DownloadItem* download_; | 235 content::DownloadItem* download_; |
242 DownloadPrefs* download_prefs_; | 236 DownloadPrefs* download_prefs_; |
243 DownloadTargetDeterminerDelegate* delegate_; | 237 DownloadTargetDeterminerDelegate* delegate_; |
244 base::FilePath last_selected_directory_; | |
245 content::DownloadTargetCallback completion_callback_; | 238 content::DownloadTargetCallback completion_callback_; |
246 CancelableRequestConsumer history_consumer_; | 239 CancelableRequestConsumer history_consumer_; |
247 | 240 |
248 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; | 241 base::WeakPtrFactory<DownloadTargetDeterminer> weak_ptr_factory_; |
249 | 242 |
250 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); | 243 DISALLOW_COPY_AND_ASSIGN(DownloadTargetDeterminer); |
251 }; | 244 }; |
252 | 245 |
253 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ | 246 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_H_ |
OLD | NEW |