OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/i18n/file_util_icu.h" | 11 #include "base/i18n/file_util_icu.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
18 #include "base/task.h" | 18 #include "base/task.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #include "chrome/browser/download/download_history.h" |
21 #include "chrome/browser/download/download_item.h" | 22 #include "chrome/browser/download/download_item.h" |
22 #include "chrome/browser/download/download_item_model.h" | 23 #include "chrome/browser/download/download_item_model.h" |
23 #include "chrome/browser/download/download_manager.h" | 24 #include "chrome/browser/download/download_manager.h" |
24 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "content/browser/browser_thread.h" | 27 #include "content/browser/browser_thread.h" |
27 #include "content/browser/content_browser_client.h" | 28 #include "content/browser/content_browser_client.h" |
28 #include "content/browser/download/save_file.h" | 29 #include "content/browser/download/save_file.h" |
29 #include "content/browser/download/save_file_manager.h" | 30 #include "content/browser/download/save_file_manager.h" |
30 #include "content/browser/download/save_item.h" | 31 #include "content/browser/download/save_item.h" |
31 #include "content/browser/renderer_host/render_process_host.h" | 32 #include "content/browser/renderer_host/render_process_host.h" |
32 #include "content/browser/renderer_host/render_view_host.h" | 33 #include "content/browser/renderer_host/render_view_host.h" |
33 #include "content/browser/renderer_host/render_view_host_delegate.h" | 34 #include "content/browser/renderer_host/render_view_host_delegate.h" |
34 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 35 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
35 #include "content/browser/tab_contents/tab_contents.h" | 36 #include "content/browser/tab_contents/tab_contents.h" |
36 #include "content/common/content_notification_types.h" | |
37 #include "content/common/notification_service.h" | |
38 #include "content/common/url_constants.h" | 37 #include "content/common/url_constants.h" |
39 #include "content/common/view_messages.h" | 38 #include "content/common/view_messages.h" |
40 #include "net/base/io_buffer.h" | 39 #include "net/base/io_buffer.h" |
41 #include "net/base/mime_util.h" | 40 #include "net/base/mime_util.h" |
42 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
43 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" |
45 | 44 |
46 using base::Time; | 45 using base::Time; |
47 using WebKit::WebPageSerializerClient; | 46 using WebKit::WebPageSerializerClient; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 #else | 109 #else |
111 FILE_PATH_LITERAL("html"); | 110 FILE_PATH_LITERAL("html"); |
112 #endif | 111 #endif |
113 | 112 |
114 SavePackage::SavePackage(TabContents* tab_contents, | 113 SavePackage::SavePackage(TabContents* tab_contents, |
115 SavePackageType save_type, | 114 SavePackageType save_type, |
116 const FilePath& file_full_path, | 115 const FilePath& file_full_path, |
117 const FilePath& directory_full_path) | 116 const FilePath& directory_full_path) |
118 : TabContentsObserver(tab_contents), | 117 : TabContentsObserver(tab_contents), |
119 file_manager_(NULL), | 118 file_manager_(NULL), |
| 119 download_manager_(NULL), |
120 download_(NULL), | 120 download_(NULL), |
121 page_url_(GetUrlToBeSaved()), | 121 page_url_(GetUrlToBeSaved()), |
122 saved_main_file_path_(file_full_path), | 122 saved_main_file_path_(file_full_path), |
123 saved_main_directory_path_(directory_full_path), | 123 saved_main_directory_path_(directory_full_path), |
124 title_(tab_contents->GetTitle()), | 124 title_(tab_contents->GetTitle()), |
125 finished_(false), | 125 finished_(false), |
126 user_canceled_(false), | 126 user_canceled_(false), |
127 disk_error_occurred_(false), | 127 disk_error_occurred_(false), |
128 save_type_(save_type), | 128 save_type_(save_type), |
129 all_save_items_count_(0), | 129 all_save_items_count_(0), |
130 wait_state_(INITIALIZE), | 130 wait_state_(INITIALIZE), |
131 tab_id_(tab_contents->GetRenderProcessHost()->id()), | 131 tab_id_(tab_contents->GetRenderProcessHost()->id()), |
132 unique_id_(g_save_package_id++), | 132 unique_id_(g_save_package_id++), |
133 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 133 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
134 DCHECK(page_url_.is_valid()); | 134 DCHECK(page_url_.is_valid()); |
135 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || | 135 DCHECK(save_type_ == SAVE_AS_ONLY_HTML || |
136 save_type_ == SAVE_AS_COMPLETE_HTML); | 136 save_type_ == SAVE_AS_COMPLETE_HTML); |
137 DCHECK(!saved_main_file_path_.empty() && | 137 DCHECK(!saved_main_file_path_.empty() && |
138 saved_main_file_path_.value().length() <= kMaxFilePathLength); | 138 saved_main_file_path_.value().length() <= kMaxFilePathLength); |
139 DCHECK(!saved_main_directory_path_.empty() && | 139 DCHECK(!saved_main_directory_path_.empty() && |
140 saved_main_directory_path_.value().length() < kMaxFilePathLength); | 140 saved_main_directory_path_.value().length() < kMaxFilePathLength); |
141 InternalInit(); | 141 InternalInit(); |
142 } | 142 } |
143 | 143 |
144 SavePackage::SavePackage(TabContents* tab_contents) | 144 SavePackage::SavePackage(TabContents* tab_contents) |
145 : TabContentsObserver(tab_contents), | 145 : TabContentsObserver(tab_contents), |
146 file_manager_(NULL), | 146 file_manager_(NULL), |
| 147 download_manager_(NULL), |
147 download_(NULL), | 148 download_(NULL), |
148 page_url_(GetUrlToBeSaved()), | 149 page_url_(GetUrlToBeSaved()), |
149 title_(tab_contents->GetTitle()), | 150 title_(tab_contents->GetTitle()), |
150 finished_(false), | 151 finished_(false), |
151 user_canceled_(false), | 152 user_canceled_(false), |
152 disk_error_occurred_(false), | 153 disk_error_occurred_(false), |
153 save_type_(SAVE_TYPE_UNKNOWN), | 154 save_type_(SAVE_TYPE_UNKNOWN), |
154 all_save_items_count_(0), | 155 all_save_items_count_(0), |
155 wait_state_(INITIALIZE), | 156 wait_state_(INITIALIZE), |
156 tab_id_(tab_contents->GetRenderProcessHost()->id()), | 157 tab_id_(tab_contents->GetRenderProcessHost()->id()), |
157 unique_id_(g_save_package_id++), | 158 unique_id_(g_save_package_id++), |
158 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 159 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
159 DCHECK(page_url_.is_valid()); | 160 DCHECK(page_url_.is_valid()); |
160 InternalInit(); | 161 InternalInit(); |
161 } | 162 } |
162 | 163 |
163 // This is for testing use. Set |finished_| as true because we don't want | 164 // This is for testing use. Set |finished_| as true because we don't want |
164 // method Cancel to be be called in destructor in test mode. | 165 // method Cancel to be be called in destructor in test mode. |
165 // We also don't call InternalInit(). | 166 // We also don't call InternalInit(). |
166 SavePackage::SavePackage(TabContents* tab_contents, | 167 SavePackage::SavePackage(TabContents* tab_contents, |
167 const FilePath& file_full_path, | 168 const FilePath& file_full_path, |
168 const FilePath& directory_full_path) | 169 const FilePath& directory_full_path) |
169 : TabContentsObserver(tab_contents), | 170 : TabContentsObserver(tab_contents), |
170 file_manager_(NULL), | 171 file_manager_(NULL), |
| 172 download_manager_(NULL), |
171 download_(NULL), | 173 download_(NULL), |
172 saved_main_file_path_(file_full_path), | 174 saved_main_file_path_(file_full_path), |
173 saved_main_directory_path_(directory_full_path), | 175 saved_main_directory_path_(directory_full_path), |
174 finished_(true), | 176 finished_(true), |
175 user_canceled_(false), | 177 user_canceled_(false), |
176 disk_error_occurred_(false), | 178 disk_error_occurred_(false), |
177 save_type_(SAVE_TYPE_UNKNOWN), | 179 save_type_(SAVE_TYPE_UNKNOWN), |
178 all_save_items_count_(0), | 180 all_save_items_count_(0), |
179 wait_state_(INITIALIZE), | 181 wait_state_(INITIALIZE), |
180 tab_id_(0), | 182 tab_id_(0), |
181 unique_id_(g_save_package_id++), | 183 unique_id_(g_save_package_id++), |
182 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 184 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
183 } | 185 } |
184 | 186 |
185 SavePackage::~SavePackage() { | 187 SavePackage::~SavePackage() { |
186 // Stop receiving saving job's updates | 188 // Stop receiving saving job's updates |
187 if (!finished_ && !canceled()) { | 189 if (!finished_ && !canceled()) { |
188 // Unexpected quit. | 190 // Unexpected quit. |
189 Cancel(true); | 191 Cancel(true); |
190 } | 192 } |
191 | 193 |
| 194 // We should no longer be observing the DownloadManager at this point. |
| 195 CHECK(!download_manager_); |
| 196 CHECK(!download_); |
| 197 |
192 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() + | 198 DCHECK(all_save_items_count_ == (waiting_item_queue_.size() + |
193 completed_count() + | 199 completed_count() + |
194 in_process_count())); | 200 in_process_count())); |
195 // Free all SaveItems. | 201 // Free all SaveItems. |
196 while (!waiting_item_queue_.empty()) { | 202 while (!waiting_item_queue_.empty()) { |
197 // We still have some items which are waiting for start to save. | 203 // We still have some items which are waiting for start to save. |
198 SaveItem* save_item = waiting_item_queue_.front(); | 204 SaveItem* save_item = waiting_item_queue_.front(); |
199 waiting_item_queue_.pop(); | 205 waiting_item_queue_.pop(); |
200 delete save_item; | 206 delete save_item; |
201 } | 207 } |
202 | 208 |
203 STLDeleteValues(&saved_success_items_); | 209 STLDeleteValues(&saved_success_items_); |
204 STLDeleteValues(&in_progress_items_); | 210 STLDeleteValues(&in_progress_items_); |
205 STLDeleteValues(&saved_failed_items_); | 211 STLDeleteValues(&saved_failed_items_); |
206 | 212 |
207 // The DownloadItem is owned by DownloadManager. | |
208 download_ = NULL; | |
209 | |
210 file_manager_ = NULL; | 213 file_manager_ = NULL; |
211 } | 214 } |
212 | 215 |
213 GURL SavePackage::GetUrlToBeSaved() { | 216 GURL SavePackage::GetUrlToBeSaved() { |
214 // Instead of using tab_contents_.GetURL here, we use url() | 217 // Instead of using tab_contents_.GetURL here, we use url() |
215 // (which is the "real" url of the page) | 218 // (which is the "real" url of the page) |
216 // from the NavigationEntry because it reflects its' origin | 219 // from the NavigationEntry because it reflects its' origin |
217 // rather than the displayed one (returned by GetURL) which may be | 220 // rather than the displayed one (returned by GetURL) which may be |
218 // different (like having "view-source:" on the front). | 221 // different (like having "view-source:" on the front). |
219 NavigationEntry* active_entry = | 222 NavigationEntry* active_entry = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 258 |
256 wait_state_ = START_PROCESS; | 259 wait_state_ = START_PROCESS; |
257 | 260 |
258 // Initialize the request context and resource dispatcher. | 261 // Initialize the request context and resource dispatcher. |
259 content::BrowserContext* browser_context = tab_contents()->browser_context(); | 262 content::BrowserContext* browser_context = tab_contents()->browser_context(); |
260 if (!browser_context) { | 263 if (!browser_context) { |
261 NOTREACHED(); | 264 NOTREACHED(); |
262 return false; | 265 return false; |
263 } | 266 } |
264 | 267 |
265 // Create the fake DownloadItem and display the view. | 268 // Get the download manager and add ourselves as an observer. |
266 DownloadManager* download_manager = | 269 download_manager_ = tab_contents()->browser_context()->GetDownloadManager(); |
267 tab_contents()->browser_context()->GetDownloadManager(); | 270 if (!download_manager_) { |
268 download_ = new DownloadItem(download_manager, | 271 NOTREACHED(); |
| 272 return false; |
| 273 } |
| 274 |
| 275 // Create the download item. |
| 276 download_ = new DownloadItem(download_manager_, |
269 saved_main_file_path_, | 277 saved_main_file_path_, |
270 page_url_, | 278 page_url_, |
271 browser_context->IsOffTheRecord()); | 279 browser_context->IsOffTheRecord()); |
| 280 download_->AddObserver(this); |
272 | 281 |
273 // Transfer the ownership to the download manager. We need the DownloadItem | 282 // Transfer ownership to the download manager. |
274 // to be alive as long as the Profile is alive. | 283 download_manager_->SavePageDownloadStarted(download_); |
275 download_manager->SavePageAsDownloadStarted(download_); | |
276 | |
277 tab_contents()->OnStartDownload(download_); | |
278 | 284 |
279 // Check save type and process the save page job. | 285 // Check save type and process the save page job. |
280 if (save_type_ == SAVE_AS_COMPLETE_HTML) { | 286 if (save_type_ == SAVE_AS_COMPLETE_HTML) { |
281 // Get directory | 287 // Get directory |
282 DCHECK(!saved_main_directory_path_.empty()); | 288 DCHECK(!saved_main_directory_path_.empty()); |
283 GetAllSavableResourceLinksForCurrentPage(); | 289 GetAllSavableResourceLinksForCurrentPage(); |
284 } else { | 290 } else { |
285 wait_state_ = NET_FILES; | 291 wait_state_ = NET_FILES; |
286 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? | 292 SaveFileCreateInfo::SaveFileSource save_source = page_url_.SchemeIsFile() ? |
287 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 293 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 BrowserThread::PostTask( | 635 BrowserThread::PostTask( |
630 BrowserThread::FILE, FROM_HERE, | 636 BrowserThread::FILE, FROM_HERE, |
631 NewRunnableMethod(file_manager_, | 637 NewRunnableMethod(file_manager_, |
632 &SaveFileManager::RemoveSavedFileFromFileMap, | 638 &SaveFileManager::RemoveSavedFileFromFileMap, |
633 save_ids)); | 639 save_ids)); |
634 | 640 |
635 finished_ = true; | 641 finished_ = true; |
636 wait_state_ = FAILED; | 642 wait_state_ = FAILED; |
637 | 643 |
638 // Inform the DownloadItem we have canceled whole save page job. | 644 // Inform the DownloadItem we have canceled whole save page job. |
639 download_->Cancel(false); | 645 if (download_) { |
| 646 download_->Cancel(false); |
| 647 FinalizeDownloadEntry(); |
| 648 } |
640 } | 649 } |
641 | 650 |
642 void SavePackage::CheckFinish() { | 651 void SavePackage::CheckFinish() { |
643 if (in_process_count() || finished_) | 652 if (in_process_count() || finished_) |
644 return; | 653 return; |
645 | 654 |
646 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && | 655 FilePath dir = (save_type_ == SAVE_AS_COMPLETE_HTML && |
647 saved_success_items_.size() > 1) ? | 656 saved_success_items_.size() > 1) ? |
648 saved_main_directory_path_ : FilePath(); | 657 saved_main_directory_path_ : FilePath(); |
649 | 658 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); | 691 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); |
683 it != saved_failed_items_.end(); ++it) | 692 it != saved_failed_items_.end(); ++it) |
684 save_ids.push_back(it->second->save_id()); | 693 save_ids.push_back(it->second->save_id()); |
685 | 694 |
686 BrowserThread::PostTask( | 695 BrowserThread::PostTask( |
687 BrowserThread::FILE, FROM_HERE, | 696 BrowserThread::FILE, FROM_HERE, |
688 NewRunnableMethod(file_manager_, | 697 NewRunnableMethod(file_manager_, |
689 &SaveFileManager::RemoveSavedFileFromFileMap, | 698 &SaveFileManager::RemoveSavedFileFromFileMap, |
690 save_ids)); | 699 save_ids)); |
691 | 700 |
692 download_->OnAllDataSaved(all_save_items_count_); | 701 if (download_) { |
693 download_->MarkAsComplete(); | 702 download_->OnAllDataSaved(all_save_items_count_); |
694 | 703 download_->MarkAsComplete(); |
695 NotificationService::current()->Notify( | 704 FinalizeDownloadEntry(); |
696 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 705 } |
697 Source<SavePackage>(this), | |
698 Details<GURL>(&page_url_)); | |
699 } | 706 } |
700 | 707 |
701 // Called for updating end state. | 708 // Called for updating end state. |
702 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { | 709 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { |
703 // Because we might have canceled this saving job before, | 710 // Because we might have canceled this saving job before, |
704 // so we might not find corresponding SaveItem. Just ignore it. | 711 // so we might not find corresponding SaveItem. Just ignore it. |
705 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); | 712 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); |
706 if (!save_item) | 713 if (!save_item) |
707 return; | 714 return; |
708 | 715 |
709 // Let SaveItem set end state. | 716 // Let SaveItem set end state. |
710 save_item->Finish(size, is_success); | 717 save_item->Finish(size, is_success); |
711 // Remove the associated save id and SavePackage. | 718 // Remove the associated save id and SavePackage. |
712 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); | 719 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); |
713 | 720 |
714 PutInProgressItemToSavedMap(save_item); | 721 PutInProgressItemToSavedMap(save_item); |
715 | 722 |
716 // Inform the DownloadItem to update UI. | 723 // Inform the DownloadItem to update UI. |
717 // We use the received bytes as number of saved files. | 724 // We use the received bytes as number of saved files. |
718 download_->Update(completed_count()); | 725 if (download_) |
| 726 download_->Update(completed_count()); |
719 | 727 |
720 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && | 728 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && |
721 save_item->url() == page_url_ && !save_item->received_bytes()) { | 729 save_item->url() == page_url_ && !save_item->received_bytes()) { |
722 // If size of main HTML page is 0, treat it as disk error. | 730 // If size of main HTML page is 0, treat it as disk error. |
723 Cancel(false); | 731 Cancel(false); |
724 return; | 732 return; |
725 } | 733 } |
726 | 734 |
727 if (canceled()) { | 735 if (canceled()) { |
728 DCHECK(finished_); | 736 DCHECK(finished_); |
(...skipping 20 matching lines...) Expand all Loading... |
749 return; | 757 return; |
750 } | 758 } |
751 SaveItem* save_item = it->second; | 759 SaveItem* save_item = it->second; |
752 | 760 |
753 save_item->Finish(0, false); | 761 save_item->Finish(0, false); |
754 | 762 |
755 PutInProgressItemToSavedMap(save_item); | 763 PutInProgressItemToSavedMap(save_item); |
756 | 764 |
757 // Inform the DownloadItem to update UI. | 765 // Inform the DownloadItem to update UI. |
758 // We use the received bytes as number of saved files. | 766 // We use the received bytes as number of saved files. |
759 download_->Update(completed_count()); | 767 if (download_) |
| 768 download_->Update(completed_count()); |
760 | 769 |
761 if (save_type_ == SAVE_AS_ONLY_HTML || | 770 if (save_type_ == SAVE_AS_ONLY_HTML || |
762 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { | 771 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { |
763 // We got error when saving page. Treat it as disk error. | 772 // We got error when saving page. Treat it as disk error. |
764 Cancel(true); | 773 Cancel(true); |
765 } | 774 } |
766 | 775 |
767 if (canceled()) { | 776 if (canceled()) { |
768 DCHECK(finished_); | 777 DCHECK(finished_); |
769 return; | 778 return; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 const std::vector<GURL>& referrers_list, | 1023 const std::vector<GURL>& referrers_list, |
1015 const std::vector<GURL>& frames_list) { | 1024 const std::vector<GURL>& frames_list) { |
1016 if (wait_state_ != RESOURCES_LIST) | 1025 if (wait_state_ != RESOURCES_LIST) |
1017 return; | 1026 return; |
1018 | 1027 |
1019 DCHECK(resources_list.size() == referrers_list.size()); | 1028 DCHECK(resources_list.size() == referrers_list.size()); |
1020 all_save_items_count_ = static_cast<int>(resources_list.size()) + | 1029 all_save_items_count_ = static_cast<int>(resources_list.size()) + |
1021 static_cast<int>(frames_list.size()); | 1030 static_cast<int>(frames_list.size()); |
1022 | 1031 |
1023 // We use total bytes as the total number of files we want to save. | 1032 // We use total bytes as the total number of files we want to save. |
1024 download_->set_total_bytes(all_save_items_count_); | 1033 if (download_) |
| 1034 download_->set_total_bytes(all_save_items_count_); |
1025 | 1035 |
1026 if (all_save_items_count_) { | 1036 if (all_save_items_count_) { |
1027 // Put all sub-resources to wait list. | 1037 // Put all sub-resources to wait list. |
1028 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { | 1038 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { |
1029 const GURL& u = resources_list[i]; | 1039 const GURL& u = resources_list[i]; |
1030 DCHECK(u.is_valid()); | 1040 DCHECK(u.is_valid()); |
1031 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? | 1041 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? |
1032 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 1042 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
1033 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 1043 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
1034 SaveItem* save_item = new SaveItem(u, referrers_list[i], | 1044 SaveItem* save_item = new SaveItem(u, referrers_list[i], |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { | 1267 bool SavePackage::IsSavableContents(const std::string& contents_mime_type) { |
1258 // WebKit creates Document object when MIME type is application/xhtml+xml, | 1268 // WebKit creates Document object when MIME type is application/xhtml+xml, |
1259 // so we also support this MIME type. | 1269 // so we also support this MIME type. |
1260 return contents_mime_type == "text/html" || | 1270 return contents_mime_type == "text/html" || |
1261 contents_mime_type == "text/xml" || | 1271 contents_mime_type == "text/xml" || |
1262 contents_mime_type == "application/xhtml+xml" || | 1272 contents_mime_type == "application/xhtml+xml" || |
1263 contents_mime_type == "text/plain" || | 1273 contents_mime_type == "text/plain" || |
1264 contents_mime_type == "text/css" || | 1274 contents_mime_type == "text/css" || |
1265 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); | 1275 net::IsSupportedJavascriptMimeType(contents_mime_type.c_str()); |
1266 } | 1276 } |
| 1277 |
| 1278 void SavePackage::StopObservation() { |
| 1279 DCHECK(download_); |
| 1280 DCHECK(download_manager_); |
| 1281 |
| 1282 download_->RemoveObserver(this); |
| 1283 download_ = NULL; |
| 1284 download_manager_ = NULL; |
| 1285 } |
| 1286 |
| 1287 void SavePackage::OnDownloadUpdated(DownloadItem* download) { |
| 1288 DCHECK(download_); |
| 1289 DCHECK(download_ == download); |
| 1290 DCHECK(download_manager_); |
| 1291 |
| 1292 // Check for removal. |
| 1293 if (download->state() == DownloadItem::REMOVING) |
| 1294 StopObservation(); |
| 1295 } |
| 1296 |
| 1297 void SavePackage::FinalizeDownloadEntry() { |
| 1298 DCHECK(download_); |
| 1299 DCHECK(download_manager_); |
| 1300 |
| 1301 download_manager_->SavePageDownloadFinished(download_); |
| 1302 StopObservation(); |
| 1303 } |
OLD | NEW |