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

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

Issue 7277073: Support for adding save page download items into downloads history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/hash_tables.h" 16 #include "base/hash_tables.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/task.h" 19 #include "base/task.h"
20 #include "chrome/browser/download/download_manager.h"
20 #include "content/browser/tab_contents/tab_contents_observer.h" 21 #include "content/browser/tab_contents/tab_contents_observer.h"
21 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
22 23
23 class DownloadItem;
24 class DownloadManager;
25 class GURL; 24 class GURL;
26 class MessageLoop; 25 class MessageLoop;
27 class PrefService; 26 class PrefService;
28 class Profile; 27 class Profile;
29 class SaveFileManager; 28 class SaveFileManager;
30 class SaveItem; 29 class SaveItem;
31 class SavePackage; 30 class SavePackage;
32 class TabContents; 31 class TabContents;
33 struct SaveFileCreateInfo; 32 struct SaveFileCreateInfo;
34 struct SavePackageParam; 33 struct SavePackageParam;
(...skipping 11 matching lines...) Expand all
46 // Saving page as complete-html page means we save not only the main html file 45 // Saving page as complete-html page means we save not only the main html file
47 // the user told it to save but also a directory for the auxiliary files such 46 // the user told it to save but also a directory for the auxiliary files such
48 // as all sub-frame html files, image files, css files and js files. 47 // as all sub-frame html files, image files, css files and js files.
49 // 48 //
50 // Each page saving job may include one or multiple files which need to be 49 // Each page saving job may include one or multiple files which need to be
51 // saved. Each file is represented by a SaveItem, and all SaveItems are owned 50 // saved. Each file is represented by a SaveItem, and all SaveItems are owned
52 // by the SavePackage. SaveItems are created when a user initiates a page 51 // by the SavePackage. SaveItems are created when a user initiates a page
53 // saving job, and exist for the duration of one tab's life time. 52 // saving job, and exist for the duration of one tab's life time.
54 class SavePackage : public base::RefCountedThreadSafe<SavePackage>, 53 class SavePackage : public base::RefCountedThreadSafe<SavePackage>,
55 public TabContentsObserver, 54 public TabContentsObserver,
55 public DownloadItem::Observer,
56 public base::SupportsWeakPtr<SavePackage> { 56 public base::SupportsWeakPtr<SavePackage> {
57 public: 57 public:
58 enum SavePackageType { 58 enum SavePackageType {
59 // The value of the save type before its set by the user. 59 // The value of the save type before its set by the user.
60 SAVE_TYPE_UNKNOWN = -1, 60 SAVE_TYPE_UNKNOWN = -1,
61 // User chose to save only the HTML of the page. 61 // User chose to save only the HTML of the page.
62 SAVE_AS_ONLY_HTML = 0, 62 SAVE_AS_ONLY_HTML = 0,
63 // User chose to save complete-html page. 63 // User chose to save complete-html page.
64 SAVE_AS_COMPLETE_HTML = 1 64 SAVE_AS_COMPLETE_HTML = 1
65 }; 65 };
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 // Notes from Init() above applies here as well. 154 // Notes from Init() above applies here as well.
155 void InternalInit(); 155 void InternalInit();
156 156
157 void Stop(); 157 void Stop();
158 void CheckFinish(); 158 void CheckFinish();
159 void SaveNextFile(bool process_all_remainder_items); 159 void SaveNextFile(bool process_all_remainder_items);
160 void DoSavingProcess(); 160 void DoSavingProcess();
161 161
162 // TabContentsObserver implementation. 162 // TabContentsObserver implementation.
163 virtual bool OnMessageReceived(const IPC::Message& message); 163 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
164
165 // DownloadItem::Observer implementation.
166 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE;
167 virtual void OnDownloadOpened(DownloadItem* download) OVERRIDE {}
168
169 // Update the download history of this item upon completion.
170 void FinalizeDownloadEntry();
171
172 // Detach from DownloadManager.
173 void StopObservation();
164 174
165 // Return max length of a path for a specific base directory. 175 // Return max length of a path for a specific base directory.
166 // This is needed on POSIX, which restrict the length of file names in 176 // This is needed on POSIX, which restrict the length of file names in
167 // addition to the restriction on the length of path names. 177 // addition to the restriction on the length of path names.
168 // |base_dir| is assumed to be a directory name with no trailing slash. 178 // |base_dir| is assumed to be a directory name with no trailing slash.
169 static uint32 GetMaxPathLengthForDirectory(const FilePath& base_dir); 179 static uint32 GetMaxPathLengthForDirectory(const FilePath& base_dir);
170 180
171 static bool GetSafePureFileName(const FilePath& dir_path, 181 static bool GetSafePureFileName(const FilePath& dir_path,
172 const FilePath::StringType& file_name_ext, 182 const FilePath::StringType& file_name_ext,
173 uint32 max_file_path_len, 183 uint32 max_file_path_len,
(...skipping 30 matching lines...) Expand all
204 214
205 void OnReceivedSavableResourceLinksForCurrentPage( 215 void OnReceivedSavableResourceLinksForCurrentPage(
206 const std::vector<GURL>& resources_list, 216 const std::vector<GURL>& resources_list,
207 const std::vector<GURL>& referrers_list, 217 const std::vector<GURL>& referrers_list,
208 const std::vector<GURL>& frames_list); 218 const std::vector<GURL>& frames_list);
209 219
210 void OnReceivedSerializedHtmlData(const GURL& frame_url, 220 void OnReceivedSerializedHtmlData(const GURL& frame_url,
211 const std::string& data, 221 const std::string& data,
212 int32 status); 222 int32 status);
213 223
214 // Convenience function.
215 DownloadManager* GetDownloadManager();
216
217
218 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap; 224 typedef base::hash_map<std::string, SaveItem*> SaveUrlItemMap;
219 // in_progress_items_ is map of all saving job in in-progress state. 225 // in_progress_items_ is map of all saving job in in-progress state.
220 SaveUrlItemMap in_progress_items_; 226 SaveUrlItemMap in_progress_items_;
221 // saved_failed_items_ is map of all saving job which are failed. 227 // saved_failed_items_ is map of all saving job which are failed.
222 SaveUrlItemMap saved_failed_items_; 228 SaveUrlItemMap saved_failed_items_;
223 229
224 // The number of in process SaveItems. 230 // The number of in process SaveItems.
225 int in_process_count() const { 231 int in_process_count() const {
226 return static_cast<int>(in_progress_items_.size()); 232 return static_cast<int>(in_progress_items_.size());
227 } 233 }
(...skipping 30 matching lines...) Expand all
258 // A queue for items we are about to start saving. 264 // A queue for items we are about to start saving.
259 SaveItemQueue waiting_item_queue_; 265 SaveItemQueue waiting_item_queue_;
260 266
261 typedef base::hash_map<int32, SaveItem*> SavedItemMap; 267 typedef base::hash_map<int32, SaveItem*> SavedItemMap;
262 // saved_success_items_ is map of all saving job which are successfully saved. 268 // saved_success_items_ is map of all saving job which are successfully saved.
263 SavedItemMap saved_success_items_; 269 SavedItemMap saved_success_items_;
264 270
265 // Non-owning pointer for handling file writing on the file thread. 271 // Non-owning pointer for handling file writing on the file thread.
266 SaveFileManager* file_manager_; 272 SaveFileManager* file_manager_;
267 273
268 // We use a fake DownloadItem here in order to reuse the DownloadItemView. 274 // DownloadManager owns the DownloadItem and handles history and UI.
269 // This class owns the pointer. 275 DownloadManager* download_manager_;
270 DownloadItem* download_; 276 DownloadItem* download_;
271 277
272 // The URL of the page the user wants to save. 278 // The URL of the page the user wants to save.
273 GURL page_url_; 279 GURL page_url_;
274 FilePath saved_main_file_path_; 280 FilePath saved_main_file_path_;
275 FilePath saved_main_directory_path_; 281 FilePath saved_main_directory_path_;
276 282
277 // The title of the page the user wants to save. 283 // The title of the page the user wants to save.
278 string16 title_; 284 string16 title_;
279 285
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 friend class SavePackageTest; 320 friend class SavePackageTest;
315 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); 321 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames);
316 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); 322 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename);
317 323
318 ScopedRunnableMethodFactory<SavePackage> method_factory_; 324 ScopedRunnableMethodFactory<SavePackage> method_factory_;
319 325
320 DISALLOW_COPY_AND_ASSIGN(SavePackage); 326 DISALLOW_COPY_AND_ASSIGN(SavePackage);
321 }; 327 };
322 328
323 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 329 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/save_page_browsertest.cc ('k') | content/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698