| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void DownloadItemMac::OnDownloadDestroyed(content::DownloadItem* download) { | 65 void DownloadItemMac::OnDownloadDestroyed(content::DownloadItem* download) { |
| 66 [item_controller_ remove]; // We're deleted now! | 66 [item_controller_ remove]; // We're deleted now! |
| 67 } | 67 } |
| 68 | 68 |
| 69 void DownloadItemMac::OnDownloadOpened(content::DownloadItem* download) { | 69 void DownloadItemMac::OnDownloadOpened(content::DownloadItem* download) { |
| 70 DCHECK_EQ(download, download_model_.download()); | 70 DCHECK_EQ(download, download_model_.download()); |
| 71 [item_controller_ downloadWasOpened]; | 71 [item_controller_ downloadWasOpened]; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void DownloadItemMac::OnDownloadShown(content::DownloadItem* download) { |
| 75 DCHECK_EQ(download, download_model_.download()); |
| 76 [item_controller_ downloadWasShown]; |
| 77 } |
| 78 |
| 74 void DownloadItemMac::LoadIcon() { | 79 void DownloadItemMac::LoadIcon() { |
| 75 IconManager* icon_manager = g_browser_process->icon_manager(); | 80 IconManager* icon_manager = g_browser_process->icon_manager(); |
| 76 if (!icon_manager) { | 81 if (!icon_manager) { |
| 77 NOTREACHED(); | 82 NOTREACHED(); |
| 78 return; | 83 return; |
| 79 } | 84 } |
| 80 | 85 |
| 81 // We may already have this particular image cached. | 86 // We may already have this particular image cached. |
| 82 base::FilePath file = download_model_.download()->GetTargetFilePath(); | 87 base::FilePath file = download_model_.download()->GetTargetFilePath(); |
| 83 gfx::Image* icon = icon_manager->LookupIconFromFilepath( | 88 gfx::Image* icon = icon_manager->LookupIconFromFilepath( |
| 84 file, IconLoader::ALL); | 89 file, IconLoader::ALL); |
| 85 if (icon) { | 90 if (icon) { |
| 86 [item_controller_ setIcon:icon->ToNSImage()]; | 91 [item_controller_ setIcon:icon->ToNSImage()]; |
| 87 return; | 92 return; |
| 88 } | 93 } |
| 89 | 94 |
| 90 // The icon isn't cached, load it asynchronously. | 95 // The icon isn't cached, load it asynchronously. |
| 91 icon_manager->LoadIcon(file, | 96 icon_manager->LoadIcon(file, |
| 92 IconLoader::ALL, | 97 IconLoader::ALL, |
| 93 base::Bind(&DownloadItemMac::OnExtractIconComplete, | 98 base::Bind(&DownloadItemMac::OnExtractIconComplete, |
| 94 base::Unretained(this)), | 99 base::Unretained(this)), |
| 95 &cancelable_task_tracker_); | 100 &cancelable_task_tracker_); |
| 96 } | 101 } |
| 97 | 102 |
| 98 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { | 103 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { |
| 99 if (!icon) | 104 if (!icon) |
| 100 return; | 105 return; |
| 101 [item_controller_ setIcon:icon->ToNSImage()]; | 106 [item_controller_ setIcon:icon->ToNSImage()]; |
| 102 } | 107 } |
| OLD | NEW |