Chromium Code Reviews| 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 <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // written to disk. | 100 // written to disk. |
| 101 bool Init(const SavePackageDownloadCreatedCallback& cb); | 101 bool Init(const SavePackageDownloadCreatedCallback& cb); |
| 102 | 102 |
| 103 // Cancel all in progress request, might be called by user or internal error. | 103 // Cancel all in progress request, might be called by user or internal error. |
| 104 void Cancel(bool user_action); | 104 void Cancel(bool user_action); |
| 105 | 105 |
| 106 void Finish(); | 106 void Finish(); |
| 107 | 107 |
| 108 // Notifications sent from the file thread to the UI thread. | 108 // Notifications sent from the file thread to the UI thread. |
| 109 void StartSave(const SaveFileCreateInfo* info); | 109 void StartSave(const SaveFileCreateInfo* info); |
| 110 bool UpdateSaveProgress(int32 save_id, int64 size, bool write_success); | 110 bool UpdateSaveProgress(int32 save_item_id, int64 size, bool write_success); |
| 111 void SaveFinished(int32 save_id, int64 size, bool is_success); | 111 void SaveFinished(int32 save_item_id, int64 size, bool is_success); |
| 112 void SaveFailed(const GURL& save_url); | |
| 113 void SaveCanceled(SaveItem* save_item); | 112 void SaveCanceled(SaveItem* save_item); |
| 114 | 113 |
| 115 // Rough percent complete, -1 means we don't know (since we didn't receive a | 114 // Rough percent complete, -1 means we don't know (since we didn't receive a |
| 116 // total size). | 115 // total size). |
| 117 int PercentComplete(); | 116 int PercentComplete(); |
| 118 | 117 |
| 119 bool canceled() const { return user_canceled_ || disk_error_occurred_; } | 118 bool canceled() const { return user_canceled_ || disk_error_occurred_; } |
| 120 bool finished() const { return finished_; } | 119 bool finished() const { return finished_; } |
| 121 SavePageType save_type() const { return save_type_; } | 120 SavePageType save_type() const { return save_type_; } |
| 122 int id() const { return unique_id_; } | 121 int id() const { return unique_id_; } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 bool need_html_ext, | 178 bool need_html_ext, |
| 180 base::FilePath::StringType* generated_name); | 179 base::FilePath::StringType* generated_name); |
| 181 | 180 |
| 182 // Main routine that initiates asking all frames for their savable resources, | 181 // Main routine that initiates asking all frames for their savable resources, |
| 183 // using GetSavableResourceLinksForFrame to send IPC to individual frames. | 182 // using GetSavableResourceLinksForFrame to send IPC to individual frames. |
| 184 // | 183 // |
| 185 // Responses are received asynchronously by OnSavableResourceLinks... methods | 184 // Responses are received asynchronously by OnSavableResourceLinks... methods |
| 186 // and pending responses are counted/tracked by | 185 // and pending responses are counted/tracked by |
| 187 // CompleteSavableResourceLinksResponse. | 186 // CompleteSavableResourceLinksResponse. |
| 188 // | 187 // |
| 189 // OnSavableResourceLinksResponse creates of SaveItems for each savable | 188 // OnSavableResourceLinksResponse creates of SaveItems for each savable |
|
Randy Smith (Not in Mondays)
2015/12/03 20:58:28
nit: Willing to fix this grammar while you're here
Łukasz Anforowicz
2015/12/04 21:16:45
Oops. That came from my commit :-)
| |
| 190 // resource and each subframe which get enqueued into |waiting_item_queue_| | 189 // resource and each subframe which get enqueued into |waiting_item_queue_| |
| 191 // with the help of FindOrCreatePendingSaveItem, EnqueueSavableResource, | 190 // with the help of CreatePendingSaveItem, EnqueueSavableResource, |
| 192 // EnqueueFrame. | 191 // EnqueueFrame. |
| 193 void GetSavableResourceLinks(); | 192 void GetSavableResourceLinks(); |
| 194 | 193 |
| 195 // Asks a given frame for its savable resources. | 194 // Asks a given frame for its savable resources. |
| 196 void GetSavableResourceLinksForFrame(RenderFrameHost* target); | 195 void GetSavableResourceLinksForFrame(RenderFrameHost* target); |
| 197 | 196 |
| 198 // Response from |sender| frame to GetSavableResourceLinksForFrame request. | 197 // Response from |sender| frame to GetSavableResourceLinksForFrame request. |
| 199 void OnSavableResourceLinksResponse( | 198 void OnSavableResourceLinksResponse( |
| 200 RenderFrameHostImpl* sender, | 199 RenderFrameHostImpl* sender, |
| 201 const std::vector<GURL>& resources_list, | 200 const std::vector<GURL>& resources_list, |
| 202 const Referrer& referrer, | 201 const Referrer& referrer, |
| 203 const std::vector<SavableSubframe>& subframes); | 202 const std::vector<SavableSubframe>& subframes); |
| 204 | 203 |
| 205 // Helper for finding or creating a SaveItem with the given parameters. | 204 // Helper for finding or creating a SaveItem with the given parameters. |
| 206 SaveItem* FindOrCreatePendingSaveItem( | 205 SaveItem* CreatePendingSaveItem( |
| 207 int container_frame_tree_node_id, | 206 int container_frame_tree_node_id, |
| 208 const GURL& url, | 207 const GURL& url, |
| 209 const Referrer& referrer, | 208 const Referrer& referrer, |
| 209 SaveFileCreateInfo::SaveFileSource save_source); | |
| 210 | |
| 211 // Helper for finding a SaveItem with the given url, or falling back to | |
| 212 // creating a SaveItem with the given parameters. | |
| 213 SaveItem* CreatePendingSaveItemDeduplicatingByUrl( | |
| 214 int container_frame_tree_node_id, | |
| 215 const GURL& url, | |
| 216 const Referrer& referrer, | |
| 210 SaveFileCreateInfo::SaveFileSource save_source); | 217 SaveFileCreateInfo::SaveFileSource save_source); |
| 211 | 218 |
| 212 // Helper to enqueue a savable resource reported by | 219 // Helper to enqueue a savable resource reported by |
| 213 // GetSavableResourceLinksForFrame. | 220 // GetSavableResourceLinksForFrame. |
| 214 void EnqueueSavableResource(int container_frame_tree_node_id, | 221 void EnqueueSavableResource(int container_frame_tree_node_id, |
| 215 const GURL& url, | 222 const GURL& url, |
| 216 const Referrer& referrer); | 223 const Referrer& referrer); |
| 217 // Helper to enqueue a subframe reported by GetSavableResourceLinksForFrame. | 224 // Helper to enqueue a subframe reported by GetSavableResourceLinksForFrame. |
| 218 void EnqueueFrame(int container_frame_tree_node_id, | 225 void EnqueueFrame(int container_frame_tree_node_id, |
| 219 int frame_tree_node_id, | 226 int frame_tree_node_id, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 236 // with resource links replaced with a link to a locally saved copy. | 243 // with resource links replaced with a link to a locally saved copy. |
| 237 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node); | 244 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node); |
| 238 | 245 |
| 239 // Routes html data (sent by renderer process in response to | 246 // Routes html data (sent by renderer process in response to |
| 240 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file | 247 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file |
| 241 // (and also keeps track of when all frames have been completed). | 248 // (and also keeps track of when all frames have been completed). |
| 242 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender, | 249 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender, |
| 243 const std::string& data, | 250 const std::string& data, |
| 244 bool end_of_data); | 251 bool end_of_data); |
| 245 | 252 |
| 246 // Look up SaveItem by save id from in progress map. | 253 // Look up SaveItem by save item id from in progress map. |
| 247 SaveItem* LookupItemInProcessBySaveId(int32 save_id); | 254 SaveItem* LookupSaveItemInProcess(int32 save_item_id); |
| 248 | 255 |
| 249 // Remove SaveItem from in progress map and put it to saved map. | 256 // Remove SaveItem from in progress map and put it to saved map. |
| 250 void PutInProgressItemToSavedMap(SaveItem* save_item); | 257 void PutInProgressItemToSavedMap(SaveItem* save_item); |
| 251 | 258 |
| 252 // Retrieves the URL to be saved from the WebContents. | 259 // Retrieves the URL to be saved from the WebContents. |
| 253 GURL GetUrlToBeSaved(); | 260 GURL GetUrlToBeSaved(); |
| 254 | 261 |
| 255 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, | 262 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, |
| 256 const base::FilePath& download_save_dir, | 263 const base::FilePath& download_save_dir, |
| 257 bool skip_dir_check, | 264 bool skip_dir_check, |
| 258 const std::string& mime_type, | 265 const std::string& mime_type, |
| 259 const std::string& accept_langs); | 266 const std::string& accept_langs); |
| 260 void ContinueGetSaveInfo(const base::FilePath& suggested_path, | 267 void ContinueGetSaveInfo(const base::FilePath& suggested_path, |
| 261 bool can_save_as_complete); | 268 bool can_save_as_complete); |
| 262 void OnPathPicked( | 269 void OnPathPicked( |
| 263 const base::FilePath& final_name, | 270 const base::FilePath& final_name, |
| 264 SavePageType type, | 271 SavePageType type, |
| 265 const SavePackageDownloadCreatedCallback& cb); | 272 const SavePackageDownloadCreatedCallback& cb); |
| 266 | 273 |
| 267 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; | 274 // Map from SaveItem::id() (aka save_item_id) into a SaveItem. |
| 275 typedef base::hash_map<int, SaveItem*> SaveItemIdMap; | |
| 268 // in_progress_items_ is map of all saving job in in-progress state. | 276 // in_progress_items_ is map of all saving job in in-progress state. |
| 269 SaveUrlItemMap in_progress_items_; | 277 SaveItemIdMap in_progress_items_; |
| 270 // saved_failed_items_ is map of all saving job which are failed. | 278 // saved_failed_items_ is map of all saving job which are failed. |
| 271 SaveUrlItemMap saved_failed_items_; | 279 SaveItemIdMap saved_failed_items_; |
| 272 | 280 |
| 273 // The number of in process SaveItems. | 281 // The number of in process SaveItems. |
| 274 int in_process_count() const { | 282 int in_process_count() const { |
| 275 return static_cast<int>(in_progress_items_.size()); | 283 return static_cast<int>(in_progress_items_.size()); |
| 276 } | 284 } |
| 277 | 285 |
| 278 // The number of all SaveItems which have completed, including success items | 286 // The number of all SaveItems which have completed, including success items |
| 279 // and failed items. | 287 // and failed items. |
| 280 int completed_count() const { | 288 int completed_count() const { |
| 281 return static_cast<int>(saved_success_items_.size() + | 289 return static_cast<int>(saved_success_items_.size() + |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 friend class SavePackageTest; | 411 friend class SavePackageTest; |
| 404 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 412 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
| 405 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 413 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
| 406 | 414 |
| 407 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 415 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
| 408 }; | 416 }; |
| 409 | 417 |
| 410 } // namespace content | 418 } // namespace content |
| 411 | 419 |
| 412 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 420 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
| OLD | NEW |