Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Side by Side Diff: chrome/browser/ui/cocoa/download/download_item_mac.mm

Issue 11673004: No need to pass DownloadItemModel ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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(DownloadItem* download,
19 DownloadItemController* controller) 19 DownloadItemController* controller)
20 : download_model_(download_model), item_controller_(controller) { 20 : download_model_(download),
21 download_model_->download()->AddObserver(this); 21 item_controller_(controller) {
22 download_model_.download()->AddObserver(this);
22 } 23 }
23 24
24 DownloadItemMac::~DownloadItemMac() { 25 DownloadItemMac::~DownloadItemMac() {
25 download_model_->download()->RemoveObserver(this); 26 download_model_.download()->RemoveObserver(this);
26 } 27 }
27 28
28 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { 29 void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) {
29 DCHECK_EQ(download, download_model_->download()); 30 DCHECK_EQ(download, download_model_.download());
30 31
31 if ([item_controller_ isDangerousMode] && !download_model_->IsDangerous()) { 32 if ([item_controller_ isDangerousMode] && !download_model_.IsDangerous()) {
32 // We have been approved. 33 // We have been approved.
33 [item_controller_ clearDangerousMode]; 34 [item_controller_ clearDangerousMode];
34 } 35 }
35 36
36 if (download->GetUserVerifiedFilePath() != lastFilePath_) { 37 if (download->GetUserVerifiedFilePath() != lastFilePath_) {
37 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous 38 // Turns out the file path is "Unconfirmed %d.crdownload" for dangerous
38 // downloads. When the download is confirmed, the file is renamed on 39 // downloads. When the download is confirmed, the file is renamed on
39 // another thread, so reload the icon if the download filename changes. 40 // another thread, so reload the icon if the download filename changes.
40 LoadIcon(); 41 LoadIcon();
41 lastFilePath_ = download->GetUserVerifiedFilePath(); 42 lastFilePath_ = download->GetUserVerifiedFilePath();
42 43
43 [item_controller_ updateToolTip]; 44 [item_controller_ updateToolTip];
44 } 45 }
45 46
46 switch (download->GetState()) { 47 switch (download->GetState()) {
47 case DownloadItem::COMPLETE: 48 case DownloadItem::COMPLETE:
48 if (download->GetAutoOpened()) { 49 if (download->GetAutoOpened()) {
49 [item_controller_ remove]; // We're deleted now! 50 [item_controller_ remove]; // We're deleted now!
50 return; 51 return;
51 } 52 }
52 // fall through 53 // fall through
53 case DownloadItem::IN_PROGRESS: 54 case DownloadItem::IN_PROGRESS:
54 case DownloadItem::CANCELLED: 55 case DownloadItem::CANCELLED:
55 [item_controller_ setStateFromDownload:download_model_.get()]; 56 [item_controller_ setStateFromDownload:&download_model_];
56 break; 57 break;
57 case DownloadItem::INTERRUPTED: 58 case DownloadItem::INTERRUPTED:
58 [item_controller_ updateToolTip]; 59 [item_controller_ updateToolTip];
59 [item_controller_ setStateFromDownload:download_model_.get()]; 60 [item_controller_ setStateFromDownload:&download_model_];
60 break; 61 break;
61 default: 62 default:
62 NOTREACHED(); 63 NOTREACHED();
63 } 64 }
64 } 65 }
65 66
66 void DownloadItemMac::OnDownloadDestroyed(content::DownloadItem* download) { 67 void DownloadItemMac::OnDownloadDestroyed(content::DownloadItem* download) {
67 [item_controller_ remove]; // We're deleted now! 68 [item_controller_ remove]; // We're deleted now!
68 } 69 }
69 70
70 void DownloadItemMac::OnDownloadOpened(content::DownloadItem* download) { 71 void DownloadItemMac::OnDownloadOpened(content::DownloadItem* download) {
71 DCHECK_EQ(download, download_model_->download()); 72 DCHECK_EQ(download, download_model_.download());
72 [item_controller_ downloadWasOpened]; 73 [item_controller_ downloadWasOpened];
73 } 74 }
74 75
75 void DownloadItemMac::LoadIcon() { 76 void DownloadItemMac::LoadIcon() {
76 IconManager* icon_manager = g_browser_process->icon_manager(); 77 IconManager* icon_manager = g_browser_process->icon_manager();
77 if (!icon_manager) { 78 if (!icon_manager) {
78 NOTREACHED(); 79 NOTREACHED();
79 return; 80 return;
80 } 81 }
81 82
82 // We may already have this particular image cached. 83 // We may already have this particular image cached.
83 FilePath file = download_model_->download()->GetUserVerifiedFilePath(); 84 FilePath file = download_model_.download()->GetUserVerifiedFilePath();
84 gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::ALL); 85 gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::ALL);
85 if (icon) { 86 if (icon) {
86 [item_controller_ setIcon:icon->ToNSImage()]; 87 [item_controller_ setIcon:icon->ToNSImage()];
87 return; 88 return;
88 } 89 }
89 90
90 // The icon isn't cached, load it asynchronously. 91 // The icon isn't cached, load it asynchronously.
91 icon_manager->LoadIcon(file, 92 icon_manager->LoadIcon(file,
92 IconLoader::ALL, 93 IconLoader::ALL,
93 base::Bind(&DownloadItemMac::OnExtractIconComplete, 94 base::Bind(&DownloadItemMac::OnExtractIconComplete,
94 base::Unretained(this)), 95 base::Unretained(this)),
95 &cancelable_task_tracker_); 96 &cancelable_task_tracker_);
96 } 97 }
97 98
98 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) { 99 void DownloadItemMac::OnExtractIconComplete(gfx::Image* icon) {
99 if (!icon) 100 if (!icon)
100 return; 101 return;
101 [item_controller_ setIcon:icon->ToNSImage()]; 102 [item_controller_ setIcon:icon->ToNSImage()];
102 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698