Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/extensions/api/recovery_private/write_from_url_operation.cc

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/recovery_private/error_messages.h" 8 #include "chrome/browser/extensions/api/recovery_private/error_messages.h"
9 #include "chrome/browser/extensions/api/recovery_private/recovery_operation_mana ger.h" 9 #include "chrome/browser/extensions/api/recovery_private/recovery_operation_mana ger.h"
10 #include "chrome/browser/extensions/api/recovery_private/write_from_url_operatio n.h" 10 #include "chrome/browser/extensions/api/recovery_private/write_from_url_operatio n.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 download_params->set_callback( 115 download_params->set_callback(
116 base::Bind(&WriteFromUrlOperation::OnDownloadStarted, this)); 116 base::Bind(&WriteFromUrlOperation::OnDownloadStarted, this));
117 117
118 content::DownloadManager* download_manager = 118 content::DownloadManager* download_manager =
119 content::BrowserContext::GetDownloadManager(current_profile); 119 content::BrowserContext::GetDownloadManager(current_profile);
120 download_manager->DownloadUrl(download_params.Pass()); 120 download_manager->DownloadUrl(download_params.Pass());
121 } 121 }
122 122
123 void WriteFromUrlOperation::OnDownloadStarted(content::DownloadItem* item, 123 void WriteFromUrlOperation::OnDownloadStarted(
124 net::Error error) { 124 content::DownloadItem* item,
125 content::DownloadInterruptReason interrupt_reason) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 if (item) { 127 if (item) {
127 DCHECK_EQ(net::OK, error); 128 DCHECK_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
128 129
129 download_ = item; 130 download_ = item;
130 download_->AddObserver(this); 131 download_->AddObserver(this);
131 132
132 // Run at least once. 133 // Run at least once.
133 OnDownloadUpdated(download_); 134 OnDownloadUpdated(download_);
134 } else { 135 } else {
135 DCHECK_NE(net::OK, error); 136 DCHECK_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
136 std::string error_message = ErrorUtils::FormatErrorMessage( 137 std::string error_message = ErrorUtils::FormatErrorMessage(
137 "Download failed: *", 138 "Download failed: *",
138 net::ErrorToString(error)); 139 content::DownloadInterruptReasonToString(interrupt_reason));
139 Error(error_message); 140 Error(error_message);
140 } 141 }
141 } 142 }
142 143
143 // Always called from the UI thread. 144 // Always called from the UI thread.
144 void WriteFromUrlOperation::OnDownloadUpdated( 145 void WriteFromUrlOperation::OnDownloadUpdated(
145 content::DownloadItem* download) { 146 content::DownloadItem* download) {
146 147
147 if (IsCancelled()) { 148 if (IsCancelled()) {
148 download->Cancel(false); 149 download->Cancel(false);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 progress_ = 100; 243 progress_ = 100;
243 SendProgress(); 244 SendProgress();
244 245
245 scoped_ptr<base::FilePath> download_path(new base::FilePath(download_path_)); 246 scoped_ptr<base::FilePath> download_path(new base::FilePath(download_path_));
246 UnzipStart(download_path.Pass()); 247 UnzipStart(download_path.Pass());
247 } 248 }
248 249
249 } // namespace recovery 250 } // namespace recovery
250 } // namespace extensions 251 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698