Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: content/browser/download/save_package.h

Issue 1308113008: OOPIFs: Transitioning Get/Send...SavableResourceLinks away from RenderViewHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-test
Patch Set: Addressed CR feedback from Randy. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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& message) override;
150 bool OnMessageReceived(const IPC::Message& message,
151 RenderFrameHost* render_frame_host) override;
150 152
151 // DownloadItem::Observer implementation. 153 // DownloadItem::Observer implementation.
152 void OnDownloadDestroyed(DownloadItem* download) override; 154 void OnDownloadDestroyed(DownloadItem* download) override;
153 155
154 // Update the download history of this item upon completion. 156 // Update the download history of this item upon completion.
155 void FinalizeDownloadEntry(); 157 void FinalizeDownloadEntry();
156 158
157 // Detach from DownloadManager. 159 // Detach from DownloadManager.
158 void StopObservation(); 160 void StopObservation();
159 161
160 // Return max length of a path for a specific base directory. 162 // 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 163 // This is needed on POSIX, which restrict the length of file names in
162 // addition to the restriction on the length of path names. 164 // addition to the restriction on the length of path names.
163 // |base_dir| is assumed to be a directory name with no trailing slash. 165 // |base_dir| is assumed to be a directory name with no trailing slash.
164 static uint32 GetMaxPathLengthForDirectory(const base::FilePath& base_dir); 166 static uint32 GetMaxPathLengthForDirectory(const base::FilePath& base_dir);
165 167
166 static bool GetSafePureFileName( 168 static bool GetSafePureFileName(
167 const base::FilePath& dir_path, 169 const base::FilePath& dir_path,
168 const base::FilePath::StringType& file_name_ext, 170 const base::FilePath::StringType& file_name_ext,
169 uint32 max_file_path_len, 171 uint32 max_file_path_len,
170 base::FilePath::StringType* pure_file_name); 172 base::FilePath::StringType* pure_file_name);
171 173
172 // Create a file name based on the response from the server. 174 // Create a file name based on the response from the server.
173 bool GenerateFileName(const std::string& disposition, 175 bool GenerateFileName(const std::string& disposition,
174 const GURL& url, 176 const GURL& url,
175 bool need_html_ext, 177 bool need_html_ext,
176 base::FilePath::StringType* generated_name); 178 base::FilePath::StringType* generated_name);
177 179
178 // Get all savable resource links from current web page, include main 180 // Set of methods to get all savable resource links from current web page,
179 // frame and sub-frame. 181 // including main frame and sub-frames.
180 void GetAllSavableResourceLinksForCurrentPage(); 182 void GetSavableResourceLinksForCurrentPage();
183 void GetSavableResourceLinksForFrame(RenderFrameHost* target);
184 void OnSavableResourceLinksResponse(
185 RenderFrameHost* sender,
186 const GURL& frame_url,
187 const std::vector<GURL>& resources_list,
188 const std::vector<Referrer>& referrers_list);
189 void OnSavableResourceLinksError(RenderFrameHost* sender);
190 void CompleteSavableResourceLinksResponseFromFrame();
191
181 // Get html data by serializing all frames of current page with lists 192 // Get html data by serializing all frames of current page with lists
182 // which contain all resource links that have local copy. 193 // which contain all resource links that have local copy.
183 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(); 194 void GetSerializedHtmlDataForCurrentPageWithLocalLinks();
184 195
185 // Look up SaveItem by save id from in progress map. 196 // Look up SaveItem by save id from in progress map.
186 SaveItem* LookupItemInProcessBySaveId(int32 save_id); 197 SaveItem* LookupItemInProcessBySaveId(int32 save_id);
187 198
188 // Remove SaveItem from in progress map and put it to saved map. 199 // Remove SaveItem from in progress map and put it to saved map.
189 void PutInProgressItemToSavedMap(SaveItem* save_item); 200 void PutInProgressItemToSavedMap(SaveItem* save_item);
190 201
191 // Retrieves the URL to be saved from the WebContents. 202 // Retrieves the URL to be saved from the WebContents.
192 GURL GetUrlToBeSaved(); 203 GURL GetUrlToBeSaved();
193 204
194 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, 205 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir,
195 const base::FilePath& download_save_dir, 206 const base::FilePath& download_save_dir,
196 bool skip_dir_check, 207 bool skip_dir_check,
197 const std::string& mime_type, 208 const std::string& mime_type,
198 const std::string& accept_langs); 209 const std::string& accept_langs);
199 void ContinueGetSaveInfo(const base::FilePath& suggested_path, 210 void ContinueGetSaveInfo(const base::FilePath& suggested_path,
200 bool can_save_as_complete); 211 bool can_save_as_complete);
201 void OnPathPicked( 212 void OnPathPicked(
202 const base::FilePath& final_name, 213 const base::FilePath& final_name,
203 SavePageType type, 214 SavePageType type,
204 const SavePackageDownloadCreatedCallback& cb); 215 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 216
210 void OnReceivedSerializedHtmlData(const GURL& frame_url, 217 void OnReceivedSerializedHtmlData(const GURL& frame_url,
211 const std::string& data, 218 const std::string& data,
212 int32 status); 219 int32 status);
213 220
214 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; 221 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap;
215 // in_progress_items_ is map of all saving job in in-progress state. 222 // in_progress_items_ is map of all saving job in in-progress state.
216 SaveUrlItemMap in_progress_items_; 223 SaveUrlItemMap in_progress_items_;
217 // saved_failed_items_ is map of all saving job which are failed. 224 // saved_failed_items_ is map of all saving job which are failed.
218 SaveUrlItemMap saved_failed_items_; 225 SaveUrlItemMap saved_failed_items_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 261
255 // Returns extension for supported MIME types (for example, for "text/plain" 262 // Returns extension for supported MIME types (for example, for "text/plain"
256 // it returns "txt"). 263 // it returns "txt").
257 static const base::FilePath::CharType* ExtensionForMimeType( 264 static const base::FilePath::CharType* ExtensionForMimeType(
258 const std::string& contents_mime_type); 265 const std::string& contents_mime_type);
259 266
260 typedef std::queue<SaveItem*> SaveItemQueue; 267 typedef std::queue<SaveItem*> SaveItemQueue;
261 // A queue for items we are about to start saving. 268 // A queue for items we are about to start saving.
262 SaveItemQueue waiting_item_queue_; 269 SaveItemQueue waiting_item_queue_;
263 270
271 // Used to de-dupe urls that are being gathered into |waiting_item_queue_|.
272 std::set<GURL> unique_urls_to_save_;
273
274 // Temporarily stores urls of savable frames, until we can process them.
275 std::vector<GURL> frame_urls_to_save_;
276
277 // Number of frames that we still need to get a response from.
278 int number_of_frames_pending_response_;
279
264 typedef base::hash_map<int32, SaveItem*> SavedItemMap; 280 typedef base::hash_map<int32, SaveItem*> SavedItemMap;
265 // saved_success_items_ is map of all saving job which are successfully saved. 281 // saved_success_items_ is map of all saving job which are successfully saved.
266 SavedItemMap saved_success_items_; 282 SavedItemMap saved_success_items_;
267 283
268 // Non-owning pointer for handling file writing on the file thread. 284 // Non-owning pointer for handling file writing on the file thread.
269 SaveFileManager* file_manager_; 285 SaveFileManager* file_manager_;
270 286
271 // DownloadManager owns the DownloadItem and handles history and UI. 287 // DownloadManager owns the DownloadItem and handles history and UI.
272 DownloadManagerImpl* download_manager_; 288 DownloadManagerImpl* download_manager_;
273 DownloadItemImpl* download_; 289 DownloadItemImpl* download_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 friend class SavePackageTest; 347 friend class SavePackageTest;
332 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); 348 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames);
333 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); 349 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename);
334 350
335 DISALLOW_COPY_AND_ASSIGN(SavePackage); 351 DISALLOW_COPY_AND_ASSIGN(SavePackage);
336 }; 352 };
337 353
338 } // namespace content 354 } // namespace content
339 355
340 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 356 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698