| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "base/thread.h" | 15 #include "base/thread.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/download/download_item_model.h" | 17 #include "chrome/browser/download/download_item_model.h" |
| 18 #include "chrome/browser/download/download_manager.h" | 18 #include "chrome/browser/download/download_manager.h" |
| 19 #include "chrome/browser/download/download_shelf.h" | 19 #include "chrome/browser/download/download_shelf.h" |
| 20 #include "chrome/browser/download/save_file.h" | 20 #include "chrome/browser/download/save_file.h" |
| 21 #include "chrome/browser/download/save_file_manager.h" | 21 #include "chrome/browser/download/save_file_manager.h" |
| 22 #include "chrome/browser/download/save_item.h" | 22 #include "chrome/browser/download/save_item.h" |
| 23 #include "chrome/browser/net/url_request_context_getter.h" |
| 23 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
| 24 #include "chrome/browser/renderer_host/render_process_host.h" | 25 #include "chrome/browser/renderer_host/render_process_host.h" |
| 25 #include "chrome/browser/renderer_host/render_view_host.h" | 26 #include "chrome/browser/renderer_host/render_view_host.h" |
| 26 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 27 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 27 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 28 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents.h" | 29 #include "chrome/browser/tab_contents/tab_contents.h" |
| 29 #include "chrome/browser/tab_contents/tab_util.h" | 30 #include "chrome/browser/tab_contents/tab_util.h" |
| 30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/notification_service.h" | 32 #include "chrome/common/notification_service.h" |
| 32 #include "chrome/common/notification_type.h" | 33 #include "chrome/common/notification_type.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 289 |
| 289 wait_state_ = START_PROCESS; | 290 wait_state_ = START_PROCESS; |
| 290 | 291 |
| 291 // Initialize the request context and resource dispatcher. | 292 // Initialize the request context and resource dispatcher. |
| 292 Profile* profile = tab_contents_->profile(); | 293 Profile* profile = tab_contents_->profile(); |
| 293 if (!profile) { | 294 if (!profile) { |
| 294 NOTREACHED(); | 295 NOTREACHED(); |
| 295 return false; | 296 return false; |
| 296 } | 297 } |
| 297 | 298 |
| 298 request_context_ = profile->GetRequestContext(); | 299 request_context_getter_ = profile->GetRequestContext(); |
| 299 | 300 |
| 300 // Create the fake DownloadItem and display the view. | 301 // Create the fake DownloadItem and display the view. |
| 301 download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_, GURL(), | 302 download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_, GURL(), |
| 302 "", FilePath(), Time::Now(), 0, -1, -1, false, false); | 303 "", FilePath(), Time::Now(), 0, -1, -1, false, false); |
| 303 download_->set_manager(tab_contents_->profile()->GetDownloadManager()); | 304 download_->set_manager(tab_contents_->profile()->GetDownloadManager()); |
| 304 tab_contents_->OnStartDownload(download_); | 305 tab_contents_->OnStartDownload(download_); |
| 305 | 306 |
| 306 // Check save type and process the save page job. | 307 // Check save type and process the save page job. |
| 307 if (save_type_ == SAVE_AS_COMPLETE_HTML) { | 308 if (save_type_ == SAVE_AS_COMPLETE_HTML) { |
| 308 // Get directory | 309 // Get directory |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 save_item->url().spec()); | 758 save_item->url().spec()); |
| 758 DCHECK(it == in_progress_items_.end()); | 759 DCHECK(it == in_progress_items_.end()); |
| 759 in_progress_items_[save_item->url().spec()] = save_item; | 760 in_progress_items_[save_item->url().spec()] = save_item; |
| 760 save_item->Start(); | 761 save_item->Start(); |
| 761 file_manager_->SaveURL(save_item->url(), | 762 file_manager_->SaveURL(save_item->url(), |
| 762 save_item->referrer(), | 763 save_item->referrer(), |
| 763 tab_contents_->process()->id(), | 764 tab_contents_->process()->id(), |
| 764 tab_contents_->render_view_host()->routing_id(), | 765 tab_contents_->render_view_host()->routing_id(), |
| 765 save_item->save_source(), | 766 save_item->save_source(), |
| 766 save_item->full_path(), | 767 save_item->full_path(), |
| 767 request_context_.get(), | 768 request_context_getter_.get(), |
| 768 this); | 769 this); |
| 769 } while (process_all_remaining_items && waiting_item_queue_.size()); | 770 } while (process_all_remaining_items && waiting_item_queue_.size()); |
| 770 } | 771 } |
| 771 | 772 |
| 772 | 773 |
| 773 // Open download page in windows explorer on file thread, to avoid blocking the | 774 // Open download page in windows explorer on file thread, to avoid blocking the |
| 774 // user interface. | 775 // user interface. |
| 775 void SavePackage::ShowDownloadInShell() { | 776 void SavePackage::ShowDownloadInShell() { |
| 776 DCHECK(file_manager_); | 777 DCHECK(file_manager_); |
| 777 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); | 778 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 int index, void* params) { | 1248 int index, void* params) { |
| 1248 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1249 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1249 ContinueSave(save_params, path, index); | 1250 ContinueSave(save_params, path, index); |
| 1250 delete save_params; | 1251 delete save_params; |
| 1251 } | 1252 } |
| 1252 | 1253 |
| 1253 void SavePackage::FileSelectionCanceled(void* params) { | 1254 void SavePackage::FileSelectionCanceled(void* params) { |
| 1254 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1255 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1255 delete save_params; | 1256 delete save_params; |
| 1256 } | 1257 } |
| OLD | NEW |