| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::LoadIcon() { | 74 void DownloadItemMac::LoadIcon() { |
| 75 IconManager* icon_manager = g_browser_process->icon_manager(); | 75 IconManager* icon_manager = g_browser_process->icon_manager(); |
| 76 if (!icon_manager) { | 76 if (!icon_manager) |
| 77 NOTREACHED(); | |
| 78 return; | 77 return; |
| 79 } | |
| 80 | 78 |
| 81 // We may already have this particular image cached. | 79 // We may already have this particular image cached. |
| 82 base::FilePath file = download_model_.download()->GetTargetFilePath(); | 80 base::FilePath file = download_model_.download()->GetTargetFilePath(); |
| 83 gfx::Image* icon = icon_manager->LookupIconFromFilepath( | 81 gfx::Image* icon = icon_manager->LookupIconFromFilepath( |
| 84 file, IconLoader::ALL); | 82 file, IconLoader::ALL); |
| 85 if (icon) { | 83 if (icon) { |
| 86 [item_controller_ setIcon:icon->ToNSImage()]; | 84 [item_controller_ setIcon:icon->ToNSImage()]; |
| 87 return; | 85 return; |
| 88 } | 86 } |
| 89 | 87 |
| 90 // The icon isn't cached, load it asynchronously. | 88 // The icon isn't cached, load it asynchronously. |
| 91 icon_manager->LoadIcon(file, | 89 icon_manager->LoadIcon(file, |
| 92 IconLoader::ALL, | 90 IconLoader::ALL, |
| 93 base::Bind(&DownloadItemMac::OnExtractIconComplete, | 91 base::Bind(&DownloadItemMac::OnExtractIconComplete, |
| 94 base::Unretained(this)), | 92 base::Unretained(this)), |
| 95 &cancelable_task_tracker_); | 93 &cancelable_task_tracker_); |
| 96 } | 94 } |
| 97 | 95 |
| 98 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { | 96 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { |
| 99 if (!icon) | 97 if (!icon) |
| 100 return; | 98 return; |
| 101 [item_controller_ setIcon:icon->ToNSImage()]; | 99 [item_controller_ setIcon:icon->ToNSImage()]; |
| 102 } | 100 } |
| OLD | NEW |