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

Side by Side Diff: chrome/browser/download/download_status_updater_mac.mm

Issue 10831340: Bulletproof download status update code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/download/download_status_updater.h" 5 #include "chrome/browser/download/download_status_updater.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/memory/scoped_nsobject.h" 8 #include "base/memory/scoped_nsobject.h"
9 #include "base/supports_user_data.h" 9 #include "base/supports_user_data.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (!result) { 68 if (!result) {
69 NSString** ref = static_cast<NSString**>( 69 NSString** ref = static_cast<NSString**>(
70 CFBundleGetDataPointerForName(foundation, 70 CFBundleGetDataPointerForName(foundation,
71 base::mac::NSToCFCast(string))); 71 base::mac::NSToCFCast(string)));
72 if (ref) { 72 if (ref) {
73 result = *ref; 73 result = *ref;
74 [cache setObject:result forKey:string]; 74 [cache setObject:result forKey:string];
75 } 75 }
76 } 76 }
77 77
78 if (!result) {
79 // Huh. At least return a local copy of the expected string.
80 result = string;
81 if ([result hasSuffix:@"Key"])
82 result = [result substringToIndex:[result length] - 3];
Robert Sesek 2012/08/16 15:30:29 Pull @"Key" into a local so you don't have to coun
Avi (use Gerrit) 2012/08/16 15:41:42 Done.
83 }
84
78 return result; 85 return result;
79 } 86 }
80 87
81 } // namespace 88 } // namespace
82 89
83 @interface NSProgress : NSObject 90 @interface NSProgress : NSObject
84 91
85 - (id)initWithParent:(id)parent userInfo:(NSDictionary*)info; 92 - (id)initWithParent:(id)parent userInfo:(NSDictionary*)info;
86 @property(copy) NSString* kind; 93 @property(copy) NSString* kind;
87 94
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 float progress) { 175 float progress) {
169 DockIcon* dock_icon = [DockIcon sharedDockIcon]; 176 DockIcon* dock_icon = [DockIcon sharedDockIcon];
170 [dock_icon setDownloads:download_count]; 177 [dock_icon setDownloads:download_count];
171 [dock_icon setIndeterminate:!progress_known]; 178 [dock_icon setIndeterminate:!progress_known];
172 [dock_icon setProgress:progress]; 179 [dock_icon setProgress:progress];
173 [dock_icon updateIcon]; 180 [dock_icon updateIcon];
174 } 181 }
175 182
176 void CreateNSProgress(content::DownloadItem* download) { 183 void CreateNSProgress(content::DownloadItem* download) {
177 NSURL* source_url = [NSURL URLWithString: 184 NSURL* source_url = [NSURL URLWithString:
178 base::SysUTF8ToNSString(download->GetURL().spec())]; 185 base::SysUTF8ToNSString(download->GetURL().possibly_invalid_spec())];
179 FilePath destination_path = download->GetFullPath(); 186 FilePath destination_path = download->GetFullPath();
180 NSURL* destination_url = [NSURL fileURLWithPath: 187 NSURL* destination_url = [NSURL fileURLWithPath:
181 base::mac::FilePathToNSString(destination_path)]; 188 base::mac::FilePathToNSString(destination_path)];
182 189
183 // If there were an image to fly to the download folder in the dock, then 190 // If there were an image to fly to the download folder in the dock, then
184 // the keys in the userInfo to set would be: 191 // the keys in the userInfo to set would be:
185 // - @"NSProgressFlyToImageKey" : NSImage 192 // - @"NSProgressFlyToImageKey" : NSImage
186 // - kNSProgressFileIconOriginalRectKey : NSValue of NSRect in global coords 193 // - kNSProgressFileIconOriginalRectKey : NSValue of NSRect in global coords
187 194
188 NSDictionary* user_info = @{ 195 NSDictionary* user_info = @{
189 ProgressString(kNSProgressFileDownloadingSourceURLKey) : source_url,
190 ProgressString(kNSProgressFileLocationCanChangeKey) : @true, 196 ProgressString(kNSProgressFileLocationCanChangeKey) : @true,
191 ProgressString(kNSProgressFileOperationKindKey) : 197 ProgressString(kNSProgressFileOperationKindKey) :
192 ProgressString(kNSProgressFileOperationKindDownloading), 198 ProgressString(kNSProgressFileOperationKindDownloading),
Robert Sesek 2012/08/16 15:30:29 nit: this should be indented 2 more
Avi (use Gerrit) 2012/08/16 15:41:42 Done.
193 ProgressString(kNSProgressFileURLKey) : destination_url 199 ProgressString(kNSProgressFileURLKey) : destination_url
194 }; 200 };
201
195 Class progress_class = NSClassFromString(@"NSProgress"); 202 Class progress_class = NSClassFromString(@"NSProgress");
196 NSProgress* progress = [progress_class performSelector:@selector(alloc)]; 203 NSProgress* progress = [progress_class performSelector:@selector(alloc)];
197 progress = [progress performSelector:@selector(initWithParent:userInfo:) 204 progress = [progress performSelector:@selector(initWithParent:userInfo:)
198 withObject:nil 205 withObject:nil
199 withObject:user_info]; 206 withObject:user_info];
200 progress.kind = ProgressString(kNSProgressKindFile); 207 progress.kind = ProgressString(kNSProgressKindFile);
201 208
209 if (source_url) {
210 [progress setUserInfoObject:source_url forKey:
211 ProgressString(kNSProgressFileDownloadingSourceURLKey)];
212 }
213
202 progress.pausable = NO; 214 progress.pausable = NO;
203 progress.cancellable = YES; 215 progress.cancellable = YES;
204 [progress setCancellationHandler:^{ 216 [progress setCancellationHandler:^{
205 dispatch_async(dispatch_get_main_queue(), ^{ 217 dispatch_async(dispatch_get_main_queue(), ^{
206 download->Cancel(true); 218 download->Cancel(true);
207 }); 219 });
208 }]; 220 }];
209 221
210 progress.totalUnitCount = download->GetTotalBytes(); 222 progress.totalUnitCount = download->GetTotalBytes();
211 progress.completedUnitCount = download->GetReceivedBytes(); 223 progress.completedUnitCount = download->GetReceivedBytes();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 290 }
279 291
280 // Notify the Finder. 292 // Notify the Finder.
281 NSString* parent_path = [download_path stringByDeletingLastPathComponent]; 293 NSString* parent_path = [download_path stringByDeletingLastPathComponent];
282 FNNotifyByPath( 294 FNNotifyByPath(
283 reinterpret_cast<const UInt8*>([parent_path fileSystemRepresentation]), 295 reinterpret_cast<const UInt8*>([parent_path fileSystemRepresentation]),
284 kFNDirectoryModifiedMessage, 296 kFNDirectoryModifiedMessage,
285 kNilOptions); 297 kNilOptions);
286 } 298 }
287 } 299 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698