| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // complete-html and providing the information for displaying saving status. | 38 // complete-html and providing the information for displaying saving status. |
| 39 // Saving page as only-html means means that we save web page to a single HTML | 39 // Saving page as only-html means means that we save web page to a single HTML |
| 40 // file regardless internal sub resources and sub frames. | 40 // file regardless internal sub resources and sub frames. |
| 41 // Saving page as complete-html page means we save not only the main html file | 41 // Saving page as complete-html page means we save not only the main html file |
| 42 // the user told it to save but also a directory for the auxiliary files such | 42 // the user told it to save but also a directory for the auxiliary files such |
| 43 // as all sub-frame html files, image files, css files and js files. | 43 // as all sub-frame html files, image files, css files and js files. |
| 44 // | 44 // |
| 45 // Each page saving job may include one or multiple files which need to be | 45 // Each page saving job may include one or multiple files which need to be |
| 46 // saved. Each file is represented by a SaveItem, and all SaveItems are owned | 46 // saved. Each file is represented by a SaveItem, and all SaveItems are owned |
| 47 // by the SavePackage. SaveItems are created when a user initiates a page | 47 // by the SavePackage. SaveItems are created when a user initiates a page |
| 48 // saving job, and exist for the duration of one tab's life time. | 48 // saving job, and exist for the duration of one contents's life time. |
| 49 class CONTENT_EXPORT SavePackage | 49 class CONTENT_EXPORT SavePackage |
| 50 : public base::RefCountedThreadSafe<SavePackage>, | 50 : public base::RefCountedThreadSafe<SavePackage>, |
| 51 public content::WebContentsObserver, | 51 public content::WebContentsObserver, |
| 52 public content::DownloadItem::Observer, | 52 public content::DownloadItem::Observer, |
| 53 public base::SupportsWeakPtr<SavePackage> { | 53 public base::SupportsWeakPtr<SavePackage> { |
| 54 public: | 54 public: |
| 55 enum WaitState { | 55 enum WaitState { |
| 56 // State when created but not initialized. | 56 // State when created but not initialized. |
| 57 INITIALIZE = 0, | 57 INITIALIZE = 0, |
| 58 // State when after initializing, but not yet saving. | 58 // State when after initializing, but not yet saving. |
| 59 START_PROCESS, | 59 START_PROCESS, |
| 60 // Waiting on a list of savable resources from the backend. | 60 // Waiting on a list of savable resources from the backend. |
| 61 RESOURCES_LIST, | 61 RESOURCES_LIST, |
| 62 // Waiting for data sent from net IO or from file system. | 62 // Waiting for data sent from net IO or from file system. |
| 63 NET_FILES, | 63 NET_FILES, |
| 64 // Waiting for html DOM data sent from render process. | 64 // Waiting for html DOM data sent from render process. |
| 65 HTML_DATA, | 65 HTML_DATA, |
| 66 // Saving page finished successfully. | 66 // Saving page finished successfully. |
| 67 SUCCESSFUL, | 67 SUCCESSFUL, |
| 68 // Failed to save page. | 68 // Failed to save page. |
| 69 FAILED | 69 FAILED |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static const FilePath::CharType kDefaultHtmlExtension[]; | 72 static const FilePath::CharType kDefaultHtmlExtension[]; |
| 73 | 73 |
| 74 // Constructor for user initiated page saving. This constructor results in a | 74 // Constructor for user initiated page saving. This constructor results in a |
| 75 // SavePackage that will generate and sanitize a suggested name for the user | 75 // SavePackage that will generate and sanitize a suggested name for the user |
| 76 // in the "Save As" dialog box. | 76 // in the "Save As" dialog box. |
| 77 explicit SavePackage(content::WebContents* tab_contents); | 77 explicit SavePackage(content::WebContents* web_contents); |
| 78 | 78 |
| 79 // This contructor is used only for testing. We can bypass the file and | 79 // This contructor is used only for testing. We can bypass the file and |
| 80 // directory name generation / sanitization by providing well known paths | 80 // directory name generation / sanitization by providing well known paths |
| 81 // better suited for tests. | 81 // better suited for tests. |
| 82 SavePackage(content::WebContents* web_contents, | 82 SavePackage(content::WebContents* web_contents, |
| 83 content::SavePageType save_type, | 83 content::SavePageType save_type, |
| 84 const FilePath& file_full_path, | 84 const FilePath& file_full_path, |
| 85 const FilePath& directory_full_path); | 85 const FilePath& directory_full_path); |
| 86 | 86 |
| 87 // Initialize the SavePackage. Returns true if it initializes properly. | 87 // Initialize the SavePackage. Returns true if it initializes properly. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 102 void SaveFailed(const GURL& save_url); | 102 void SaveFailed(const GURL& save_url); |
| 103 void SaveCanceled(SaveItem* save_item); | 103 void SaveCanceled(SaveItem* save_item); |
| 104 | 104 |
| 105 // Rough percent complete, -1 means we don't know (since we didn't receive a | 105 // Rough percent complete, -1 means we don't know (since we didn't receive a |
| 106 // total size). | 106 // total size). |
| 107 int PercentComplete(); | 107 int PercentComplete(); |
| 108 | 108 |
| 109 bool canceled() const { return user_canceled_ || disk_error_occurred_; } | 109 bool canceled() const { return user_canceled_ || disk_error_occurred_; } |
| 110 bool finished() const { return finished_; } | 110 bool finished() const { return finished_; } |
| 111 content::SavePageType save_type() const { return save_type_; } | 111 content::SavePageType save_type() const { return save_type_; } |
| 112 int tab_id() const { return tab_id_; } | 112 int contents_id() const { return contents_id_; } |
| 113 int id() const { return unique_id_; } | 113 int id() const { return unique_id_; } |
| 114 content::WebContents* web_contents() const; | 114 content::WebContents* web_contents() const; |
| 115 | 115 |
| 116 void GetSaveInfo(); | 116 void GetSaveInfo(); |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 friend class base::RefCountedThreadSafe<SavePackage>; | 119 friend class base::RefCountedThreadSafe<SavePackage>; |
| 120 | 120 |
| 121 // For testing only. | 121 // For testing only. |
| 122 SavePackage(content::WebContents* web_contents, | 122 SavePackage(content::WebContents* web_contents, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 FileNameSet file_name_set_; | 287 FileNameSet file_name_set_; |
| 288 | 288 |
| 289 typedef base::hash_map<FilePath::StringType, uint32> FileNameCountMap; | 289 typedef base::hash_map<FilePath::StringType, uint32> FileNameCountMap; |
| 290 // This map is used to track serial number for specified filename. | 290 // This map is used to track serial number for specified filename. |
| 291 FileNameCountMap file_name_count_map_; | 291 FileNameCountMap file_name_count_map_; |
| 292 | 292 |
| 293 // Indicates current waiting state when SavePackage try to get something | 293 // Indicates current waiting state when SavePackage try to get something |
| 294 // from outside. | 294 // from outside. |
| 295 WaitState wait_state_; | 295 WaitState wait_state_; |
| 296 | 296 |
| 297 // Since for one tab, it can only have one SavePackage in same time. | 297 // Since for one contents, it can only have one SavePackage in same time. |
| 298 // Now we actually use render_process_id as tab's unique id. | 298 // Now we actually use render_process_id as the contents's unique id. |
| 299 const int tab_id_; | 299 const int contents_id_; |
| 300 | 300 |
| 301 // Unique ID for this SavePackage. | 301 // Unique ID for this SavePackage. |
| 302 const int unique_id_; | 302 const int unique_id_; |
| 303 | 303 |
| 304 // Variables to record errors that happened so we can record them via | 304 // Variables to record errors that happened so we can record them via |
| 305 // UMA statistics. | 305 // UMA statistics. |
| 306 bool wrote_to_completed_file_; | 306 bool wrote_to_completed_file_; |
| 307 bool wrote_to_failed_file_; | 307 bool wrote_to_failed_file_; |
| 308 | 308 |
| 309 friend class SavePackageTest; | 309 friend class SavePackageTest; |
| 310 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 310 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
| 311 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 311 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
| 312 | 312 |
| 313 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 313 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
| 314 }; | 314 }; |
| 315 | 315 |
| 316 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 316 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
| OLD | NEW |