OLD | NEW |
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 Loading... |
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 // Notes from Init() above applies here as well. | 157 // Notes from Init() above applies here as well. |
158 void InternalInit(); | 158 void InternalInit(); |
159 | 159 |
160 void Stop(); | 160 void Stop(); |
161 void CheckFinish(); | 161 void CheckFinish(); |
162 void SaveNextFile(bool process_all_remainder_items); | 162 void SaveNextFile(bool process_all_remainder_items); |
163 void DoSavingProcess(); | 163 void DoSavingProcess(); |
164 | 164 |
165 // TabContentsObserver implementation. | 165 // TabContentsObserver implementation. |
166 virtual bool OnMessageReceived(const IPC::Message& message); | 166 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 167 |
| 168 // DownloadItem::Observer implementation. |
| 169 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE; |
| 170 virtual void OnDownloadOpened(DownloadItem* download) OVERRIDE {} |
| 171 |
| 172 // Update the download history of this item upon completion. |
| 173 void FinalizeDownloadEntry(); |
| 174 |
| 175 // Detach from DownloadManager. |
| 176 void StopObservation(); |
167 | 177 |
168 // Return max length of a path for a specific base directory. | 178 // Return max length of a path for a specific base directory. |
169 // This is needed on POSIX, which restrict the length of file names in | 179 // This is needed on POSIX, which restrict the length of file names in |
170 // addition to the restriction on the length of path names. | 180 // addition to the restriction on the length of path names. |
171 // |base_dir| is assumed to be a directory name with no trailing slash. | 181 // |base_dir| is assumed to be a directory name with no trailing slash. |
172 static uint32 GetMaxPathLengthForDirectory(const FilePath& base_dir); | 182 static uint32 GetMaxPathLengthForDirectory(const FilePath& base_dir); |
173 | 183 |
174 static bool GetSafePureFileName(const FilePath& dir_path, | 184 static bool GetSafePureFileName(const FilePath& dir_path, |
175 const FilePath::StringType& file_name_ext, | 185 const FilePath::StringType& file_name_ext, |
176 uint32 max_file_path_len, | 186 uint32 max_file_path_len, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // A queue for items we are about to start saving. | 269 // A queue for items we are about to start saving. |
260 SaveItemQueue waiting_item_queue_; | 270 SaveItemQueue waiting_item_queue_; |
261 | 271 |
262 typedef base::hash_map<int32, SaveItem*> SavedItemMap; | 272 typedef base::hash_map<int32, SaveItem*> SavedItemMap; |
263 // saved_success_items_ is map of all saving job which are successfully saved. | 273 // saved_success_items_ is map of all saving job which are successfully saved. |
264 SavedItemMap saved_success_items_; | 274 SavedItemMap saved_success_items_; |
265 | 275 |
266 // Non-owning pointer for handling file writing on the file thread. | 276 // Non-owning pointer for handling file writing on the file thread. |
267 SaveFileManager* file_manager_; | 277 SaveFileManager* file_manager_; |
268 | 278 |
269 // We use a fake DownloadItem here in order to reuse the DownloadItemView. | 279 // DownloadManager owns the DownloadItem and handles history and UI. |
270 // This class owns the pointer. | 280 DownloadManager* download_manager_; |
271 DownloadItem* download_; | 281 DownloadItem* download_; |
272 | 282 |
273 // The URL of the page the user wants to save. | 283 // The URL of the page the user wants to save. |
274 GURL page_url_; | 284 GURL page_url_; |
275 FilePath saved_main_file_path_; | 285 FilePath saved_main_file_path_; |
276 FilePath saved_main_directory_path_; | 286 FilePath saved_main_directory_path_; |
277 | 287 |
278 // The title of the page the user wants to save. | 288 // The title of the page the user wants to save. |
279 string16 title_; | 289 string16 title_; |
280 | 290 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 friend class SavePackageTest; | 325 friend class SavePackageTest; |
316 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 326 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
317 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 327 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
318 | 328 |
319 ScopedRunnableMethodFactory<SavePackage> method_factory_; | 329 ScopedRunnableMethodFactory<SavePackage> method_factory_; |
320 | 330 |
321 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 331 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
322 }; | 332 }; |
323 | 333 |
324 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 334 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
OLD | NEW |