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

Side by Side Diff: chrome/installer/mac/app/AppDelegate.m

Issue 2203583002: Added unpacking step (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added use of temporary folders, removed semaphore from main installer code, adjusted some files' APIs, resolved remaining comments Created 4 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
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 "AppDelegate.h" 5 #import "AppDelegate.h"
6 6
7 #import "Downloader.h"
7 #import "InstallerWindowController.h" 8 #import "InstallerWindowController.h"
8 #import "NSError+ChromeInstallerAdditions.h" 9 #import "NSError+ChromeInstallerAdditions.h"
9 #import "NSAlert+ChromeInstallerAdditions.h" 10 #import "NSAlert+ChromeInstallerAdditions.h"
11 #import "OmahaCommunication.h"
12 #import "Unpacker.h"
10 13
11 @interface NSAlert () 14 @interface NSAlert ()
12 - (void)beginSheetModalForWindow:(NSWindow*)sheetWindow 15 - (void)beginSheetModalForWindow:(NSWindow*)sheetWindow
13 completionHandler: 16 completionHandler:
14 (void (^__nullable)(NSModalResponse returnCode))handler; 17 (void (^__nullable)(NSModalResponse returnCode))handler;
15 @end 18 @end
16 19
17 @interface AppDelegate ()<OmahaCommunicationDelegate, DownloaderDelegate> { 20 @interface AppDelegate ()<OmahaCommunicationDelegate,
21 DownloaderDelegate,
22 UnpackDelegate> {
18 InstallerWindowController* installerWindowController_; 23 InstallerWindowController* installerWindowController_;
19 } 24 }
20 @property(strong) NSWindow* window; 25 @property(strong) NSWindow* window;
21 @end 26 @end
22 27
23 @implementation AppDelegate 28 @implementation AppDelegate
24 @synthesize window = window_; 29 @synthesize window = window_;
25 30
26 // Sets up the main window and begins the downloading process. 31 // Sets up the main window and begins the downloading process.
27 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { 32 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
(...skipping 10 matching lines...) Expand all
38 } 43 }
39 44
40 - (void)startDownload { 45 - (void)startDownload {
41 [installerWindowController_ updateStatusDescription:@"Initializing..."]; 46 [installerWindowController_ updateStatusDescription:@"Initializing..."];
42 OmahaCommunication* omahaMessenger = [[OmahaCommunication alloc] init]; 47 OmahaCommunication* omahaMessenger = [[OmahaCommunication alloc] init];
43 omahaMessenger.delegate = self; 48 omahaMessenger.delegate = self;
44 49
45 [omahaMessenger fetchDownloadURLs]; 50 [omahaMessenger fetchDownloadURLs];
46 } 51 }
47 52
48 - (void)onOmahaSuccessWithURLs:(NSArray*)URLs { 53 - (void)omahaCommunication:(OmahaCommunication*)messenger
54 onOmahaSuccessWithURLs:(NSArray*)URLs {
49 [installerWindowController_ updateStatusDescription:@"Downloading..."]; 55 [installerWindowController_ updateStatusDescription:@"Downloading..."];
50 Downloader* download = [[Downloader alloc] init]; 56 Downloader* download = [[Downloader alloc] init];
51 download.delegate = self; 57 download.delegate = self;
52 [download downloadChromeImageToDownloadsDirectory:[URLs firstObject]]; 58 [download downloadChromeImageFrom:[URLs firstObject]];
53 } 59 }
54 60
55 - (void)onOmahaFailureWithError:(NSError*)error { 61 - (void)omahaCommunication:(OmahaCommunication*)messenger
62 onOmahaFailureWithError:(NSError*)error {
56 NSError* networkError = 63 NSError* networkError =
57 [NSError errorForAlerts:@"Network Error" 64 [NSError errorForAlerts:@"Network Error"
58 withDescription:@"Could not connect to Chrome server." 65 withDescription:@"Could not connect to Chrome server."
59 isRecoverable:YES]; 66 isRecoverable:YES];
60 [self displayError:networkError]; 67 [self displayError:networkError];
61 } 68 }
62 69
63 // Bridge method from Downloader to InstallerWindowController. Allows Downloader 70 // Bridge method from Downloader to InstallerWindowController. Allows Downloader
64 // to update the progressbar without having direct access to any UI obejcts. 71 // to update the progressbar without having direct access to any UI obejcts.
65 - (void)didDownloadData:(double)downloadProgressPercentage { 72 - (void)downloader:(Downloader*)download
73 didDownloadData:(double)downloadProgressPercentage {
66 [installerWindowController_ 74 [installerWindowController_
67 updateDownloadProgress:(double)downloadProgressPercentage]; 75 updateDownloadProgress:(double)downloadProgressPercentage];
68 } 76 }
69 77
70 - (void)downloader:(Downloader*)download 78 - (void)downloader:(Downloader*)download
71 onDownloadSuccess:(NSURL*)diskImagePath { 79 onDownloadSuccessWithDiskURL:(NSURL*)diskImagePath {
72 [installerWindowController_ updateStatusDescription:@"Done."]; 80 [installerWindowController_ updateStatusDescription:@"Done."];
73 // TODO: replace the line of code below with real code someday 81
82 Unpacker* unpacker = [[Unpacker alloc]
Elly Fong-Jones 2016/08/16 15:26:18 who owns the unpacker? it looks like we don't stor
Anna Zeng 2016/08/16 23:07:39 Currently, nobody owns it, just the same as how we
Sidney San Martín 2016/08/17 22:09:06 ellyjones@: Just curious, is the plan to use ARC f
83 initWithFinalAppPath:@"/Applications/Google Chromo.app"];
84 unpacker.delegate = self;
85
86 [unpacker mountDMGFromURL:diskImagePath];
74 } 87 }
75 88
76 - (void)downloader:(Downloader*)download 89 - (void)downloader:(Downloader*)download
77 onDownloadFailureWithError:(NSError*)error { 90 onDownloadFailureWithError:(NSError*)error {
78 NSError* downloadError = 91 NSError* downloadError =
79 [NSError errorForAlerts:@"Download Failure" 92 [NSError errorForAlerts:@"Download Failure"
80 withDescription:@"Unable to download Google Chrome." 93 withDescription:@"Unable to download Google Chrome."
81 isRecoverable:NO]; 94 isRecoverable:NO];
82 [self displayError:downloadError]; 95 [self displayError:downloadError];
83 } 96 }
84 97
98 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)mountpath {
99 [unpacker extractChrome];
100 }
101
102 // TODO: adjust error descriptions for the following failure methods
103 - (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSString*)mountpath {
104 NSError* mountError =
105 [NSError errorForAlerts:@"Install Failure"
106 withDescription:@"Unable to add Google Chrome to Applications."
107 isRecoverable:NO];
108 [self displayError:mountError];
109 }
110
111 - (void)unpacker:(Unpacker*)unpacker onExtractSuccess:(NSString*)appPath {
112 [unpacker unmountDMG];
113 }
114
115 - (void)unpacker:(Unpacker*)unpacker onExtractFailure:(NSString*)appPath {
116 NSError* extractError =
117 [NSError errorForAlerts:@"Install Failure"
118 withDescription:@"Unable to add Google Chrome to Applications."
119 isRecoverable:NO];
120 [self displayError:extractError];
121 }
122
123 - (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSError*)error {
124 // TODO: change the name of chromo to chrome
125 if (![[NSWorkspace sharedWorkspace] launchApplication:@"Google Chromo"]) {
Sidney San Martín 2016/08/13 12:37:18 Pass the full path or use `launchApplicationAtURL:
Elly Fong-Jones 2016/08/16 15:26:18 Also, we're not called "Chromo" :)
Anna Zeng 2016/08/16 23:07:39 Done.
Anna Zeng 2016/08/16 23:07:39 I made a note of this, and added a TODO to make th
126 NSLog(@"Chromo failed to launch");
127 }
128 }
129
130 - (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSString*)appPath {
131 NSError* extractError =
132 [NSError errorForAlerts:@"Install Failure"
133 withDescription:@"Unable to add Google Chrome to Applications."
134 isRecoverable:NO];
135 [self displayError:extractError];
Sidney San Martín 2016/08/13 12:37:18 Is an unmount failure fatal/worth showing the user
Anna Zeng 2016/08/16 23:07:39 This is true! I have now moved the unmount step to
136 }
137
85 // Displays an alert on the main window using the contents of the passed in 138 // Displays an alert on the main window using the contents of the passed in
86 // error. 139 // error.
87 - (void)displayError:(NSError*)error { 140 - (void)displayError:(NSError*)error {
88 NSAlert* alertForUser = [NSAlert alertWithError:error]; 141 NSAlert* alertForUser = [NSAlert alertWithError:error];
89 142
90 dispatch_sync(dispatch_get_main_queue(), ^{ 143 dispatch_sync(dispatch_get_main_queue(), ^{
91 [alertForUser beginSheetModalForWindow:window_ 144 [alertForUser beginSheetModalForWindow:window_
92 completionHandler:^(NSModalResponse returnCode) { 145 completionHandler:^(NSModalResponse returnCode) {
93 if (returnCode != [alertForUser quitButton]) { 146 if (returnCode != [alertForUser quitButton]) {
94 [self startDownload]; 147 [self startDownload];
95 } else { 148 } else {
96 [NSApp terminate:nil]; 149 [NSApp terminate:nil];
97 } 150 }
98 }]; 151 }];
99 }); 152 });
100 } 153 }
101 154
102 @end 155 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698