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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #import <Foundation/Foundation.h> 5 #import "Downloader.h"
6 6
7 #import "DownloadDelegate.h" 7 #include <assert.h>
8 #import "Downloader.h" 8
9 #import "NetworkCommunication.h" 9 #import "NetworkCommunication.h"
10 #import "OmahaXMLParser.h" 10 #import "OmahaXMLParser.h"
11 11
12 @implementation Downloader 12 @implementation Downloader
13 13
14 @synthesize delegate = delegate_;
15
14 // TODO: make this overrideable with commandline argument? or enviro variable 16 // TODO: make this overrideable with commandline argument? or enviro variable
15 + (NSString*)getDownloadsFilePath { 17 + (NSString*)getDownloadsFilePath {
16 NSArray* downloadPaths = NSSearchPathForDirectoriesInDomains( 18 NSArray* downloadPaths = NSSearchPathForDirectoriesInDomains(
17 NSDownloadsDirectory, NSUserDomainMask, YES); 19 NSDownloadsDirectory, NSUserDomainMask, YES);
18 NSString* filePathToDownloads = [downloadPaths objectAtIndex:0]; 20 NSString* filePathToDownloads = [downloadPaths objectAtIndex:0];
19 NSArray* filenameComposition = @[ filePathToDownloads, @"GoogleChrome.dmg" ]; 21 NSArray* filenameComposition = @[ filePathToDownloads, @"GoogleChrome.dmg" ];
20 NSString* completeFilePath = 22 NSString* completeFilePath =
21 [NSString pathWithComponents:filenameComposition]; 23 [NSString pathWithComponents:filenameComposition];
22 return completeFilePath; 24 return completeFilePath;
23 } 25 }
(...skipping 28 matching lines...) Expand all
52 NSMutableArray* completeURLs = 54 NSMutableArray* completeURLs =
53 [self appendFilename:parser.chromeImageFilename toURLs:incompleteURLs]; 55 [self appendFilename:parser.chromeImageFilename toURLs:incompleteURLs];
54 56
55 NSURL* chromeURL = [completeURLs firstObject]; 57 NSURL* chromeURL = [completeURLs firstObject];
56 return chromeURL; 58 return chromeURL;
57 } 59 }
58 60
59 // Downloads contents of chromeURL to downloads folders and delegates the work 61 // Downloads contents of chromeURL to downloads folders and delegates the work
60 // to the DownloadDelegate class. 62 // to the DownloadDelegate class.
61 - (BOOL)writeChromeImageToDownloadsDirectory:(NSURL*)chromeURL { 63 - (BOOL)writeChromeImageToDownloadsDirectory:(NSURL*)chromeURL {
62 DownloadDelegate* delegate = [[DownloadDelegate alloc] init];
63 NetworkCommunication* downloadTask = 64 NetworkCommunication* downloadTask =
64 [[NetworkCommunication alloc] initWithDelegate:delegate]; 65 [[NetworkCommunication alloc] initWithDelegate:self];
65 66
66 // TODO: What if file already exists? 67 // TODO: What if file already exists?
67 [downloadTask createRequestWithUrlAsString:[chromeURL absoluteString] 68 [downloadTask createRequestWithUrlAsString:[chromeURL absoluteString]
68 andXMLBody:nil]; 69 andXMLBody:nil];
69 [downloadTask sendDownloadRequest]; 70 [downloadTask sendDownloadRequest];
70 71
71 NSFileManager* manager = [[NSFileManager alloc] init]; 72 NSFileManager* manager = [[NSFileManager alloc] init];
72 return [manager fileExistsAtPath:[Downloader getDownloadsFilePath]]; 73 return [manager fileExistsAtPath:[Downloader getDownloadsFilePath]];
73 } 74 }
74 75
75 // Pieces together the getting the URL portion and downloading the contents of 76 // Pieces together the getting the URL portion and downloading the contents of
76 // URL portion. 77 // URL portion.
77 - (BOOL)downloadChromeImageToDownloadsDirectory:(NSData*)omahaResponseXML { 78 - (BOOL)downloadChromeImageToDownloadsDirectory:(NSData*)omahaResponseXML {
78 NSURL* chromeURL = [self getChromeImageURLFromOmahaResponse:omahaResponseXML]; 79 NSURL* chromeURL = [self getChromeImageURLFromOmahaResponse:omahaResponseXML];
79 BOOL writeWasSuccessful = 80 BOOL writeWasSuccessful =
80 [self writeChromeImageToDownloadsDirectory:chromeURL]; 81 [self writeChromeImageToDownloadsDirectory:chromeURL];
81 return writeWasSuccessful; 82 return writeWasSuccessful;
82 } 83 }
83 84
85 // Skeleton of delegate method to provide download progress updates.
86 // TODO: Make use of (totalBytesWritten/totalBytesExpectedToWrite)*100
87 // to generate download progress percentage.
88 - (void)URLSession:(NSURLSession*)session
89 downloadTask:(NSURLSessionDownloadTask*)downloadTask
90 didWriteData:(int64_t)bytesWritten
91 totalBytesWritten:(int64_t)totalBytesWritten
92 totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
93 }
94
95 // Delegate method to move downloaded disk image to user's Download directory.
96 - (void)URLSession:(NSURLSession*)session
97 downloadTask:(NSURLSessionDownloadTask*)downloadTask
98 didFinishDownloadingToURL:(NSURL*)location {
99 assert([location isFileURL]);
100 NSFileManager* manager = [[NSFileManager alloc] init];
101 NSURL* downloadsDirectory =
102 [[NSURL alloc] initFileURLWithPath:[Downloader getDownloadsFilePath]];
103 if ([manager fileExistsAtPath:location.path]) {
104 [manager moveItemAtURL:location toURL:downloadsDirectory error:nil];
105 } else {
106 // TODO: Error Handling
107 }
108 }
109
110 - (void)URLSession:(NSURLSession*)session
111 task:(NSURLSessionTask*)task
112 didCompleteWithError:(NSError*)error {
113 // TODO: Error Handling
114
115 [delegate_ onDownloadSuccess];
116 }
117
84 @end 118 @end
OLDNEW
« 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