| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { | 30 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { |
| 31 DCHECK_EQ(download, download_model_.download()); | 31 DCHECK_EQ(download, download_model_.download()); |
| 32 | 32 |
| 33 if ([item_controller_ isDangerousMode] && !download_model_.IsDangerous()) { | 33 if ([item_controller_ isDangerousMode] && !download_model_.IsDangerous()) { |
| 34 // We have been approved. | 34 // We have been approved. |
| 35 [item_controller_ clearDangerousMode]; | 35 [item_controller_ clearDangerousMode]; |
| 36 } | 36 } |
| 37 | 37 |
| 38 if (download->GetUserVerifiedFilePath() != lastFilePath_) { | 38 if (download->GetTargetFilePath() != lastFilePath_) { |
| 39 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous | |
| 40 // downloads. When the download is confirmed, the file is renamed on | |
| 41 // another thread, so reload the icon if the download filename changes. | |
| 42 LoadIcon(); | 39 LoadIcon(); |
| 43 lastFilePath_ = download->GetUserVerifiedFilePath(); | 40 lastFilePath_ = download->GetTargetFilePath(); |
| 44 | 41 |
| 45 [item_controller_ updateToolTip]; | 42 [item_controller_ updateToolTip]; |
| 46 } | 43 } |
| 47 | 44 |
| 48 switch (download->GetState()) { | 45 switch (download->GetState()) { |
| 49 case DownloadItem::COMPLETE: | 46 case DownloadItem::COMPLETE: |
| 50 if (download_model_.ShouldRemoveFromShelfWhenComplete()) { | 47 if (download_model_.ShouldRemoveFromShelfWhenComplete()) { |
| 51 [item_controller_ remove]; // We're deleted now! | 48 [item_controller_ remove]; // We're deleted now! |
| 52 return; | 49 return; |
| 53 } | 50 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 } | 72 } |
| 76 | 73 |
| 77 void DownloadItemMac::LoadIcon() { | 74 void DownloadItemMac::LoadIcon() { |
| 78 IconManager* icon_manager = g_browser_process->icon_manager(); | 75 IconManager* icon_manager = g_browser_process->icon_manager(); |
| 79 if (!icon_manager) { | 76 if (!icon_manager) { |
| 80 NOTREACHED(); | 77 NOTREACHED(); |
| 81 return; | 78 return; |
| 82 } | 79 } |
| 83 | 80 |
| 84 // We may already have this particular image cached. | 81 // We may already have this particular image cached. |
| 85 base::FilePath file = download_model_.download()->GetUserVerifiedFilePath(); | 82 base::FilePath file = download_model_.download()->GetTargetFilePath(); |
| 86 gfx::Image* icon = icon_manager->LookupIconFromFilepath( | 83 gfx::Image* icon = icon_manager->LookupIconFromFilepath( |
| 87 file, IconLoader::ALL); | 84 file, IconLoader::ALL); |
| 88 if (icon) { | 85 if (icon) { |
| 89 [item_controller_ setIcon:icon->ToNSImage()]; | 86 [item_controller_ setIcon:icon->ToNSImage()]; |
| 90 return; | 87 return; |
| 91 } | 88 } |
| 92 | 89 |
| 93 // The icon isn't cached, load it asynchronously. | 90 // The icon isn't cached, load it asynchronously. |
| 94 icon_manager->LoadIcon(file, | 91 icon_manager->LoadIcon(file, |
| 95 IconLoader::ALL, | 92 IconLoader::ALL, |
| 96 base::Bind(&DownloadItemMac::OnExtractIconComplete, | 93 base::Bind(&DownloadItemMac::OnExtractIconComplete, |
| 97 base::Unretained(this)), | 94 base::Unretained(this)), |
| 98 &cancelable_task_tracker_); | 95 &cancelable_task_tracker_); |
| 99 } | 96 } |
| 100 | 97 |
| 101 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { | 98 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { |
| 102 if (!icon) | 99 if (!icon) |
| 103 return; | 100 return; |
| 104 [item_controller_ setIcon:icon->ToNSImage()]; | 101 [item_controller_ setIcon:icon->ToNSImage()]; |
| 105 } | 102 } |
| OLD | NEW |