| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/threading/worker_pool.h" | 6 #include "base/threading/worker_pool.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | 9 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
| 10 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" | 10 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 download_params->set_callback( | 103 download_params->set_callback( |
| 104 base::Bind(&WriteFromUrlOperation::OnDownloadStarted, this)); | 104 base::Bind(&WriteFromUrlOperation::OnDownloadStarted, this)); |
| 105 | 105 |
| 106 content::DownloadManager* download_manager = | 106 content::DownloadManager* download_manager = |
| 107 content::BrowserContext::GetDownloadManager(current_profile); | 107 content::BrowserContext::GetDownloadManager(current_profile); |
| 108 download_manager->DownloadUrl(download_params.Pass()); | 108 download_manager->DownloadUrl(download_params.Pass()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void WriteFromUrlOperation::OnDownloadStarted(content::DownloadItem* item, | 111 void WriteFromUrlOperation::OnDownloadStarted( |
| 112 net::Error error) { | 112 content::DownloadItem* item, |
| 113 content::DownloadInterruptReason interrupt_reason) { |
| 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 114 | 115 |
| 115 if (download_stopped_) { | 116 if (download_stopped_) { |
| 116 // At this point DownloadCleanUp was called but the |download_| wasn't | 117 // At this point DownloadCleanUp was called but the |download_| wasn't |
| 117 // stored yet and still hasn't been cancelled. | 118 // stored yet and still hasn't been cancelled. |
| 118 item->Cancel(true); | 119 item->Cancel(true); |
| 119 return; | 120 return; |
| 120 } | 121 } |
| 121 | 122 |
| 122 if (item) { | 123 if (item) { |
| 123 DCHECK_EQ(net::OK, error); | 124 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 124 | 125 |
| 125 download_ = item; | 126 download_ = item; |
| 126 download_->AddObserver(this); | 127 download_->AddObserver(this); |
| 127 | 128 |
| 128 // Run at least once. | 129 // Run at least once. |
| 129 OnDownloadUpdated(download_); | 130 OnDownloadUpdated(download_); |
| 130 } else { | 131 } else { |
| 131 DCHECK_NE(net::OK, error); | 132 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); |
| 132 std::string error_message = ErrorUtils::FormatErrorMessage( | 133 std::string error_message = ErrorUtils::FormatErrorMessage( |
| 133 "Download failed: *", | 134 "Download failed: *", |
| 134 net::ErrorToString(error)); | 135 content::DownloadInterruptReasonToString(interrupt_reason)); |
| 135 Error(error_message); | 136 Error(error_message); |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 // Always called from the UI thread. | 140 // Always called from the UI thread. |
| 140 void WriteFromUrlOperation::OnDownloadUpdated(content::DownloadItem* download) { | 141 void WriteFromUrlOperation::OnDownloadUpdated(content::DownloadItem* download) { |
| 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 142 | 143 |
| 143 if (download_stopped_) { | 144 if (download_stopped_) { |
| 144 return; | 145 return; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 DVLOG(1) << "Download verification complete."; | 251 DVLOG(1) << "Download verification complete."; |
| 251 | 252 |
| 252 SetProgress(kProgressComplete); | 253 SetProgress(kProgressComplete); |
| 253 | 254 |
| 254 scoped_ptr<base::FilePath> download_path(new base::FilePath(download_path_)); | 255 scoped_ptr<base::FilePath> download_path(new base::FilePath(download_path_)); |
| 255 UnzipStart(download_path.Pass()); | 256 UnzipStart(download_path.Pass()); |
| 256 } | 257 } |
| 257 | 258 |
| 258 } // namespace image_writer | 259 } // namespace image_writer |
| 259 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |