| 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 "chrome/browser/download/save_package.h" | 5 #include "chrome/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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "content/browser/tab_contents/tab_contents.h" | 46 #include "content/browser/tab_contents/tab_contents.h" |
| 47 #include "content/common/notification_service.h" | 47 #include "content/common/notification_service.h" |
| 48 #include "content/common/notification_type.h" | 48 #include "content/common/notification_type.h" |
| 49 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 50 #include "net/base/io_buffer.h" | 50 #include "net/base/io_buffer.h" |
| 51 #include "net/base/mime_util.h" | 51 #include "net/base/mime_util.h" |
| 52 #include "net/base/net_util.h" | 52 #include "net/base/net_util.h" |
| 53 #include "net/url_request/url_request_context.h" | 53 #include "net/url_request/url_request_context.h" |
| 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClie
nt.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "net/url_request/url_request_context_getter.h" | |
| 57 | 56 |
| 58 using base::Time; | 57 using base::Time; |
| 59 using WebKit::WebPageSerializerClient; | 58 using WebKit::WebPageSerializerClient; |
| 60 | 59 |
| 61 namespace { | 60 namespace { |
| 62 | 61 |
| 63 // A counter for uniquely identifying each save package. | 62 // A counter for uniquely identifying each save package. |
| 64 int g_save_package_id = 0; | 63 int g_save_package_id = 0; |
| 65 | 64 |
| 66 // Default name which will be used when we can not get proper name from | 65 // Default name which will be used when we can not get proper name from |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 303 |
| 305 wait_state_ = START_PROCESS; | 304 wait_state_ = START_PROCESS; |
| 306 | 305 |
| 307 // Initialize the request context and resource dispatcher. | 306 // Initialize the request context and resource dispatcher. |
| 308 Profile* profile = tab_contents()->profile(); | 307 Profile* profile = tab_contents()->profile(); |
| 309 if (!profile) { | 308 if (!profile) { |
| 310 NOTREACHED(); | 309 NOTREACHED(); |
| 311 return false; | 310 return false; |
| 312 } | 311 } |
| 313 | 312 |
| 314 request_context_getter_ = profile->GetRequestContext(); | |
| 315 | |
| 316 // Create the fake DownloadItem and display the view. | 313 // Create the fake DownloadItem and display the view. |
| 317 DownloadManager* download_manager = | 314 DownloadManager* download_manager = |
| 318 tab_contents()->profile()->GetDownloadManager(); | 315 tab_contents()->profile()->GetDownloadManager(); |
| 319 download_ = new DownloadItem(download_manager, | 316 download_ = new DownloadItem(download_manager, |
| 320 saved_main_file_path_, | 317 saved_main_file_path_, |
| 321 page_url_, | 318 page_url_, |
| 322 profile->IsOffTheRecord()); | 319 profile->IsOffTheRecord()); |
| 323 | 320 |
| 324 // Transfer the ownership to the download manager. We need the DownloadItem | 321 // Transfer the ownership to the download manager. We need the DownloadItem |
| 325 // to be alive as long as the Profile is alive. | 322 // to be alive as long as the Profile is alive. |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 save_item->url().spec()); | 856 save_item->url().spec()); |
| 860 DCHECK(it == in_progress_items_.end()); | 857 DCHECK(it == in_progress_items_.end()); |
| 861 in_progress_items_[save_item->url().spec()] = save_item; | 858 in_progress_items_[save_item->url().spec()] = save_item; |
| 862 save_item->Start(); | 859 save_item->Start(); |
| 863 file_manager_->SaveURL(save_item->url(), | 860 file_manager_->SaveURL(save_item->url(), |
| 864 save_item->referrer(), | 861 save_item->referrer(), |
| 865 tab_contents()->GetRenderProcessHost()->id(), | 862 tab_contents()->GetRenderProcessHost()->id(), |
| 866 routing_id(), | 863 routing_id(), |
| 867 save_item->save_source(), | 864 save_item->save_source(), |
| 868 save_item->full_path(), | 865 save_item->full_path(), |
| 869 request_context_getter_.get(), | 866 tab_contents()->profile()->GetResourceContext(), |
| 870 this); | 867 this); |
| 871 } while (process_all_remaining_items && waiting_item_queue_.size()); | 868 } while (process_all_remaining_items && waiting_item_queue_.size()); |
| 872 } | 869 } |
| 873 | 870 |
| 874 | 871 |
| 875 // Open download page in windows explorer on file thread, to avoid blocking the | 872 // Open download page in windows explorer on file thread, to avoid blocking the |
| 876 // user interface. | 873 // user interface. |
| 877 void SavePackage::ShowDownloadInShell() { | 874 void SavePackage::ShowDownloadInShell() { |
| 878 DCHECK(file_manager_); | 875 DCHECK(file_manager_); |
| 879 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); | 876 DCHECK(finished_ && !canceled() && !saved_main_file_path_.empty()); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 } | 1462 } |
| 1466 | 1463 |
| 1467 // SelectFileDialog::Listener interface. | 1464 // SelectFileDialog::Listener interface. |
| 1468 void SavePackage::FileSelected(const FilePath& path, | 1465 void SavePackage::FileSelected(const FilePath& path, |
| 1469 int index, void* params) { | 1466 int index, void* params) { |
| 1470 ContinueSave(path, index); | 1467 ContinueSave(path, index); |
| 1471 } | 1468 } |
| 1472 | 1469 |
| 1473 void SavePackage::FileSelectionCanceled(void* params) { | 1470 void SavePackage::FileSelectionCanceled(void* params) { |
| 1474 } | 1471 } |
| OLD | NEW |