Chromium Code Reviews| Index: content/browser/download/save_package.h |
| diff --git a/content/browser/download/save_package.h b/content/browser/download/save_package.h |
| index 818ad5bf524a7523393af4f2389dd1082cdfe424..719f4981ca96dc3edfa863438d9c768d81ee63ea 100644 |
| --- a/content/browser/download/save_package.h |
| +++ b/content/browser/download/save_package.h |
| @@ -5,7 +5,8 @@ |
| #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
| #define CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
| -#include <queue> |
| +#include <deque> |
| +#include <map> |
| #include <set> |
| #include <string> |
| #include <vector> |
| @@ -51,6 +52,8 @@ struct SaveFileCreateInfo; |
| // saved. Each file is represented by a SaveItem, and all SaveItems are owned |
| // by the SavePackage. SaveItems are created when a user initiates a page |
| // saving job, and exist for the duration of one contents's life time. |
| +// SaveItems go through waiting_item_queue_, in_progress_items_ and finally |
| +// end up either in saved_success_items_ or saved_failed_items_. |
| class CONTENT_EXPORT SavePackage |
| : public base::RefCountedThreadSafe<SavePackage>, |
| public WebContentsObserver, |
| @@ -189,32 +192,48 @@ class CONTENT_EXPORT SavePackage |
| void CompleteSavableResourceLinksResponse(); |
| // For each frame in the current page, ask the renderer process associated |
| - // with that frame to serialize that frame into html. |
| + // with that frame to serialize that frame into html (serialize into html with |
| + // "blanks" that we can replace with links to local paths). |
|
ncarter (slow)
2015/10/08 20:57:55
Make this parenthetical clause its own sentence, s
Łukasz Anforowicz
2015/10/09 16:54:08
I guess this comment is confusing (I have a feelin
|
| void GetSerializedHtmlWithLocalLinks(); |
| - // Ask renderer process to serialize |target| frame into html data |
| - // with lists which contain all resource links that have a local copy. |
| - // - The parameter |saved_links| contains original URLs of all saved links |
| - // (which may include URLs referred to from the whole page (not just from |
| - // the |target| frame). |
| - // - The parameter |saved_file_paths| contains corresponding local file paths |
| - // of all saved links, which is matched with |saved_links| vector one by |
| - // one. |
| - // - The parameter |relative_dir_name| is relative path of directory which |
| - // contain all saved auxiliary files included all sub frames and resouces. |
| - void GetSerializedHtmlWithLocalLinksForFrame( |
| - const std::vector<GURL>& saved_links, |
| - const std::vector<base::FilePath>& saved_file_paths, |
| - const base::FilePath& relative_dir_name, |
| - RenderFrameHost* target); |
| - |
| - // Routes html data (sent by renderer process in response to |
| - // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file |
| - // (and also keeps track of when all frames have been completed). |
| - void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHost* sender, |
| - const GURL& frame_url, |
| - const std::string& data, |
| - int32 status); |
| + // Equivalent of GetSerializedHtmlWithLocalLinks that targets a single |
| + // |target| frame. |
| + void GetSerializedHtmlWithLocalLinksForFrame(RenderFrameHost* target); |
| + |
| + // Response to GetSerializedHtmlWithLocalLinksForFrame above that routes html |
| + // fragment into the local file associated with |sender|. |
| + void OnSerializedHtmlFragment(RenderFrameHost* sender, |
| + const std::string& data); |
| + |
| + // Response to GetSerializedHtmlWithLocalLinksForFrame above that replaces |
| + // |render_frame_or_proxy_routing_id| with a corresponding local path |
| + // and then writes the result to the local file associated with |sender|. |
| + void OnSerializedLocalPathForSubFrame(RenderFrameHost* sender, |
| + int render_frame_or_proxy_routing_id); |
| + |
| + // Response to GetSerializedHtmlWithLocalLinksForFrame above that replaces |
| + // |savable_resource| with a corresponding local path and then writes the |
| + // result to the local file associated with |sender|. |
| + void OnSerializedLocalPathForSavableResource(RenderFrameHost* sender, |
| + const GURL& savable_resource); |
| + |
| + // Response to GetSerializedHtmlWithLocalLinksForFrame above that keeps track |
| + // of how many frames still need to complete their serialization process. |
| + void OnSerializedEndOfFrame(RenderFrameHost* sender); |
| + |
| + // Helper used by OnSerializedLocalPathForSubFrame and |
| + // OnSerializedLocalPathForSavableResource to convert |save_item| into a local |
| + // path (and falling back to |fallback_url| if |save_item| is null). |
| + void SerializeLocalPathForSaveItem(RenderFrameHost* sender, |
| + SaveItem* save_item, |
| + const GURL& fallback_url); |
| + |
| + // Finds in-progress SaveItem by |frame_tree_node_id|. |
| + SaveItem* FindInProgressSaveItemByFrameTreeNodeID(int frame_tree_node_id); |
| + |
| + // Helper to log telemetry entry for writes to already completed or failed |
| + // SaveItems. |
| + void LogWriteToAlreadyCompletedOrFailedSaveItem(SaveItem* save_item); |
| // Look up SaveItem by save id from in progress map. |
| SaveItem* LookupItemInProcessBySaveId(int32 save_id); |
| @@ -283,15 +302,23 @@ class CONTENT_EXPORT SavePackage |
| static const base::FilePath::CharType* ExtensionForMimeType( |
| const std::string& contents_mime_type); |
| - typedef std::queue<SaveItem*> SaveItemQueue; |
| + typedef std::deque<SaveItem*> SaveItemQueue; |
| // A queue for items we are about to start saving. |
| SaveItemQueue waiting_item_queue_; |
| - // Used to de-dupe urls that are being gathered into |waiting_item_queue_|. |
| - std::set<GURL> unique_urls_to_save_; |
| - |
| - // Temporarily stores urls of savable frames, until we can process them. |
| - std::vector<GURL> frame_urls_to_save_; |
| + // Used to |
| + // 1) de-dupe urls that are being gathered via GetSavableResourceLinks, |
| + // 2) find a SaveItem which needs to be updated with frame_tree_node_id or |
| + // referrer, |
| + // 3) find local path for savable resource. |
| + // Note that |url_to_save_item_| does NOT own SaveItems - they remain owned |
| + // by waiting_item_queue_, in_progress_items_, saved_success_items_, etc. |
| + std::map<GURL, SaveItem*> url_to_save_item_; |
| + |
| + // Used to find local path for a subframe. |
| + // Note that |frame_tree_node_id_to_save_item_| does NOT own SaveItems - they |
| + // remain owned by waiting_item_queue_, in_progress_items_, etc. |
| + std::map<int, SaveItem*> frame_tree_node_id_to_save_item_; |
| // Number of frames that we still need to get a response from. |
| int number_of_frames_pending_response_; |