Chromium Code Reviews| 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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 // The download manager keeps ownership but adds us as an observer. | 284 // The download manager keeps ownership but adds us as an observer. |
| 285 download_ = download_manager_->CreateSavePackageDownloadItem( | 285 download_ = download_manager_->CreateSavePackageDownloadItem( |
| 286 saved_main_file_path_, page_url_, | 286 saved_main_file_path_, page_url_, |
| 287 browser_context->IsOffTheRecord(), this); | 287 browser_context->IsOffTheRecord(), this); |
| 288 | 288 |
| 289 // Check save type and process the save page job. | 289 // Check save type and process the save page job. |
| 290 if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { | 290 if (save_type_ == content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML) { |
| 291 // Get directory | 291 // Get directory |
| 292 DCHECK(!saved_main_directory_path_.empty()); | 292 DCHECK(!saved_main_directory_path_.empty()); |
| 293 GetAllSavableResourceLinksForCurrentPage(); | 293 GetAllSavableResourceLinksForCurrentPage(); |
| 294 } else if (save_type_ == | |
| 295 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML_SINGLE_FILE_MHTML) { | |
| 296 web_contents()->GenerateMHTML(saved_main_file_path_, base::Bind( | |
| 297 &SavePackage::MHTMLGenerated, this)); | |
| 294 } else { | 298 } else { |
| 295 wait_state_ = NET_FILES; | 299 wait_state_ = NET_FILES; |
| 296 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? | 300 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
| 297 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 301 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
| 298 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 302 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
| 299 SaveItem* save_item = new SaveItem(page_url_, | 303 SaveItem* save_item = new SaveItem(page_url_, |
| 300 GURL(), | 304 GURL(), |
| 301 this, | 305 this, |
| 302 save_source); | 306 save_source); |
| 303 // Add this item to waiting list. | 307 // Add this item to waiting list. |
| 304 waiting_item_queue_.push(save_item); | 308 waiting_item_queue_.push(save_item); |
| 305 all_save_items_count_ = 1; | 309 all_save_items_count_ = 1; |
| 306 download_->SetTotalBytes(1); | 310 download_->SetTotalBytes(1); |
| 307 | 311 |
| 308 DoSavingProcess(); | 312 DoSavingProcess(); |
| 309 } | 313 } |
| 310 | 314 |
| 311 return true; | 315 return true; |
| 312 } | 316 } |
| 313 | 317 |
| 318 void SavePackage::MHTMLGenerated(const FilePath& path, int64 size) { | |
|
asanka
2012/04/13 15:28:19
I think the size will be -1 if there was an error
benjhayden
2012/04/13 20:44:11
Done.
| |
| 319 Finish(); | |
| 320 } | |
| 321 | |
| 314 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further | 322 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further |
| 315 // restricted by NAME_MAX. The maximum allowed path looks like: | 323 // restricted by NAME_MAX. The maximum allowed path looks like: |
| 316 // '/path/to/save_dir' + '/' + NAME_MAX. | 324 // '/path/to/save_dir' + '/' + NAME_MAX. |
| 317 uint32 SavePackage::GetMaxPathLengthForDirectory(const FilePath& base_dir) { | 325 uint32 SavePackage::GetMaxPathLengthForDirectory(const FilePath& base_dir) { |
| 318 #if defined(OS_POSIX) | 326 #if defined(OS_POSIX) |
| 319 return std::min(kMaxFilePathLength, | 327 return std::min(kMaxFilePathLength, |
| 320 static_cast<uint32>(base_dir.value().length()) + | 328 static_cast<uint32>(base_dir.value().length()) + |
| 321 NAME_MAX + 1); | 329 NAME_MAX + 1); |
| 322 #else | 330 #else |
| 323 return kMaxFilePathLength; | 331 return kMaxFilePathLength; |
| (...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1315 StopObservation(); | 1323 StopObservation(); |
| 1316 } | 1324 } |
| 1317 | 1325 |
| 1318 void SavePackage::FinalizeDownloadEntry() { | 1326 void SavePackage::FinalizeDownloadEntry() { |
| 1319 DCHECK(download_); | 1327 DCHECK(download_); |
| 1320 DCHECK(download_manager_); | 1328 DCHECK(download_manager_); |
| 1321 | 1329 |
| 1322 download_manager_->SavePageDownloadFinished(download_); | 1330 download_manager_->SavePageDownloadFinished(download_); |
| 1323 StopObservation(); | 1331 StopObservation(); |
| 1324 } | 1332 } |
| OLD | NEW |