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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // written to disk. | 103 // written to disk. |
104 bool Init(const SavePackageDownloadCreatedCallback& cb); | 104 bool Init(const SavePackageDownloadCreatedCallback& cb); |
105 | 105 |
106 // Cancel all in progress request, might be called by user or internal error. | 106 // Cancel all in progress request, might be called by user or internal error. |
107 void Cancel(bool user_action); | 107 void Cancel(bool user_action); |
108 | 108 |
109 void Finish(); | 109 void Finish(); |
110 | 110 |
111 // Notifications sent from the file thread to the UI thread. | 111 // Notifications sent from the file thread to the UI thread. |
112 void StartSave(const SaveFileCreateInfo* info); | 112 void StartSave(const SaveFileCreateInfo* info); |
113 bool UpdateSaveProgress(int32_t save_item_id, | 113 bool UpdateSaveProgress(SaveItemId save_item_id, |
114 int64_t size, | 114 int64_t size, |
115 bool write_success); | 115 bool write_success); |
116 void SaveFinished(int32_t save_item_id, int64_t size, bool is_success); | 116 void SaveFinished(SaveItemId save_item_id, int64_t size, bool is_success); |
117 void SaveCanceled(SaveItem* save_item); | 117 void SaveCanceled(SaveItem* save_item); |
118 | 118 |
119 // Rough percent complete, -1 means we don't know (since we didn't receive a | 119 // Rough percent complete, -1 means we don't know (since we didn't receive a |
120 // total size). | 120 // total size). |
121 int PercentComplete(); | 121 int PercentComplete(); |
122 | 122 |
123 bool canceled() const { return user_canceled_ || disk_error_occurred_; } | 123 bool canceled() const { return user_canceled_ || disk_error_occurred_; } |
124 bool finished() const { return finished_; } | 124 bool finished() const { return finished_; } |
125 SavePageType save_type() const { return save_type_; } | 125 SavePageType save_type() const { return save_type_; } |
126 int id() const { return unique_id_; } | 126 |
| 127 SavePackageId id() const { return unique_id_; } |
127 | 128 |
128 void GetSaveInfo(); | 129 void GetSaveInfo(); |
129 | 130 |
130 private: | 131 private: |
131 friend class base::RefCountedThreadSafe<SavePackage>; | 132 friend class base::RefCountedThreadSafe<SavePackage>; |
132 | 133 |
133 void InitWithDownloadItem( | 134 void InitWithDownloadItem( |
134 const SavePackageDownloadCreatedCallback& download_created_callback, | 135 const SavePackageDownloadCreatedCallback& download_created_callback, |
135 DownloadItemImpl* item); | 136 DownloadItemImpl* item); |
136 | 137 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node); | 250 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node); |
250 | 251 |
251 // Routes html data (sent by renderer process in response to | 252 // Routes html data (sent by renderer process in response to |
252 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file | 253 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file |
253 // (and also keeps track of when all frames have been completed). | 254 // (and also keeps track of when all frames have been completed). |
254 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender, | 255 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender, |
255 const std::string& data, | 256 const std::string& data, |
256 bool end_of_data); | 257 bool end_of_data); |
257 | 258 |
258 // Look up SaveItem by save item id from in progress map. | 259 // Look up SaveItem by save item id from in progress map. |
259 SaveItem* LookupSaveItemInProcess(int32_t save_item_id); | 260 SaveItem* LookupSaveItemInProcess(SaveItemId save_item_id); |
260 | 261 |
261 // Remove SaveItem from in progress map and put it to saved map. | 262 // Remove SaveItem from in progress map and put it to saved map. |
262 void PutInProgressItemToSavedMap(SaveItem* save_item); | 263 void PutInProgressItemToSavedMap(SaveItem* save_item); |
263 | 264 |
264 // Retrieves the URL to be saved from the WebContents. | 265 // Retrieves the URL to be saved from the WebContents. |
265 GURL GetUrlToBeSaved(); | 266 GURL GetUrlToBeSaved(); |
266 | 267 |
267 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, | 268 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, |
268 const base::FilePath& download_save_dir, | 269 const base::FilePath& download_save_dir, |
269 bool skip_dir_check, | 270 bool skip_dir_check, |
270 const std::string& mime_type, | 271 const std::string& mime_type, |
271 const std::string& accept_langs); | 272 const std::string& accept_langs); |
272 void ContinueGetSaveInfo(const base::FilePath& suggested_path, | 273 void ContinueGetSaveInfo(const base::FilePath& suggested_path, |
273 bool can_save_as_complete); | 274 bool can_save_as_complete); |
274 void OnPathPicked( | 275 void OnPathPicked( |
275 const base::FilePath& final_name, | 276 const base::FilePath& final_name, |
276 SavePageType type, | 277 SavePageType type, |
277 const SavePackageDownloadCreatedCallback& cb); | 278 const SavePackageDownloadCreatedCallback& cb); |
278 | 279 |
279 // Map from SaveItem::id() (aka save_item_id) into a SaveItem. | 280 // Map from SaveItem::id() (aka save_item_id) into a SaveItem. |
280 typedef base::hash_map<int, SaveItem*> SaveItemIdMap; | 281 typedef base::hash_map<SaveItemId, SaveItem*> SaveItemIdMap; |
281 // in_progress_items_ is map of all saving job in in-progress state. | 282 // in_progress_items_ is map of all saving job in in-progress state. |
282 SaveItemIdMap in_progress_items_; | 283 SaveItemIdMap in_progress_items_; |
283 // saved_failed_items_ is map of all saving job which are failed. | 284 // saved_failed_items_ is map of all saving job which are failed. |
284 SaveItemIdMap saved_failed_items_; | 285 SaveItemIdMap saved_failed_items_; |
285 | 286 |
286 // The number of in process SaveItems. | 287 // The number of in process SaveItems. |
287 int in_process_count() const { | 288 int in_process_count() const { |
288 return static_cast<int>(in_progress_items_.size()); | 289 return static_cast<int>(in_progress_items_.size()); |
289 } | 290 } |
290 | 291 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // (i.e. to prevent information disclosure to oop frames). | 344 // (i.e. to prevent information disclosure to oop frames). |
344 // Note that |frame_tree_node_id_to_contained_save_items_| does NOT own | 345 // Note that |frame_tree_node_id_to_contained_save_items_| does NOT own |
345 // SaveItems - they remain owned by waiting_item_queue_, in_progress_items_, | 346 // SaveItems - they remain owned by waiting_item_queue_, in_progress_items_, |
346 // etc. | 347 // etc. |
347 base::hash_map<int, std::vector<SaveItem*>> | 348 base::hash_map<int, std::vector<SaveItem*>> |
348 frame_tree_node_id_to_contained_save_items_; | 349 frame_tree_node_id_to_contained_save_items_; |
349 | 350 |
350 // Number of frames that we still need to get a response from. | 351 // Number of frames that we still need to get a response from. |
351 int number_of_frames_pending_response_; | 352 int number_of_frames_pending_response_; |
352 | 353 |
353 typedef base::hash_map<int32_t, SaveItem*> SavedItemMap; | |
354 // saved_success_items_ is map of all saving job which are successfully saved. | 354 // saved_success_items_ is map of all saving job which are successfully saved. |
355 SavedItemMap saved_success_items_; | 355 base::hash_map<SaveItemId, SaveItem*> saved_success_items_; |
356 | 356 |
357 // Non-owning pointer for handling file writing on the file thread. | 357 // Non-owning pointer for handling file writing on the file thread. |
358 SaveFileManager* file_manager_; | 358 SaveFileManager* file_manager_; |
359 | 359 |
360 // DownloadManager owns the DownloadItem and handles history and UI. | 360 // DownloadManager owns the DownloadItem and handles history and UI. |
361 DownloadManagerImpl* download_manager_; | 361 DownloadManagerImpl* download_manager_; |
362 DownloadItemImpl* download_; | 362 DownloadItemImpl* download_; |
363 | 363 |
364 // The URL of the page the user wants to save. | 364 // The URL of the page the user wants to save. |
365 GURL page_url_; | 365 GURL page_url_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 typedef base::hash_map<base::FilePath::StringType, uint32_t> FileNameCountMap; | 400 typedef base::hash_map<base::FilePath::StringType, uint32_t> FileNameCountMap; |
401 // This map is used to track serial number for specified filename. | 401 // This map is used to track serial number for specified filename. |
402 FileNameCountMap file_name_count_map_; | 402 FileNameCountMap file_name_count_map_; |
403 | 403 |
404 // Indicates current waiting state when SavePackage try to get something | 404 // Indicates current waiting state when SavePackage try to get something |
405 // from outside. | 405 // from outside. |
406 WaitState wait_state_; | 406 WaitState wait_state_; |
407 | 407 |
408 // Unique ID for this SavePackage. | 408 // Unique ID for this SavePackage. |
409 const int unique_id_; | 409 const SavePackageId unique_id_; |
410 | 410 |
411 // Variables to record errors that happened so we can record them via | 411 // Variables to record errors that happened so we can record them via |
412 // UMA statistics. | 412 // UMA statistics. |
413 bool wrote_to_completed_file_; | 413 bool wrote_to_completed_file_; |
414 bool wrote_to_failed_file_; | 414 bool wrote_to_failed_file_; |
415 | 415 |
416 friend class SavePackageTest; | 416 friend class SavePackageTest; |
417 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 417 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
418 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 418 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
419 | 419 |
420 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 420 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
421 }; | 421 }; |
422 | 422 |
423 } // namespace content | 423 } // namespace content |
424 | 424 |
425 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 425 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
OLD | NEW |