| 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/ui/cocoa/download/download_item_mac.h" | 5 #include "chrome/browser/ui/cocoa/download/download_item_mac.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
| 10 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" | 10 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" |
| 11 #include "content/public/browser/download_item.h" | 11 #include "content/public/browser/download_item.h" |
| 12 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 13 | 13 |
| 14 using content::DownloadItem; | 14 using content::DownloadItem; |
| 15 | 15 |
| 16 // DownloadItemMac ------------------------------------------------------------- | 16 // DownloadItemMac ------------------------------------------------------------- |
| 17 | 17 |
| 18 DownloadItemMac::DownloadItemMac(DownloadItemModel* download_model, | 18 DownloadItemMac::DownloadItemMac(DownloadItemModel* download_model, |
| 19 DownloadItemController* controller) | 19 DownloadItemController* controller) |
| 20 : download_model_(download_model), item_controller_(controller) { | 20 : download_model_(download_model), item_controller_(controller) { |
| 21 download_model_->download()->AddObserver(this); | 21 download_model_->download()->AddObserver(this); |
| 22 } | 22 } |
| 23 | 23 |
| 24 DownloadItemMac::~DownloadItemMac() { | 24 DownloadItemMac::~DownloadItemMac() { |
| 25 download_model_->download()->RemoveObserver(this); | 25 download_model_->download()->RemoveObserver(this); |
| 26 icon_consumer_.CancelAllRequests(); | |
| 27 } | 26 } |
| 28 | 27 |
| 29 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { | 28 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { |
| 30 DCHECK_EQ(download, download_model_->download()); | 29 DCHECK_EQ(download, download_model_->download()); |
| 31 | 30 |
| 32 if ([item_controller_ isDangerousMode] && !download_model_->IsDangerous()) { | 31 if ([item_controller_ isDangerousMode] && !download_model_->IsDangerous()) { |
| 33 // We have been approved. | 32 // We have been approved. |
| 34 [item_controller_ clearDangerousMode]; | 33 [item_controller_ clearDangerousMode]; |
| 35 } | 34 } |
| 36 | 35 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 81 |
| 83 // We may already have this particular image cached. | 82 // We may already have this particular image cached. |
| 84 FilePath file = download_model_->download()->GetUserVerifiedFilePath(); | 83 FilePath file = download_model_->download()->GetUserVerifiedFilePath(); |
| 85 gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::ALL); | 84 gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::ALL); |
| 86 if (icon) { | 85 if (icon) { |
| 87 [item_controller_ setIcon:icon->ToNSImage()]; | 86 [item_controller_ setIcon:icon->ToNSImage()]; |
| 88 return; | 87 return; |
| 89 } | 88 } |
| 90 | 89 |
| 91 // The icon isn't cached, load it asynchronously. | 90 // The icon isn't cached, load it asynchronously. |
| 92 icon_manager->LoadIcon(file, IconLoader::ALL, &icon_consumer_, | 91 icon_manager->LoadIcon(file, |
| 92 IconLoader::ALL, |
| 93 base::Bind(&DownloadItemMac::OnExtractIconComplete, | 93 base::Bind(&DownloadItemMac::OnExtractIconComplete, |
| 94 base::Unretained(this))); | 94 base::Unretained(this)), |
| 95 &cancelable_task_tracker_); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void DownloadItemMac::OnExtractIconComplete(IconManager::Handle handle, | 98 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { |
| 98 gfx::Image* icon) { | |
| 99 if (!icon) | 99 if (!icon) |
| 100 return; | 100 return; |
| 101 [item_controller_ setIcon:icon->ToNSImage()]; | 101 [item_controller_ setIcon:icon->ToNSImage()]; |
| 102 } | 102 } |
| OLD | NEW |