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

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

Issue 1529363006: Introducing SavePackageId and SaveItemId as distinct IdType<...>-based types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback from Daniel. Created 4 years, 11 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
« no previous file with comments | « content/browser/download/save_file.h ('k') | content/browser/download/save_file_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 class SaveFileManager : public base::RefCountedThreadSafe<SaveFileManager> { 86 class SaveFileManager : public base::RefCountedThreadSafe<SaveFileManager> {
87 public: 87 public:
88 SaveFileManager(); 88 SaveFileManager();
89 89
90 // Lifetime management. 90 // Lifetime management.
91 CONTENT_EXPORT void Shutdown(); 91 CONTENT_EXPORT void Shutdown();
92 92
93 // Save the specified URL. Called on the UI thread and forwarded to the 93 // Save the specified URL. Called on the UI thread and forwarded to the
94 // ResourceDispatcherHostImpl on the IO thread. 94 // ResourceDispatcherHostImpl on the IO thread.
95 void SaveURL(int save_item_id, 95 void SaveURL(SaveItemId save_item_id,
96 const GURL& url, 96 const GURL& url,
97 const Referrer& referrer, 97 const Referrer& referrer,
98 int render_process_host_id, 98 int render_process_host_id,
99 int render_view_routing_id, 99 int render_view_routing_id,
100 int render_frame_routing_id, 100 int render_frame_routing_id,
101 SaveFileCreateInfo::SaveFileSource save_source, 101 SaveFileCreateInfo::SaveFileSource save_source,
102 const base::FilePath& file_full_path, 102 const base::FilePath& file_full_path,
103 ResourceContext* context, 103 ResourceContext* context,
104 SavePackage* save_package); 104 SavePackage* save_package);
105 105
106 // Notifications sent from the IO thread and run on the file thread: 106 // Notifications sent from the IO thread and run on the file thread:
107 void StartSave(SaveFileCreateInfo* info); 107 void StartSave(SaveFileCreateInfo* info);
108 void UpdateSaveProgress(int save_item_id, net::IOBuffer* data, int size); 108 void UpdateSaveProgress(SaveItemId save_item_id,
109 void SaveFinished(int save_item_id, int save_package_id, bool is_success); 109 net::IOBuffer* data,
110 int size);
111 void SaveFinished(SaveItemId save_item_id,
112 SavePackageId save_package_id,
113 bool is_success);
110 114
111 // Notifications sent from the UI thread and run on the file thread. 115 // Notifications sent from the UI thread and run on the file thread.
112 // Cancel a SaveFile instance which has specified save item id. 116 // Cancel a SaveFile instance which has specified save item id.
113 void CancelSave(int save_item_id); 117 void CancelSave(SaveItemId save_item_id);
114 118
115 // Called on the UI thread to remove a save package from SaveFileManager's 119 // Called on the UI thread to remove a save package from SaveFileManager's
116 // tracking map. 120 // tracking map.
117 void RemoveSaveFile(int save_item_id, SavePackage* package); 121 void RemoveSaveFile(SaveItemId save_item_id, SavePackage* package);
118 122
119 // Helper function for deleting specified file. 123 // Helper function for deleting specified file.
120 void DeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir); 124 void DeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir);
121 125
122 // Runs on file thread to save a file by copying from file system when 126 // Runs on file thread to save a file by copying from file system when
123 // original url is using file scheme. 127 // original url is using file scheme.
124 void SaveLocalFile(const GURL& original_file_url, 128 void SaveLocalFile(const GURL& original_file_url,
125 int save_item_id, 129 SaveItemId save_item_id,
126 int save_package_id); 130 SavePackageId save_package_id);
127 131
128 // Renames all the successfully saved files. 132 // Renames all the successfully saved files.
129 void RenameAllFiles(const FinalNamesMap& final_names, 133 void RenameAllFiles(const FinalNamesMap& final_names,
130 const base::FilePath& resource_dir, 134 const base::FilePath& resource_dir,
131 int render_process_id, 135 int render_process_id,
132 int render_frame_routing_id, 136 int render_frame_routing_id,
133 int save_package_id); 137 SavePackageId save_package_id);
134 138
135 // When the user cancels the saving, we need to remove all remaining saved 139 // When the user cancels the saving, we need to remove all remaining saved
136 // files of this page saving job from save_file_map_. 140 // files of this page saving job from save_file_map_.
137 void RemoveSavedFileFromFileMap(const std::vector<int>& save_item_ids); 141 void RemoveSavedFileFromFileMap(const std::vector<SaveItemId>& save_item_ids);
138 142
139 private: 143 private:
140 friend class base::RefCountedThreadSafe<SaveFileManager>; 144 friend class base::RefCountedThreadSafe<SaveFileManager>;
141 145
142 ~SaveFileManager(); 146 ~SaveFileManager();
143 147
144 // A cleanup helper that runs on the file thread. 148 // A cleanup helper that runs on the file thread.
145 void OnShutdown(); 149 void OnShutdown();
146 150
147 // Called only on UI thread to get the SavePackage for a contents's browser 151 // Called only on UI thread to get the SavePackage for a contents's browser
148 // context. 152 // context.
149 static SavePackage* GetSavePackageFromRenderIds(int render_process_id, 153 static SavePackage* GetSavePackageFromRenderIds(int render_process_id,
150 int render_frame_routing_id); 154 int render_frame_routing_id);
151 155
152 // Look up the SavePackage according to save item id. 156 // Look up the SavePackage according to save item id.
153 SavePackage* LookupPackage(int save_item_id); 157 SavePackage* LookupPackage(SaveItemId save_item_id);
154 158
155 // Called only on the file thread. 159 // Called only on the file thread.
156 // Look up one in-progress saving item according to save item id. 160 // Look up one in-progress saving item according to save item id.
157 SaveFile* LookupSaveFile(int save_item_id); 161 SaveFile* LookupSaveFile(SaveItemId save_item_id);
158 162
159 // Help function for sending notification of canceling specific request. 163 // Help function for sending notification of canceling specific request.
160 void SendCancelRequest(int save_item_id); 164 void SendCancelRequest(SaveItemId save_item_id);
161 165
162 // Notifications sent from the file thread and run on the UI thread. 166 // Notifications sent from the file thread and run on the UI thread.
163 167
164 // Lookup the SaveManager for this WebContents' saving browser context and 168 // Lookup the SaveManager for this WebContents' saving browser context and
165 // inform it the saving job has been started. 169 // inform it the saving job has been started.
166 void OnStartSave(const SaveFileCreateInfo& info); 170 void OnStartSave(const SaveFileCreateInfo& info);
167 // Update the SavePackage with the current state of a started saving job. 171 // Update the SavePackage with the current state of a started saving job.
168 // If the SavePackage for this saving job is gone, cancel the request. 172 // If the SavePackage for this saving job is gone, cancel the request.
169 void OnUpdateSaveProgress(int save_item_id, 173 void OnUpdateSaveProgress(SaveItemId save_item_id,
170 int64_t bytes_so_far, 174 int64_t bytes_so_far,
171 bool write_success); 175 bool write_success);
172 // Update the SavePackage with the finish state, and remove the request 176 // Update the SavePackage with the finish state, and remove the request
173 // tracking entries. 177 // tracking entries.
174 void OnSaveFinished(int save_item_id, int64_t bytes_so_far, bool is_success); 178 void OnSaveFinished(SaveItemId save_item_id,
179 int64_t bytes_so_far,
180 bool is_success);
175 // Notifies SavePackage that the whole page saving job is finished. 181 // Notifies SavePackage that the whole page saving job is finished.
176 void OnFinishSavePageJob(int render_process_id, 182 void OnFinishSavePageJob(int render_process_id,
177 int render_frame_routing_id, 183 int render_frame_routing_id,
178 int save_package_id); 184 SavePackageId save_package_id);
179 185
180 // Notifications sent from the UI thread and run on the file thread. 186 // Notifications sent from the UI thread and run on the file thread.
181 187
182 // Deletes a specified file on the file thread. 188 // Deletes a specified file on the file thread.
183 void OnDeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir); 189 void OnDeleteDirectoryOrFile(const base::FilePath& full_path, bool is_dir);
184 190
185 // Notifications sent from the UI thread and run on the IO thread 191 // Notifications sent from the UI thread and run on the IO thread
186 192
187 // Initiates a request for URL to be saved. 193 // Initiates a request for URL to be saved.
188 void OnSaveURL(const GURL& url, 194 void OnSaveURL(const GURL& url,
189 const Referrer& referrer, 195 const Referrer& referrer,
190 int save_item_id, 196 SaveItemId save_item_id,
191 int save_package_id, 197 SavePackageId save_package_id,
192 int render_process_host_id, 198 int render_process_host_id,
193 int render_view_routing_id, 199 int render_view_routing_id,
194 int render_frame_routing_id, 200 int render_frame_routing_id,
195 ResourceContext* context); 201 ResourceContext* context);
196 // Call ResourceDispatcherHostImpl's CancelRequest method to execute cancel 202 // Call ResourceDispatcherHostImpl's CancelRequest method to execute cancel
197 // action in the IO thread. 203 // action in the IO thread.
198 void ExecuteCancelSaveRequest(int render_process_id, int request_id); 204 void ExecuteCancelSaveRequest(int render_process_id, int request_id);
199 205
200 // A map from save_item_id into SaveFiles. 206 // A map from save_item_id into SaveFiles.
201 typedef base::hash_map<int, SaveFile*> SaveFileMap; 207 typedef base::hash_map<SaveItemId, SaveFile*> SaveFileMap;
202 SaveFileMap save_file_map_; 208 SaveFileMap save_file_map_;
203 209
204 // Tracks which SavePackage to send data to, called only on UI thread. 210 // Tracks which SavePackage to send data to, called only on UI thread.
205 // SavePackageMap maps save item ids to their SavePackage. 211 // SavePackageMap maps save item ids to their SavePackage.
206 typedef base::hash_map<int, SavePackage*> SavePackageMap; 212 typedef base::hash_map<SaveItemId, SavePackage*> SavePackageMap;
207 SavePackageMap packages_; 213 SavePackageMap packages_;
208 214
209 DISALLOW_COPY_AND_ASSIGN(SaveFileManager); 215 DISALLOW_COPY_AND_ASSIGN(SaveFileManager);
210 }; 216 };
211 217
212 } // namespace content 218 } // namespace content
213 219
214 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_ 220 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/download/save_file.h ('k') | content/browser/download/save_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698