| 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 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "content/browser/download/save_file_manager.h" | 7 #include "content/browser/download/save_file_manager.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 BrowserThread::FILE, FROM_HERE, | 39 BrowserThread::FILE, FROM_HERE, |
| 40 base::Bind(&SaveFileManager::OnShutdown, this)); | 40 base::Bind(&SaveFileManager::OnShutdown, this)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Stop file thread operations. | 43 // Stop file thread operations. |
| 44 void SaveFileManager::OnShutdown() { | 44 void SaveFileManager::OnShutdown() { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 45 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 46 STLDeleteValues(&save_file_map_); | 46 STLDeleteValues(&save_file_map_); |
| 47 } | 47 } |
| 48 | 48 |
| 49 SaveFile* SaveFileManager::LookupSaveFile(int save_item_id) { | 49 SaveFile* SaveFileManager::LookupSaveFile(SaveItemId save_item_id) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 50 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 51 SaveFileMap::iterator it = save_file_map_.find(save_item_id); | 51 SaveFileMap::iterator it = save_file_map_.find(save_item_id); |
| 52 return it == save_file_map_.end() ? NULL : it->second; | 52 return it == save_file_map_.end() ? nullptr : it->second; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Look up a SavePackage according to a save id. | 55 // Look up a SavePackage according to a save id. |
| 56 SavePackage* SaveFileManager::LookupPackage(int save_item_id) { | 56 SavePackage* SaveFileManager::LookupPackage(SaveItemId save_item_id) { |
| 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 58 SavePackageMap::iterator it = packages_.find(save_item_id); | 58 SavePackageMap::iterator it = packages_.find(save_item_id); |
| 59 if (it != packages_.end()) | 59 if (it != packages_.end()) |
| 60 return it->second; | 60 return it->second; |
| 61 return NULL; | 61 return nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Call from SavePackage for starting a saving job | 64 // Call from SavePackage for starting a saving job |
| 65 void SaveFileManager::SaveURL(int save_item_id, | 65 void SaveFileManager::SaveURL(SaveItemId save_item_id, |
| 66 const GURL& url, | 66 const GURL& url, |
| 67 const Referrer& referrer, | 67 const Referrer& referrer, |
| 68 int render_process_host_id, | 68 int render_process_host_id, |
| 69 int render_view_routing_id, | 69 int render_view_routing_id, |
| 70 int render_frame_routing_id, | 70 int render_frame_routing_id, |
| 71 SaveFileCreateInfo::SaveFileSource save_source, | 71 SaveFileCreateInfo::SaveFileSource save_source, |
| 72 const base::FilePath& file_full_path, | 72 const base::FilePath& file_full_path, |
| 73 ResourceContext* context, | 73 ResourceContext* context, |
| 74 SavePackage* save_package) { | 74 SavePackage* save_package) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 // this kind of save job by ourself. | 93 // this kind of save job by ourself. |
| 94 BrowserThread::PostTask( | 94 BrowserThread::PostTask( |
| 95 BrowserThread::FILE, FROM_HERE, | 95 BrowserThread::FILE, FROM_HERE, |
| 96 base::Bind(&SaveFileManager::StartSave, this, info)); | 96 base::Bind(&SaveFileManager::StartSave, this, info)); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Utility function for look up table maintenance, called on the UI thread. | 100 // Utility function for look up table maintenance, called on the UI thread. |
| 101 // A manager may have multiple save page job (SavePackage) in progress, | 101 // A manager may have multiple save page job (SavePackage) in progress, |
| 102 // so we just look up the save id and remove it from the tracking table. | 102 // so we just look up the save id and remove it from the tracking table. |
| 103 void SaveFileManager::RemoveSaveFile(int save_item_id, | 103 void SaveFileManager::RemoveSaveFile(SaveItemId save_item_id, |
| 104 SavePackage* save_package) { | 104 SavePackage* save_package) { |
| 105 DCHECK(save_package); | 105 DCHECK(save_package); |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 107 // A save page job (SavePackage) can only have one manager, | 107 // A save page job (SavePackage) can only have one manager, |
| 108 // so remove it if it exists. | 108 // so remove it if it exists. |
| 109 SavePackageMap::iterator it = packages_.find(save_item_id); | 109 SavePackageMap::iterator it = packages_.find(save_item_id); |
| 110 if (it != packages_.end()) | 110 if (it != packages_.end()) |
| 111 packages_.erase(it); | 111 packages_.erase(it); |
| 112 } | 112 } |
| 113 | 113 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 131 | 131 |
| 132 void SaveFileManager::DeleteDirectoryOrFile(const base::FilePath& full_path, | 132 void SaveFileManager::DeleteDirectoryOrFile(const base::FilePath& full_path, |
| 133 bool is_dir) { | 133 bool is_dir) { |
| 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 135 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 136 BrowserThread::FILE, FROM_HERE, | 136 BrowserThread::FILE, FROM_HERE, |
| 137 base::Bind(&SaveFileManager::OnDeleteDirectoryOrFile, | 137 base::Bind(&SaveFileManager::OnDeleteDirectoryOrFile, |
| 138 this, full_path, is_dir)); | 138 this, full_path, is_dir)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void SaveFileManager::SendCancelRequest(int save_item_id) { | 141 void SaveFileManager::SendCancelRequest(SaveItemId save_item_id) { |
| 142 // Cancel the request which has specific save id. | 142 // Cancel the request which has specific save id. |
| 143 DCHECK_GT(save_item_id, -1); | 143 DCHECK(save_item_id.is_valid()); |
| 144 BrowserThread::PostTask( | 144 BrowserThread::PostTask( |
| 145 BrowserThread::FILE, FROM_HERE, | 145 BrowserThread::FILE, FROM_HERE, |
| 146 base::Bind(&SaveFileManager::CancelSave, this, save_item_id)); | 146 base::Bind(&SaveFileManager::CancelSave, this, save_item_id)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Notifications sent from the IO thread and run on the file thread: | 149 // Notifications sent from the IO thread and run on the file thread: |
| 150 | 150 |
| 151 // The IO thread created |info|, but the file thread (this method) uses it | 151 // The IO thread created |info|, but the file thread (this method) uses it |
| 152 // to create a SaveFile which will hold and finally destroy |info|. It will | 152 // to create a SaveFile which will hold and finally destroy |info|. It will |
| 153 // then passes |info| to the UI thread for reporting saving status. | 153 // then passes |info| to the UI thread for reporting saving status. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 166 | 166 |
| 167 BrowserThread::PostTask( | 167 BrowserThread::PostTask( |
| 168 BrowserThread::UI, FROM_HERE, | 168 BrowserThread::UI, FROM_HERE, |
| 169 base::Bind(&SaveFileManager::OnStartSave, this, *info)); | 169 base::Bind(&SaveFileManager::OnStartSave, this, *info)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // We do forward an update to the UI thread here, since we do not use timer to | 172 // We do forward an update to the UI thread here, since we do not use timer to |
| 173 // update the UI. If the user has canceled the saving action (in the UI | 173 // update the UI. If the user has canceled the saving action (in the UI |
| 174 // thread). We may receive a few more updates before the IO thread gets the | 174 // thread). We may receive a few more updates before the IO thread gets the |
| 175 // cancel message. We just delete the data since the SaveFile has been deleted. | 175 // cancel message. We just delete the data since the SaveFile has been deleted. |
| 176 void SaveFileManager::UpdateSaveProgress(int save_item_id, | 176 void SaveFileManager::UpdateSaveProgress(SaveItemId save_item_id, |
| 177 net::IOBuffer* data, | 177 net::IOBuffer* data, |
| 178 int data_len) { | 178 int data_len) { |
| 179 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 179 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 180 SaveFile* save_file = LookupSaveFile(save_item_id); | 180 SaveFile* save_file = LookupSaveFile(save_item_id); |
| 181 if (save_file) { | 181 if (save_file) { |
| 182 DCHECK(save_file->InProgress()); | 182 DCHECK(save_file->InProgress()); |
| 183 | 183 |
| 184 DownloadInterruptReason reason = | 184 DownloadInterruptReason reason = |
| 185 save_file->AppendDataToFile(data->data(), data_len); | 185 save_file->AppendDataToFile(data->data(), data_len); |
| 186 BrowserThread::PostTask( | 186 BrowserThread::PostTask( |
| 187 BrowserThread::UI, FROM_HERE, | 187 BrowserThread::UI, FROM_HERE, |
| 188 base::Bind(&SaveFileManager::OnUpdateSaveProgress, this, | 188 base::Bind(&SaveFileManager::OnUpdateSaveProgress, this, |
| 189 save_file->save_item_id(), save_file->BytesSoFar(), | 189 save_file->save_item_id(), save_file->BytesSoFar(), |
| 190 reason == DOWNLOAD_INTERRUPT_REASON_NONE)); | 190 reason == DOWNLOAD_INTERRUPT_REASON_NONE)); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 // The IO thread will call this when saving is completed or it got error when | 194 // The IO thread will call this when saving is completed or it got error when |
| 195 // fetching data. We forward the message to OnSaveFinished in UI thread. | 195 // fetching data. We forward the message to OnSaveFinished in UI thread. |
| 196 void SaveFileManager::SaveFinished(int save_item_id, | 196 void SaveFileManager::SaveFinished(SaveItemId save_item_id, |
| 197 int save_package_id, | 197 SavePackageId save_package_id, |
| 198 bool is_success) { | 198 bool is_success) { |
| 199 DVLOG(20) << " " << __FUNCTION__ << "()" | 199 DVLOG(20) << " " << __FUNCTION__ << "()" |
| 200 << " save_item_id = " << save_item_id | 200 << " save_item_id = " << save_item_id |
| 201 << " save_package_id = " << save_package_id | 201 << " save_package_id = " << save_package_id |
| 202 << " is_success = " << is_success; | 202 << " is_success = " << is_success; |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 203 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 204 SaveFileMap::iterator it = save_file_map_.find(save_item_id); | 204 SaveFile* save_file = LookupSaveFile(save_item_id); |
| 205 if (it != save_file_map_.end()) { | 205 if (save_file != nullptr) { |
| 206 SaveFile* save_file = it->second; | |
| 207 DCHECK(save_file->InProgress()); | 206 DCHECK(save_file->InProgress()); |
| 208 | |
| 209 DVLOG(20) << " " << __FUNCTION__ << "()" | 207 DVLOG(20) << " " << __FUNCTION__ << "()" |
| 210 << " save_file = " << save_file->DebugString(); | 208 << " save_file = " << save_file->DebugString(); |
| 211 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
| 212 BrowserThread::UI, FROM_HERE, | 210 BrowserThread::UI, FROM_HERE, |
| 213 base::Bind(&SaveFileManager::OnSaveFinished, this, save_item_id, | 211 base::Bind(&SaveFileManager::OnSaveFinished, this, save_item_id, |
| 214 save_file->BytesSoFar(), is_success)); | 212 save_file->BytesSoFar(), is_success)); |
| 215 | 213 |
| 216 save_file->Finish(); | 214 save_file->Finish(); |
| 217 save_file->Detach(); | 215 save_file->Detach(); |
| 218 } | 216 } |
| 219 } | 217 } |
| 220 | 218 |
| 221 // Notifications sent from the file thread and run on the UI thread. | 219 // Notifications sent from the file thread and run on the UI thread. |
| 222 | 220 |
| 223 void SaveFileManager::OnStartSave(const SaveFileCreateInfo& info) { | 221 void SaveFileManager::OnStartSave(const SaveFileCreateInfo& info) { |
| 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 225 SavePackage* save_package = GetSavePackageFromRenderIds( | 223 SavePackage* save_package = GetSavePackageFromRenderIds( |
| 226 info.render_process_id, info.render_frame_routing_id); | 224 info.render_process_id, info.render_frame_routing_id); |
| 227 if (!save_package) { | 225 if (!save_package) { |
| 228 // Cancel this request. | 226 // Cancel this request. |
| 229 SendCancelRequest(info.save_item_id); | 227 SendCancelRequest(info.save_item_id); |
| 230 return; | 228 return; |
| 231 } | 229 } |
| 232 | 230 |
| 233 // Insert started saving job to tracking list. | 231 // Insert started saving job to tracking list. |
| 234 SavePackageMap::iterator sit = packages_.find(info.save_item_id); | 232 DCHECK(packages_.find(info.save_item_id) == packages_.end()); |
| 235 DCHECK(sit == packages_.end()); | |
| 236 packages_[info.save_item_id] = save_package; | 233 packages_[info.save_item_id] = save_package; |
| 237 | 234 |
| 238 // Forward this message to SavePackage. | 235 // Forward this message to SavePackage. |
| 239 save_package->StartSave(&info); | 236 save_package->StartSave(&info); |
| 240 } | 237 } |
| 241 | 238 |
| 242 void SaveFileManager::OnUpdateSaveProgress(int save_item_id, | 239 void SaveFileManager::OnUpdateSaveProgress(SaveItemId save_item_id, |
| 243 int64_t bytes_so_far, | 240 int64_t bytes_so_far, |
| 244 bool write_success) { | 241 bool write_success) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 242 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 246 SavePackage* package = LookupPackage(save_item_id); | 243 SavePackage* package = LookupPackage(save_item_id); |
| 247 if (package) | 244 if (package) |
| 248 package->UpdateSaveProgress(save_item_id, bytes_so_far, write_success); | 245 package->UpdateSaveProgress(save_item_id, bytes_so_far, write_success); |
| 249 else | 246 else |
| 250 SendCancelRequest(save_item_id); | 247 SendCancelRequest(save_item_id); |
| 251 } | 248 } |
| 252 | 249 |
| 253 void SaveFileManager::OnSaveFinished(int save_item_id, | 250 void SaveFileManager::OnSaveFinished(SaveItemId save_item_id, |
| 254 int64_t bytes_so_far, | 251 int64_t bytes_so_far, |
| 255 bool is_success) { | 252 bool is_success) { |
| 256 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 257 SavePackage* package = LookupPackage(save_item_id); | 254 SavePackage* package = LookupPackage(save_item_id); |
| 258 if (package) | 255 if (package) |
| 259 package->SaveFinished(save_item_id, bytes_so_far, is_success); | 256 package->SaveFinished(save_item_id, bytes_so_far, is_success); |
| 260 } | 257 } |
| 261 | 258 |
| 262 // Notifications sent from the UI thread and run on the IO thread. | 259 // Notifications sent from the UI thread and run on the IO thread. |
| 263 | 260 |
| 264 void SaveFileManager::OnSaveURL(const GURL& url, | 261 void SaveFileManager::OnSaveURL(const GURL& url, |
| 265 const Referrer& referrer, | 262 const Referrer& referrer, |
| 266 int save_item_id, | 263 SaveItemId save_item_id, |
| 267 int save_package_id, | 264 SavePackageId save_package_id, |
| 268 int render_process_host_id, | 265 int render_process_host_id, |
| 269 int render_view_routing_id, | 266 int render_view_routing_id, |
| 270 int render_frame_routing_id, | 267 int render_frame_routing_id, |
| 271 ResourceContext* context) { | 268 ResourceContext* context) { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 269 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 273 ResourceDispatcherHostImpl::Get()->BeginSaveFile( | 270 ResourceDispatcherHostImpl::Get()->BeginSaveFile( |
| 274 url, referrer, save_item_id, save_package_id, render_process_host_id, | 271 url, referrer, save_item_id, save_package_id, render_process_host_id, |
| 275 render_view_routing_id, render_frame_routing_id, context); | 272 render_view_routing_id, render_frame_routing_id, context); |
| 276 } | 273 } |
| 277 | 274 |
| 278 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, | 275 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, |
| 279 int request_id) { | 276 int request_id) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 281 ResourceDispatcherHostImpl::Get()->CancelRequest( | 278 ResourceDispatcherHostImpl::Get()->CancelRequest( |
| 282 render_process_id, request_id); | 279 render_process_id, request_id); |
| 283 } | 280 } |
| 284 | 281 |
| 285 // Notifications sent from the UI thread and run on the file thread. | 282 // Notifications sent from the UI thread and run on the file thread. |
| 286 | 283 |
| 287 // This method will be sent via a user action, or shutdown on the UI thread, | 284 // This method will be sent via a user action, or shutdown on the UI thread, |
| 288 // and run on the file thread. We don't post a message back for cancels, | 285 // and run on the file thread. We don't post a message back for cancels, |
| 289 // but we do forward the cancel to the IO thread. Since this message has been | 286 // but we do forward the cancel to the IO thread. Since this message has been |
| 290 // sent from the UI thread, the saving job may have already completed and | 287 // sent from the UI thread, the saving job may have already completed and |
| 291 // won't exist in our map. | 288 // won't exist in our map. |
| 292 void SaveFileManager::CancelSave(int save_item_id) { | 289 void SaveFileManager::CancelSave(SaveItemId save_item_id) { |
| 293 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 290 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 294 SaveFileMap::iterator it = save_file_map_.find(save_item_id); | 291 SaveFileMap::iterator it = save_file_map_.find(save_item_id); |
| 295 if (it != save_file_map_.end()) { | 292 if (it != save_file_map_.end()) { |
| 296 SaveFile* save_file = it->second; | 293 SaveFile* save_file = it->second; |
| 297 | 294 |
| 298 if (!save_file->InProgress()) { | 295 if (!save_file->InProgress()) { |
| 299 // We've won a race with the UI thread--we finished the file before | 296 // We've won a race with the UI thread--we finished the file before |
| 300 // the UI thread cancelled it on us. Unfortunately, in this situation | 297 // the UI thread cancelled it on us. Unfortunately, in this situation |
| 301 // the cancel wins, so we need to delete the now detached file. | 298 // the cancel wins, so we need to delete the now detached file. |
| 302 base::DeleteFile(save_file->FullPath(), false); | 299 base::DeleteFile(save_file->FullPath(), false); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 317 save_file_map_.erase(it); | 314 save_file_map_.erase(it); |
| 318 delete save_file; | 315 delete save_file; |
| 319 } | 316 } |
| 320 } | 317 } |
| 321 | 318 |
| 322 // It is possible that SaveItem which has specified save_item_id has been | 319 // It is possible that SaveItem which has specified save_item_id has been |
| 323 // canceled | 320 // canceled |
| 324 // before this function runs. So if we can not find corresponding SaveFile by | 321 // before this function runs. So if we can not find corresponding SaveFile by |
| 325 // using specified save_item_id, just return. | 322 // using specified save_item_id, just return. |
| 326 void SaveFileManager::SaveLocalFile(const GURL& original_file_url, | 323 void SaveFileManager::SaveLocalFile(const GURL& original_file_url, |
| 327 int save_item_id, | 324 SaveItemId save_item_id, |
| 328 int save_package_id) { | 325 SavePackageId save_package_id) { |
| 329 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 326 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 330 SaveFile* save_file = LookupSaveFile(save_item_id); | 327 SaveFile* save_file = LookupSaveFile(save_item_id); |
| 331 if (!save_file) | 328 if (!save_file) |
| 332 return; | 329 return; |
| 333 // If it has finished, just return. | 330 // If it has finished, just return. |
| 334 if (!save_file->InProgress()) | 331 if (!save_file->InProgress()) |
| 335 return; | 332 return; |
| 336 | 333 |
| 337 // Close the save file before the copy operation. | 334 // Close the save file before the copy operation. |
| 338 save_file->Finish(); | 335 save_file->Finish(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 359 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 356 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 360 DCHECK(!full_path.empty()); | 357 DCHECK(!full_path.empty()); |
| 361 | 358 |
| 362 base::DeleteFile(full_path, is_dir); | 359 base::DeleteFile(full_path, is_dir); |
| 363 } | 360 } |
| 364 | 361 |
| 365 void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names, | 362 void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names, |
| 366 const base::FilePath& resource_dir, | 363 const base::FilePath& resource_dir, |
| 367 int render_process_id, | 364 int render_process_id, |
| 368 int render_frame_routing_id, | 365 int render_frame_routing_id, |
| 369 int save_package_id) { | 366 SavePackageId save_package_id) { |
| 370 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 367 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 371 | 368 |
| 372 if (!resource_dir.empty() && !base::PathExists(resource_dir)) | 369 if (!resource_dir.empty() && !base::PathExists(resource_dir)) |
| 373 base::CreateDirectory(resource_dir); | 370 base::CreateDirectory(resource_dir); |
| 374 | 371 |
| 375 for (const auto& i : final_names) { | 372 for (const auto& i : final_names) { |
| 376 int save_item_id = i.first; | 373 SaveItemId save_item_id = i.first; |
| 377 const base::FilePath& final_name = i.second; | 374 const base::FilePath& final_name = i.second; |
| 378 | 375 |
| 379 SaveFileMap::iterator it = save_file_map_.find(save_item_id); | 376 SaveFileMap::iterator it = save_file_map_.find(save_item_id); |
| 380 if (it != save_file_map_.end()) { | 377 if (it != save_file_map_.end()) { |
| 381 SaveFile* save_file = it->second; | 378 SaveFile* save_file = it->second; |
| 382 DCHECK(!save_file->InProgress()); | 379 DCHECK(!save_file->InProgress()); |
| 383 save_file->Rename(final_name); | 380 save_file->Rename(final_name); |
| 384 delete save_file; | 381 delete save_file; |
| 385 save_file_map_.erase(it); | 382 save_file_map_.erase(it); |
| 386 } | 383 } |
| 387 } | 384 } |
| 388 | 385 |
| 389 BrowserThread::PostTask( | 386 BrowserThread::PostTask( |
| 390 BrowserThread::UI, FROM_HERE, | 387 BrowserThread::UI, FROM_HERE, |
| 391 base::Bind(&SaveFileManager::OnFinishSavePageJob, this, render_process_id, | 388 base::Bind(&SaveFileManager::OnFinishSavePageJob, this, render_process_id, |
| 392 render_frame_routing_id, save_package_id)); | 389 render_frame_routing_id, save_package_id)); |
| 393 } | 390 } |
| 394 | 391 |
| 395 void SaveFileManager::OnFinishSavePageJob(int render_process_id, | 392 void SaveFileManager::OnFinishSavePageJob(int render_process_id, |
| 396 int render_frame_routing_id, | 393 int render_frame_routing_id, |
| 397 int save_package_id) { | 394 SavePackageId save_package_id) { |
| 398 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 395 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 399 | 396 |
| 400 SavePackage* save_package = | 397 SavePackage* save_package = |
| 401 GetSavePackageFromRenderIds(render_process_id, render_frame_routing_id); | 398 GetSavePackageFromRenderIds(render_process_id, render_frame_routing_id); |
| 402 | 399 |
| 403 if (save_package && save_package->id() == save_package_id) | 400 if (save_package && save_package->id() == save_package_id) |
| 404 save_package->Finish(); | 401 save_package->Finish(); |
| 405 } | 402 } |
| 406 | 403 |
| 407 void SaveFileManager::RemoveSavedFileFromFileMap( | 404 void SaveFileManager::RemoveSavedFileFromFileMap( |
| 408 const std::vector<int>& save_item_ids) { | 405 const std::vector<SaveItemId>& save_item_ids) { |
| 409 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 406 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 410 | 407 |
| 411 for (const int save_item_id : save_item_ids) { | 408 for (const SaveItemId save_item_id : save_item_ids) { |
| 412 SaveFileMap::iterator it = save_file_map_.find(save_item_id); | 409 SaveFileMap::iterator it = save_file_map_.find(save_item_id); |
| 413 if (it != save_file_map_.end()) { | 410 if (it != save_file_map_.end()) { |
| 414 SaveFile* save_file = it->second; | 411 SaveFile* save_file = it->second; |
| 415 DCHECK(!save_file->InProgress()); | 412 DCHECK(!save_file->InProgress()); |
| 416 base::DeleteFile(save_file->FullPath(), false); | 413 base::DeleteFile(save_file->FullPath(), false); |
| 417 delete save_file; | 414 delete save_file; |
| 418 save_file_map_.erase(it); | 415 save_file_map_.erase(it); |
| 419 } | 416 } |
| 420 } | 417 } |
| 421 } | 418 } |
| 422 | 419 |
| 423 } // namespace content | 420 } // namespace content |
| OLD | NEW |