OLD | NEW |
---|---|
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 CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 | 139 |
140 // Notes from Init() above applies here as well. | 140 // Notes from Init() above applies here as well. |
141 void InternalInit(); | 141 void InternalInit(); |
142 | 142 |
143 void Stop(); | 143 void Stop(); |
144 void CheckFinish(); | 144 void CheckFinish(); |
145 void SaveNextFile(bool process_all_remainder_items); | 145 void SaveNextFile(bool process_all_remainder_items); |
146 void DoSavingProcess(); | 146 void DoSavingProcess(); |
147 | 147 |
148 // WebContentsObserver implementation. | 148 // WebContentsObserver implementation. |
149 bool OnMessageReceived(const IPC::Message& message) override; | 149 bool OnMessageReceived(const IPC::Message&) override; |
nasko
2015/09/03 18:17:02
Why did these methods lose the parameter name? Chr
Łukasz Anforowicz
2015/09/03 19:41:24
Because I saw this practice in Blink and thought t
| |
150 bool OnMessageReceived(const IPC::Message&, RenderFrameHost* source) override; | |
nasko
2015/09/03 18:17:02
nit: Let's keep the parameter name consistent, s/s
Łukasz Anforowicz
2015/09/03 19:41:24
I think that "source" is a better parameter name,
nasko
2015/09/04 16:03:21
In general, the Chrome codebase tries to be consis
Łukasz Anforowicz
2015/09/08 16:23:21
Ok, I've renamed to reuse the name picked by the b
| |
150 | 151 |
151 // DownloadItem::Observer implementation. | 152 // DownloadItem::Observer implementation. |
152 void OnDownloadDestroyed(DownloadItem* download) override; | 153 void OnDownloadDestroyed(DownloadItem* download) override; |
153 | 154 |
154 // Update the download history of this item upon completion. | 155 // Update the download history of this item upon completion. |
155 void FinalizeDownloadEntry(); | 156 void FinalizeDownloadEntry(); |
156 | 157 |
157 // Detach from DownloadManager. | 158 // Detach from DownloadManager. |
158 void StopObservation(); | 159 void StopObservation(); |
159 | 160 |
160 // Return max length of a path for a specific base directory. | 161 // Return max length of a path for a specific base directory. |
161 // This is needed on POSIX, which restrict the length of file names in | 162 // This is needed on POSIX, which restrict the length of file names in |
162 // addition to the restriction on the length of path names. | 163 // addition to the restriction on the length of path names. |
163 // |base_dir| is assumed to be a directory name with no trailing slash. | 164 // |base_dir| is assumed to be a directory name with no trailing slash. |
164 static uint32 GetMaxPathLengthForDirectory(const base::FilePath& base_dir); | 165 static uint32 GetMaxPathLengthForDirectory(const base::FilePath& base_dir); |
165 | 166 |
166 static bool GetSafePureFileName( | 167 static bool GetSafePureFileName( |
167 const base::FilePath& dir_path, | 168 const base::FilePath& dir_path, |
168 const base::FilePath::StringType& file_name_ext, | 169 const base::FilePath::StringType& file_name_ext, |
169 uint32 max_file_path_len, | 170 uint32 max_file_path_len, |
170 base::FilePath::StringType* pure_file_name); | 171 base::FilePath::StringType* pure_file_name); |
171 | 172 |
172 // Create a file name based on the response from the server. | 173 // Create a file name based on the response from the server. |
173 bool GenerateFileName(const std::string& disposition, | 174 bool GenerateFileName(const std::string& disposition, |
174 const GURL& url, | 175 const GURL& url, |
175 bool need_html_ext, | 176 bool need_html_ext, |
176 base::FilePath::StringType* generated_name); | 177 base::FilePath::StringType* generated_name); |
177 | 178 |
178 // Get all savable resource links from current web page, include main | 179 // Set of methods to get all savable resource links from current web page, |
179 // frame and sub-frame. | 180 // including main frame and sub-frames. |
180 void GetAllSavableResourceLinksForCurrentPage(); | 181 void GetSavableResourceLinksForCurrentPage(); |
182 void GetSavableResourceLinksForFrame(RenderFrameHost* target); | |
183 void OnSavableResourceLinksResponse( | |
184 RenderFrameHost* source, | |
185 const std::vector<GURL>& resources_list, | |
186 const std::vector<Referrer>& referrers_list); | |
187 void OnSavableResourceLinksError(RenderFrameHost* source); | |
188 void CompleteSavableResourceLinksResponseFromFrame(); | |
189 | |
181 // Get html data by serializing all frames of current page with lists | 190 // Get html data by serializing all frames of current page with lists |
182 // which contain all resource links that have local copy. | 191 // which contain all resource links that have local copy. |
183 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(); | 192 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(); |
184 | 193 |
185 // Look up SaveItem by save id from in progress map. | 194 // Look up SaveItem by save id from in progress map. |
186 SaveItem* LookupItemInProcessBySaveId(int32 save_id); | 195 SaveItem* LookupItemInProcessBySaveId(int32 save_id); |
187 | 196 |
188 // Remove SaveItem from in progress map and put it to saved map. | 197 // Remove SaveItem from in progress map and put it to saved map. |
189 void PutInProgressItemToSavedMap(SaveItem* save_item); | 198 void PutInProgressItemToSavedMap(SaveItem* save_item); |
190 | 199 |
191 // Retrieves the URL to be saved from the WebContents. | 200 // Retrieves the URL to be saved from the WebContents. |
192 GURL GetUrlToBeSaved(); | 201 GURL GetUrlToBeSaved(); |
193 | 202 |
194 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, | 203 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, |
195 const base::FilePath& download_save_dir, | 204 const base::FilePath& download_save_dir, |
196 bool skip_dir_check, | 205 bool skip_dir_check, |
197 const std::string& mime_type, | 206 const std::string& mime_type, |
198 const std::string& accept_langs); | 207 const std::string& accept_langs); |
199 void ContinueGetSaveInfo(const base::FilePath& suggested_path, | 208 void ContinueGetSaveInfo(const base::FilePath& suggested_path, |
200 bool can_save_as_complete); | 209 bool can_save_as_complete); |
201 void OnPathPicked( | 210 void OnPathPicked( |
202 const base::FilePath& final_name, | 211 const base::FilePath& final_name, |
203 SavePageType type, | 212 SavePageType type, |
204 const SavePackageDownloadCreatedCallback& cb); | 213 const SavePackageDownloadCreatedCallback& cb); |
205 void OnReceivedSavableResourceLinksForCurrentPage( | |
206 const std::vector<GURL>& resources_list, | |
207 const std::vector<Referrer>& referrers_list, | |
208 const std::vector<GURL>& frames_list); | |
209 | 214 |
210 void OnReceivedSerializedHtmlData(const GURL& frame_url, | 215 void OnReceivedSerializedHtmlData(const GURL& frame_url, |
211 const std::string& data, | 216 const std::string& data, |
212 int32 status); | 217 int32 status); |
213 | 218 |
214 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; | 219 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; |
215 // in_progress_items_ is map of all saving job in in-progress state. | 220 // in_progress_items_ is map of all saving job in in-progress state. |
216 SaveUrlItemMap in_progress_items_; | 221 SaveUrlItemMap in_progress_items_; |
217 // saved_failed_items_ is map of all saving job which are failed. | 222 // saved_failed_items_ is map of all saving job which are failed. |
218 SaveUrlItemMap saved_failed_items_; | 223 SaveUrlItemMap saved_failed_items_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 259 |
255 // Returns extension for supported MIME types (for example, for "text/plain" | 260 // Returns extension for supported MIME types (for example, for "text/plain" |
256 // it returns "txt"). | 261 // it returns "txt"). |
257 static const base::FilePath::CharType* ExtensionForMimeType( | 262 static const base::FilePath::CharType* ExtensionForMimeType( |
258 const std::string& contents_mime_type); | 263 const std::string& contents_mime_type); |
259 | 264 |
260 typedef std::queue<SaveItem*> SaveItemQueue; | 265 typedef std::queue<SaveItem*> SaveItemQueue; |
261 // A queue for items we are about to start saving. | 266 // A queue for items we are about to start saving. |
262 SaveItemQueue waiting_item_queue_; | 267 SaveItemQueue waiting_item_queue_; |
263 | 268 |
269 // Used to de-dupe urls that are being gathered into |waiting_item_queue_|. | |
270 std::set<GURL> unique_urls_to_save_; | |
271 | |
272 // Number of pending FrameMsg_GetSavableResourceLinks without a response. | |
273 int number_of_frames_with_pending_get_savable_resource_links_; | |
nasko
2015/09/03 18:17:02
I wonder if we can name this a bit shorter. Do we
Łukasz Anforowicz
2015/09/03 19:41:24
We will probably need something equivalent for per
nasko
2015/09/04 16:03:21
The latter message will likely need it. The questi
Łukasz Anforowicz
2015/09/08 16:23:21
Ah, makes sense. Each instance of SavePackage onl
| |
274 | |
264 typedef base::hash_map<int32, SaveItem*> SavedItemMap; | 275 typedef base::hash_map<int32, SaveItem*> SavedItemMap; |
265 // saved_success_items_ is map of all saving job which are successfully saved. | 276 // saved_success_items_ is map of all saving job which are successfully saved. |
266 SavedItemMap saved_success_items_; | 277 SavedItemMap saved_success_items_; |
267 | 278 |
268 // Non-owning pointer for handling file writing on the file thread. | 279 // Non-owning pointer for handling file writing on the file thread. |
269 SaveFileManager* file_manager_; | 280 SaveFileManager* file_manager_; |
270 | 281 |
271 // DownloadManager owns the DownloadItem and handles history and UI. | 282 // DownloadManager owns the DownloadItem and handles history and UI. |
272 DownloadManagerImpl* download_manager_; | 283 DownloadManagerImpl* download_manager_; |
273 DownloadItemImpl* download_; | 284 DownloadItemImpl* download_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 friend class SavePackageTest; | 342 friend class SavePackageTest; |
332 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 343 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
333 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 344 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
334 | 345 |
335 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 346 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
336 }; | 347 }; |
337 | 348 |
338 } // namespace content | 349 } // namespace content |
339 | 350 |
340 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 351 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
OLD | NEW |