| 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 // Objects that handle file operations for saving files, on the file thread. | 5 // Objects that handle file operations for saving files, on the file thread. |
| 6 // | 6 // |
| 7 // The SaveFileManager owns a set of SaveFile objects, each of which connects | 7 // The SaveFileManager owns a set of SaveFile objects, each of which connects |
| 8 // with a SaveItem object which belongs to one SavePackage and runs on the file | 8 // with a SaveItem object which belongs to one SavePackage and runs on the file |
| 9 // thread for saving data in order to avoid disk activity on either network IO | 9 // thread for saving data in order to avoid disk activity on either network IO |
| 10 // thread or the UI thread. It coordinates the notifications from the network | 10 // thread or the UI thread. It coordinates the notifications from the network |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #define CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_ | 59 #define CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_ |
| 60 | 60 |
| 61 #include <string> | 61 #include <string> |
| 62 | 62 |
| 63 #include "base/basictypes.h" | 63 #include "base/basictypes.h" |
| 64 #include "base/hash_tables.h" | 64 #include "base/hash_tables.h" |
| 65 #include "base/memory/ref_counted.h" | 65 #include "base/memory/ref_counted.h" |
| 66 #include "content/browser/download/save_types.h" | 66 #include "content/browser/download/save_types.h" |
| 67 #include "content/common/content_export.h" | 67 #include "content/common/content_export.h" |
| 68 | 68 |
| 69 class FilePath; | |
| 70 class GURL; | 69 class GURL; |
| 71 | 70 |
| 71 namespace base { |
| 72 class FilePath; |
| 73 } |
| 72 | 74 |
| 73 namespace net { | 75 namespace net { |
| 74 class IOBuffer; | 76 class IOBuffer; |
| 75 } | 77 } |
| 76 | 78 |
| 77 namespace content { | 79 namespace content { |
| 78 class ResourceContext; | 80 class ResourceContext; |
| 79 class SaveFile; | 81 class SaveFile; |
| 80 class SavePackage; | 82 class SavePackage; |
| 81 struct Referrer; | 83 struct Referrer; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 // Note that this is different from the SavePackage's id. | 94 // Note that this is different from the SavePackage's id. |
| 93 int GetNextId(); | 95 int GetNextId(); |
| 94 | 96 |
| 95 // Save the specified URL. Called on the UI thread and forwarded to the | 97 // Save the specified URL. Called on the UI thread and forwarded to the |
| 96 // ResourceDispatcherHostImpl on the IO thread. | 98 // ResourceDispatcherHostImpl on the IO thread. |
| 97 void SaveURL(const GURL& url, | 99 void SaveURL(const GURL& url, |
| 98 const Referrer& referrer, | 100 const Referrer& referrer, |
| 99 int render_process_host_id, | 101 int render_process_host_id, |
| 100 int render_view_id, | 102 int render_view_id, |
| 101 SaveFileCreateInfo::SaveFileSource save_source, | 103 SaveFileCreateInfo::SaveFileSource save_source, |
| 102 const FilePath& file_full_path, | 104 const base::FilePath& file_full_path, |
| 103 ResourceContext* context, | 105 ResourceContext* context, |
| 104 SavePackage* save_package); | 106 SavePackage* save_package); |
| 105 | 107 |
| 106 // Notifications sent from the IO thread and run on the file thread: | 108 // Notifications sent from the IO thread and run on the file thread: |
| 107 void StartSave(SaveFileCreateInfo* info); | 109 void StartSave(SaveFileCreateInfo* info); |
| 108 void UpdateSaveProgress(int save_id, net::IOBuffer* data, int size); | 110 void UpdateSaveProgress(int save_id, net::IOBuffer* data, int size); |
| 109 void SaveFinished(int save_id, | 111 void SaveFinished(int save_id, |
| 110 const GURL& save_url, | 112 const GURL& save_url, |
| 111 int render_process_id, | 113 int render_process_id, |
| 112 bool is_success); | 114 bool is_success); |
| 113 | 115 |
| 114 // Notifications sent from the UI thread and run on the file thread. | 116 // Notifications sent from the UI thread and run on the file thread. |
| 115 // Cancel a SaveFile instance which has specified save id. | 117 // Cancel a SaveFile instance which has specified save id. |
| 116 void CancelSave(int save_id); | 118 void CancelSave(int save_id); |
| 117 | 119 |
| 118 // Called on the UI thread to remove a save package from SaveFileManager's | 120 // Called on the UI thread to remove a save package from SaveFileManager's |
| 119 // tracking map. | 121 // tracking map. |
| 120 void RemoveSaveFile(int save_id, const GURL& save_url, | 122 void RemoveSaveFile(int save_id, const GURL& save_url, |
| 121 SavePackage* package); | 123 SavePackage* package); |
| 122 | 124 |
| 123 // Helper function for deleting specified file. | 125 // Helper function for deleting specified file. |
| 124 void DeleteDirectoryOrFile(const FilePath& full_path, bool is_dir); | 126 void DeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir); |
| 125 | 127 |
| 126 // Runs on file thread to save a file by copying from file system when | 128 // Runs on file thread to save a file by copying from file system when |
| 127 // original url is using file scheme. | 129 // original url is using file scheme. |
| 128 void SaveLocalFile(const GURL& original_file_url, | 130 void SaveLocalFile(const GURL& original_file_url, |
| 129 int save_id, | 131 int save_id, |
| 130 int render_process_id); | 132 int render_process_id); |
| 131 | 133 |
| 132 // Renames all the successfully saved files. | 134 // Renames all the successfully saved files. |
| 133 // |final_names| points to a vector which contains pairs of save ids and | 135 // |final_names| points to a vector which contains pairs of save ids and |
| 134 // final names of successfully saved files. | 136 // final names of successfully saved files. |
| 135 void RenameAllFiles( | 137 void RenameAllFiles( |
| 136 const FinalNameList& final_names, | 138 const FinalNameList& final_names, |
| 137 const FilePath& resource_dir, | 139 const base::FilePath& resource_dir, |
| 138 int render_process_id, | 140 int render_process_id, |
| 139 int render_view_id, | 141 int render_view_id, |
| 140 int save_package_id); | 142 int save_package_id); |
| 141 | 143 |
| 142 // When the user cancels the saving, we need to remove all remaining saved | 144 // When the user cancels the saving, we need to remove all remaining saved |
| 143 // files of this page saving job from save_file_map_. | 145 // files of this page saving job from save_file_map_. |
| 144 void RemoveSavedFileFromFileMap(const SaveIDList & save_ids); | 146 void RemoveSavedFileFromFileMap(const SaveIDList & save_ids); |
| 145 | 147 |
| 146 private: | 148 private: |
| 147 friend class base::RefCountedThreadSafe<SaveFileManager>; | 149 friend class base::RefCountedThreadSafe<SaveFileManager>; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // map:(url, SavePackage) to find the request and remove it. | 194 // map:(url, SavePackage) to find the request and remove it. |
| 193 void OnErrorFinished(const GURL& save_url, int contents_id); | 195 void OnErrorFinished(const GURL& save_url, int contents_id); |
| 194 // Notifies SavePackage that the whole page saving job is finished. | 196 // Notifies SavePackage that the whole page saving job is finished. |
| 195 void OnFinishSavePageJob(int render_process_id, | 197 void OnFinishSavePageJob(int render_process_id, |
| 196 int render_view_id, | 198 int render_view_id, |
| 197 int save_package_id); | 199 int save_package_id); |
| 198 | 200 |
| 199 // Notifications sent from the UI thread and run on the file thread. | 201 // Notifications sent from the UI thread and run on the file thread. |
| 200 | 202 |
| 201 // Deletes a specified file on the file thread. | 203 // Deletes a specified file on the file thread. |
| 202 void OnDeleteDirectoryOrFile(const FilePath& full_path, bool is_dir); | 204 void OnDeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir); |
| 203 | 205 |
| 204 // Notifications sent from the UI thread and run on the IO thread | 206 // Notifications sent from the UI thread and run on the IO thread |
| 205 | 207 |
| 206 // Initiates a request for URL to be saved. | 208 // Initiates a request for URL to be saved. |
| 207 void OnSaveURL(const GURL& url, | 209 void OnSaveURL(const GURL& url, |
| 208 const Referrer& referrer, | 210 const Referrer& referrer, |
| 209 int render_process_host_id, | 211 int render_process_host_id, |
| 210 int render_view_id, | 212 int render_view_id, |
| 211 ResourceContext* context); | 213 ResourceContext* context); |
| 212 // Handler for a notification sent to the IO thread for generating save id. | 214 // Handler for a notification sent to the IO thread for generating save id. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 241 typedef base::hash_map<int, StartingRequestsMap> | 243 typedef base::hash_map<int, StartingRequestsMap> |
| 242 ContentsToStartingRequestsMap; | 244 ContentsToStartingRequestsMap; |
| 243 ContentsToStartingRequestsMap contents_starting_requests_; | 245 ContentsToStartingRequestsMap contents_starting_requests_; |
| 244 | 246 |
| 245 DISALLOW_COPY_AND_ASSIGN(SaveFileManager); | 247 DISALLOW_COPY_AND_ASSIGN(SaveFileManager); |
| 246 }; | 248 }; |
| 247 | 249 |
| 248 } // namespace content | 250 } // namespace content |
| 249 | 251 |
| 250 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_ | 252 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_ |
| OLD | NEW |