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

Unified Diff: chrome/installer/mac/app/Downloader.m

Issue 2148293005: Migrate mac installer to delegate-driven model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last patch before CQ Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/mac/app/Downloader.h ('k') | chrome/installer/mac/app/MainDelegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/mac/app/Downloader.m
diff --git a/chrome/installer/mac/app/Downloader.m b/chrome/installer/mac/app/Downloader.m
index 857897ab934878287b7b4e8a1c2d97d1619445b7..25490da04a21c8289c1fe3a6dbe42049eb0b1cdd 100644
--- a/chrome/installer/mac/app/Downloader.m
+++ b/chrome/installer/mac/app/Downloader.m
@@ -2,15 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import <Foundation/Foundation.h>
-
-#import "DownloadDelegate.h"
#import "Downloader.h"
+
+#include <assert.h>
+
#import "NetworkCommunication.h"
#import "OmahaXMLParser.h"
@implementation Downloader
+@synthesize delegate = delegate_;
+
// TODO: make this overrideable with commandline argument? or enviro variable
+ (NSString*)getDownloadsFilePath {
NSArray* downloadPaths = NSSearchPathForDirectoriesInDomains(
@@ -59,9 +61,8 @@
// Downloads contents of chromeURL to downloads folders and delegates the work
// to the DownloadDelegate class.
- (BOOL)writeChromeImageToDownloadsDirectory:(NSURL*)chromeURL {
- DownloadDelegate* delegate = [[DownloadDelegate alloc] init];
NetworkCommunication* downloadTask =
- [[NetworkCommunication alloc] initWithDelegate:delegate];
+ [[NetworkCommunication alloc] initWithDelegate:self];
// TODO: What if file already exists?
[downloadTask createRequestWithUrlAsString:[chromeURL absoluteString]
@@ -81,4 +82,37 @@
return writeWasSuccessful;
}
+// Skeleton of delegate method to provide download progress updates.
+// TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100
+// to generate download progress percentage.
+- (void)URLSession:(NSURLSession*)session
+ downloadTask:(NSURLSessionDownloadTask*)downloadTask
+ didWriteData:(int64_t)bytesWritten
+ totalBytesWritten:(int64_t)totalBytesWritten
+ totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
+}
+
+// Delegate method to move downloaded disk image to user's Download directory.
+- (void)URLSession:(NSURLSession*)session
+ downloadTask:(NSURLSessionDownloadTask*)downloadTask
+ didFinishDownloadingToURL:(NSURL*)location {
+ assert([location isFileURL]);
+ NSFileManager* manager = [[NSFileManager alloc] init];
+ NSURL* downloadsDirectory =
+ [[NSURL alloc] initFileURLWithPath:[Downloader getDownloadsFilePath]];
+ if ([manager fileExistsAtPath:location.path]) {
+ [manager moveItemAtURL:location toURL:downloadsDirectory error:nil];
+ } else {
+ // TODO: Error Handling
+ }
+}
+
+- (void)URLSession:(NSURLSession*)session
+ task:(NSURLSessionTask*)task
+ didCompleteWithError:(NSError*)error {
+ // TODO: Error Handling
+
+ [delegate_ onDownloadSuccess];
+}
+
@end
« no previous file with comments | « chrome/installer/mac/app/Downloader.h ('k') | chrome/installer/mac/app/MainDelegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698