| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |