OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/mac/sdk_forward_declarations.h" | 9 #include "base/mac/sdk_forward_declarations.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
11 #include "base/supports_user_data.h" | 12 #include "base/supports_user_data.h" |
12 #import "chrome/browser/ui/cocoa/dock_icon.h" | 13 #import "chrome/browser/ui/cocoa/dock_icon.h" |
13 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // These are not the keys themselves; they are the names for dynamic lookup via | 19 // These are not the keys themselves; they are the names for dynamic lookup via |
19 // the ProgressString() function. | 20 // the ProgressString() function. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 dispatch_async(dispatch_get_main_queue(), ^{ | 155 dispatch_async(dispatch_get_main_queue(), ^{ |
155 download->Cancel(true); | 156 download->Cancel(true); |
156 }); | 157 }); |
157 }]; | 158 }]; |
158 | 159 |
159 progress.totalUnitCount = download->GetTotalBytes(); | 160 progress.totalUnitCount = download->GetTotalBytes(); |
160 progress.completedUnitCount = download->GetReceivedBytes(); | 161 progress.completedUnitCount = download->GetReceivedBytes(); |
161 | 162 |
162 [progress publish]; | 163 [progress publish]; |
163 | 164 |
164 download->SetUserData(&kCrNSProgressUserDataKey, | 165 download->SetUserData( |
165 new CrNSProgressUserData(progress, destination_path)); | 166 &kCrNSProgressUserDataKey, |
| 167 base::MakeUnique<CrNSProgressUserData>(progress, destination_path)); |
166 } | 168 } |
167 | 169 |
168 void UpdateNSProgress(content::DownloadItem* download, | 170 void UpdateNSProgress(content::DownloadItem* download, |
169 CrNSProgressUserData* progress_data) { | 171 CrNSProgressUserData* progress_data) { |
170 NSProgress* progress = progress_data->progress(); | 172 NSProgress* progress = progress_data->progress(); |
171 progress.totalUnitCount = download->GetTotalBytes(); | 173 progress.totalUnitCount = download->GetTotalBytes(); |
172 progress.completedUnitCount = download->GetReceivedBytes(); | 174 progress.completedUnitCount = download->GetReceivedBytes(); |
173 [progress setUserInfoObject:@(download->CurrentSpeed()) | 175 [progress setUserInfoObject:@(download->CurrentSpeed()) |
174 forKey:ProgressString(kNSProgressThroughputKeyName)]; | 176 forKey:ProgressString(kNSProgressThroughputKeyName)]; |
175 | 177 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // Bounce the dock icon. | 240 // Bounce the dock icon. |
239 [[NSDistributedNotificationCenter defaultCenter] | 241 [[NSDistributedNotificationCenter defaultCenter] |
240 postNotificationName:@"com.apple.DownloadFileFinished" | 242 postNotificationName:@"com.apple.DownloadFileFinished" |
241 object:download_path]; | 243 object:download_path]; |
242 } | 244 } |
243 | 245 |
244 // Notify the Finder. | 246 // Notify the Finder. |
245 [[NSWorkspace sharedWorkspace] noteFileSystemChanged:download_path]; | 247 [[NSWorkspace sharedWorkspace] noteFileSystemChanged:download_path]; |
246 } | 248 } |
247 } | 249 } |
OLD | NEW |