| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/download/save_package.h" | 5 #include "chrome/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 return pure_file_name.substr(0, l_paren_index); | 110 return pure_file_name.substr(0, l_paren_index); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| 115 SavePackage::SavePackage(WebContents* web_content, | 115 SavePackage::SavePackage(WebContents* web_content, |
| 116 SavePackageType save_type, | 116 SavePackageType save_type, |
| 117 const FilePath& file_full_path, | 117 const FilePath& file_full_path, |
| 118 const FilePath& directory_full_path) | 118 const FilePath& directory_full_path) |
| 119 : web_contents_(web_content), | 119 : file_manager_(NULL), |
| 120 web_contents_(web_content), |
| 120 download_(NULL), | 121 download_(NULL), |
| 121 saved_main_file_path_(file_full_path), | 122 saved_main_file_path_(file_full_path), |
| 122 saved_main_directory_path_(directory_full_path), | 123 saved_main_directory_path_(directory_full_path), |
| 123 finished_(false), | 124 finished_(false), |
| 124 user_canceled_(false), | 125 user_canceled_(false), |
| 125 disk_error_occurred_(false), | 126 disk_error_occurred_(false), |
| 126 save_type_(save_type), | 127 save_type_(save_type), |
| 127 all_save_items_count_(0), | 128 all_save_items_count_(0), |
| 128 wait_state_(INITIALIZE), | 129 wait_state_(INITIALIZE), |
| 129 tab_id_(web_content->process()->pid()) { | 130 tab_id_(web_content->process()->pid()) { |
| 130 DCHECK(web_content); | 131 DCHECK(web_content); |
| 131 const GURL& current_page_url = web_contents_->GetURL(); | 132 const GURL& current_page_url = web_contents_->GetURL(); |
| 132 DCHECK(current_page_url.is_valid()); | 133 DCHECK(current_page_url.is_valid()); |
| 133 page_url_ = current_page_url; | 134 page_url_ = current_page_url; |
| 134 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || | 135 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || |
| 135 save_type_ == SAVE_AS_COMPLETE_HTML); | 136 save_type_ == SAVE_AS_COMPLETE_HTML); |
| 136 DCHECK(!saved_main_file_path_.empty() && | 137 DCHECK(!saved_main_file_path_.empty() && |
| 137 saved_main_file_path_.value().length() <= kMaxFilePathLength); | 138 saved_main_file_path_.value().length() <= kMaxFilePathLength); |
| 138 DCHECK(!saved_main_directory_path_.empty() && | 139 DCHECK(!saved_main_directory_path_.empty() && |
| 139 saved_main_directory_path_.value().length() < kMaxFilePathLength); | 140 saved_main_directory_path_.value().length() < kMaxFilePathLength); |
| 140 } | 141 } |
| 141 | 142 |
| 142 SavePackage::SavePackage(WebContents* web_contents) | 143 SavePackage::SavePackage(WebContents* web_contents) |
| 143 : web_contents_(web_contents), | 144 : file_manager_(NULL), |
| 145 web_contents_(web_contents), |
| 144 download_(NULL), | 146 download_(NULL), |
| 145 finished_(false), | 147 finished_(false), |
| 146 user_canceled_(false), | 148 user_canceled_(false), |
| 147 disk_error_occurred_(false), | 149 disk_error_occurred_(false), |
| 148 all_save_items_count_(0), | 150 all_save_items_count_(0), |
| 149 wait_state_(INITIALIZE), | 151 wait_state_(INITIALIZE), |
| 150 tab_id_(web_contents->process()->pid()) { | 152 tab_id_(web_contents->process()->pid()) { |
| 151 const GURL& current_page_url = web_contents_->GetURL(); | 153 const GURL& current_page_url = web_contents_->GetURL(); |
| 152 DCHECK(current_page_url.is_valid()); | 154 DCHECK(current_page_url.is_valid()); |
| 153 page_url_ = current_page_url; | 155 page_url_ = current_page_url; |
| 154 } | 156 } |
| 155 | 157 |
| 156 // This is for testing use. Set |finished_| as true because we don't want | 158 // This is for testing use. Set |finished_| as true because we don't want |
| 157 // method Cancel to be be called in destructor in test mode. | 159 // method Cancel to be be called in destructor in test mode. |
| 158 SavePackage::SavePackage(const FilePath& file_full_path, | 160 SavePackage::SavePackage(const FilePath& file_full_path, |
| 159 const FilePath& directory_full_path) | 161 const FilePath& directory_full_path) |
| 160 : download_(NULL), | 162 : file_manager_(NULL), |
| 163 download_(NULL), |
| 161 saved_main_file_path_(file_full_path), | 164 saved_main_file_path_(file_full_path), |
| 162 saved_main_directory_path_(directory_full_path), | 165 saved_main_directory_path_(directory_full_path), |
| 163 finished_(true), | 166 finished_(true), |
| 164 user_canceled_(false), | 167 user_canceled_(false), |
| 165 disk_error_occurred_(false), | 168 disk_error_occurred_(false), |
| 166 all_save_items_count_(0), | 169 all_save_items_count_(0), |
| 167 tab_id_(0) { | 170 tab_id_(0) { |
| 168 DCHECK(!saved_main_file_path_.empty() && | 171 DCHECK(!saved_main_file_path_.empty() && |
| 169 saved_main_file_path_.value().length() <= kMaxFilePathLength); | 172 saved_main_file_path_.value().length() <= kMaxFilePathLength); |
| 170 DCHECK(!saved_main_directory_path_.empty() && | 173 DCHECK(!saved_main_directory_path_.empty() && |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 if (!write_success) { | 503 if (!write_success) { |
| 501 // Cancel job with reason of disk error. | 504 // Cancel job with reason of disk error. |
| 502 Cancel(false); | 505 Cancel(false); |
| 503 } | 506 } |
| 504 return true; | 507 return true; |
| 505 } | 508 } |
| 506 | 509 |
| 507 // Stop all page saving jobs that are in progress and instruct the file thread | 510 // Stop all page saving jobs that are in progress and instruct the file thread |
| 508 // to delete all saved files. | 511 // to delete all saved files. |
| 509 void SavePackage::Stop() { | 512 void SavePackage::Stop() { |
| 513 // If we haven't moved out of the initial state, there's nothing to cancel and |
| 514 // there won't be valid pointers for file_manager_ or download_. |
| 515 if (wait_state_ == INITIALIZE) |
| 516 return; |
| 517 |
| 510 // When stopping, if it still has some items in in_progress, cancel them. | 518 // When stopping, if it still has some items in in_progress, cancel them. |
| 511 DCHECK(canceled()); | 519 DCHECK(canceled()); |
| 512 if (in_process_count()) { | 520 if (in_process_count()) { |
| 513 SaveUrlItemMap::iterator it = in_progress_items_.begin(); | 521 SaveUrlItemMap::iterator it = in_progress_items_.begin(); |
| 514 for (; it != in_progress_items_.end(); ++it) { | 522 for (; it != in_progress_items_.end(); ++it) { |
| 515 SaveItem* save_item = it->second; | 523 SaveItem* save_item = it->second; |
| 516 DCHECK(save_item->state() == SaveItem::IN_PROGRESS); | 524 DCHECK(save_item->state() == SaveItem::IN_PROGRESS); |
| 517 save_item->Cancel(); | 525 save_item->Cancel(); |
| 518 } | 526 } |
| 519 // Remove all in progress item to saved map. For failed items, they will | 527 // Remove all in progress item to saved map. For failed items, they will |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 int index, void* params) { | 1146 int index, void* params) { |
| 1139 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1147 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1140 ContinueSave(save_params, path, index); | 1148 ContinueSave(save_params, path, index); |
| 1141 delete save_params; | 1149 delete save_params; |
| 1142 } | 1150 } |
| 1143 | 1151 |
| 1144 void SavePackage::FileSelectionCanceled(void* params) { | 1152 void SavePackage::FileSelectionCanceled(void* params) { |
| 1145 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1153 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1146 delete save_params; | 1154 delete save_params; |
| 1147 } | 1155 } |
| OLD | NEW |