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

Side by Side Diff: chrome/browser/extensions/webstore_installer.cc

Issue 11068027: OnDownloadStarted takes DownloadItem* instead of DownloadId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r160830 Created 8 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/webstore_installer.h" 5 #include "chrome/browser/extensions/webstore_installer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 27 matching lines...) Expand all
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
40 #include "net/base/escape.h" 40 #include "net/base/escape.h"
41 41
42 #if defined(OS_CHROMEOS) 42 #if defined(OS_CHROMEOS)
43 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" 43 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h"
44 #endif 44 #endif
45 45
46 using content::BrowserContext; 46 using content::BrowserContext;
47 using content::BrowserThread; 47 using content::BrowserThread;
48 using content::DownloadId;
49 using content::DownloadItem; 48 using content::DownloadItem;
50 using content::DownloadManager; 49 using content::DownloadManager;
51 using content::NavigationController; 50 using content::NavigationController;
52 using content::DownloadUrlParameters; 51 using content::DownloadUrlParameters;
53 52
54 namespace { 53 namespace {
55 54
56 // Key used to attach the Approval to the DownloadItem. 55 // Key used to attach the Approval to the DownloadItem.
57 const char kApprovalKey[] = "extensions.webstore_installer"; 56 const char kApprovalKey[] = "extensions.webstore_installer";
58 57
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 g_download_directory_for_tests = directory; 271 g_download_directory_for_tests = directory;
273 } 272 }
274 273
275 WebstoreInstaller::~WebstoreInstaller() { 274 WebstoreInstaller::~WebstoreInstaller() {
276 if (download_item_) { 275 if (download_item_) {
277 download_item_->RemoveObserver(this); 276 download_item_->RemoveObserver(this);
278 download_item_ = NULL; 277 download_item_ = NULL;
279 } 278 }
280 } 279 }
281 280
282 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) { 281 void WebstoreInstaller::OnDownloadStarted(
283 if (error != net::OK) { 282 DownloadItem* item, net::Error error) {
283 if (!item) {
284 DCHECK_NE(net::OK, error);
284 ReportFailure(net::ErrorToString(error), FAILURE_REASON_OTHER); 285 ReportFailure(net::ErrorToString(error), FAILURE_REASON_OTHER);
285 return; 286 return;
286 } 287 }
287 288
288 CHECK(id.IsValid()); 289 DCHECK_EQ(net::OK, error);
289 290 download_item_ = item;
290 DownloadManager* download_manager = 291 download_item_->AddObserver(this);
291 BrowserContext::GetDownloadManager(profile_); 292 if (approval_.get())
292 if (!download_manager) 293 download_item_->SetUserData(kApprovalKey, approval_.release());
293 return; 294 if (delegate_)
294 download_item_ = download_manager->GetDownload(id.local()); 295 delegate_->OnExtensionDownloadStarted(id_, download_item_);
295 // TODO(benjhayden): DCHECK(item && item->IsInProgress()) after investigating
296 // the relationship between net::OK and invalid id.
297 if (download_item_) {
298 download_item_->AddObserver(this);
299 if (approval_.get())
300 download_item_->SetUserData(kApprovalKey, approval_.release());
301 if (delegate_)
302 delegate_->OnExtensionDownloadStarted(id_, download_item_);
303 }
304 } 296 }
305 297
306 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) { 298 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) {
307 CHECK_EQ(download_item_, download); 299 CHECK_EQ(download_item_, download);
308 300
309 switch (download->GetState()) { 301 switch (download->GetState()) {
310 case DownloadItem::CANCELLED: 302 case DownloadItem::CANCELLED:
311 ReportFailure(kDownloadCanceledError, FAILURE_REASON_CANCELLED); 303 ReportFailure(kDownloadCanceledError, FAILURE_REASON_CANCELLED);
312 break; 304 break;
313 case DownloadItem::INTERRUPTED: 305 case DownloadItem::INTERRUPTED:
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 void WebstoreInstaller::ReportSuccess() { 377 void WebstoreInstaller::ReportSuccess() {
386 if (delegate_) { 378 if (delegate_) {
387 delegate_->OnExtensionInstallSuccess(id_); 379 delegate_->OnExtensionInstallSuccess(id_);
388 delegate_ = NULL; 380 delegate_ = NULL;
389 } 381 }
390 382
391 Release(); // Balanced in Start(). 383 Release(); // Balanced in Start().
392 } 384 }
393 385
394 } // namespace extensions 386 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_installer.h ('k') | chrome/browser/plugins/plugin_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698