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

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

Issue 2281263003: Use AuthorizedInstall to move Chrome into place and set up permissions (Closed)
Patch Set: Bridge pointer bug fixes, integration of AuthorizedInstall Created 4 years, 3 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/AppDelegate.m ('k') | 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 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 "Unpacker.h" 5 #import "Unpacker.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #include <DiskArbitration/DiskArbitration.h> 8 #include <DiskArbitration/DiskArbitration.h>
9 #include <dispatch/dispatch.h> 9 #include <dispatch/dispatch.h>
10 #include <Security/Security.h> 10 #include <Security/Security.h>
Mark Mentovai 2016/08/29 18:51:25 Move this #include to the other file.
Anna Zeng 2016/08/29 21:47:05 Done.
11 11
12 #import "Downloader.h" 12 #import "Downloader.h"
13 13
14 @interface Unpacker () { 14 @interface Unpacker () {
15 NSURL* temporaryDirectoryURL_; 15 NSURL* temporaryDirectoryURL_;
16 NSString* mountPath_; 16 NSString* mountPath_;
17 17
18 NSTask* __weak mountTask_; 18 NSTask* __weak mountTask_;
19 19
20 DASessionRef session_; 20 DASessionRef session_;
21 dispatch_queue_t unpack_dq_; 21 dispatch_queue_t unpack_dq_;
22 } 22 }
23 - (void)didFinishEjectingDisk:(DADiskRef)disk 23 - (void)didFinishEjectingDisk:(DADiskRef)disk
24 withDissenter:(DADissenterRef)dissenter; 24 withDissenter:(DADissenterRef)dissenter;
25 @end 25 @end
26 26
27 static void eject_callback(DADiskRef disk, 27 static void eject_callback(DADiskRef disk,
28 DADissenterRef dissenter, 28 DADissenterRef dissenter,
29 void* context) { 29 void* context) {
30 Unpacker* unpacker = (__bridge Unpacker*)context; 30 Unpacker* unpacker = (__bridge_transfer Unpacker*)context;
31 [unpacker didFinishEjectingDisk:disk withDissenter:dissenter]; 31 [unpacker didFinishEjectingDisk:disk withDissenter:dissenter];
32 } 32 }
33 33
34 static void unmount_callback(DADiskRef disk, 34 static void unmount_callback(DADiskRef disk,
35 DADissenterRef dissenter, 35 DADissenterRef dissenter,
36 void* context) { 36 void* context) {
37 if (dissenter) { 37 if (dissenter) {
38 Unpacker* unpacker = (__bridge Unpacker*)context; 38 Unpacker* unpacker = (__bridge Unpacker*)context;
39 [unpacker didFinishEjectingDisk:disk withDissenter:dissenter]; 39 [unpacker didFinishEjectingDisk:disk withDissenter:dissenter];
40 } else { 40 } else {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 [[NSNotificationCenter defaultCenter] 90 [[NSNotificationCenter defaultCenter]
91 addObserver:self 91 addObserver:self
92 selector:@selector(cleanUp) 92 selector:@selector(cleanUp)
93 name:NSApplicationWillTerminateNotification 93 name:NSApplicationWillTerminateNotification
94 object:nil]; 94 object:nil];
95 95
96 [[NSFileManager defaultManager] moveItemAtURL:fileURL 96 [[NSFileManager defaultManager] moveItemAtURL:fileURL
97 toURL:temporaryDiskImageURL 97 toURL:temporaryDiskImageURL
98 error:nil]; 98 error:nil];
99 99
100 SecStaticCodeRef diskStaticCode;
101 SecRequirementRef diskRequirement;
102 SecStaticCodeCreateWithPath((CFURLRef)CFBridgingRetain(temporaryDiskImageURL),
103 kSecCSDefaultFlags, &diskStaticCode);
104 // TODO: what requirement goes in here??
105 SecRequirementCreateWithString((CFStringRef) @"", kSecCSDefaultFlags,
106 &diskRequirement);
107 if (SecStaticCodeCheckValidity(diskStaticCode, kSecCSDefaultFlags,
108 diskRequirement) != errSecSuccess) {
109 // TODO: add in more strict error handling
110 NSLog(@"verification failed");
111 }
112
113 NSString* path = @"/usr/bin/hdiutil"; 100 NSString* path = @"/usr/bin/hdiutil";
114 NSArray* args = @[ 101 NSArray* args = @[
115 @"attach", temporaryDiskImageURL, @"-nobrowse", @"-noverify", 102 @"attach", temporaryDiskImageURL, @"-nobrowse", @"-noverify",
116 @"-mountpoint", mountPath_ 103 @"-mountpoint", mountPath_
117 ]; 104 ];
118 105
119 NSTask* mountTask = [[NSTask alloc] init]; 106 NSTask* mountTask = [[NSTask alloc] init];
120 mountTask.launchPath = path; 107 mountTask.launchPath = path;
121 mountTask.arguments = args; 108 mountTask.arguments = args;
122 mountTask.terminationHandler = ^void(NSTask* task) { 109 mountTask.terminationHandler = ^void(NSTask* task) {
(...skipping 20 matching lines...) Expand all
143 unpack_dq_ = 130 unpack_dq_ =
144 dispatch_queue_create("com.google.chrome.unpack", DISPATCH_QUEUE_SERIAL); 131 dispatch_queue_create("com.google.chrome.unpack", DISPATCH_QUEUE_SERIAL);
145 DASessionSetDispatchQueue(session_, unpack_dq_); 132 DASessionSetDispatchQueue(session_, unpack_dq_);
146 DADiskRef child_disk = DADiskCreateFromVolumePath( 133 DADiskRef child_disk = DADiskCreateFromVolumePath(
147 nil, session_, 134 nil, session_,
148 (__bridge CFURLRef)[NSURL fileURLWithPath:mountPath_ isDirectory:YES]); 135 (__bridge CFURLRef)[NSURL fileURLWithPath:mountPath_ isDirectory:YES]);
149 DADiskRef whole_disk = DADiskCopyWholeDisk(child_disk); 136 DADiskRef whole_disk = DADiskCopyWholeDisk(child_disk);
150 137
151 DADiskUnmount(whole_disk, 138 DADiskUnmount(whole_disk,
152 kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce, 139 kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce,
153 unmount_callback, (__bridge void*)self); 140 unmount_callback, (__bridge_retained void*)self);
154 141
155 CFRelease(whole_disk); 142 CFRelease(whole_disk);
156 CFRelease(child_disk); 143 CFRelease(child_disk);
157 } 144 }
158 145
159 - (void)didFinishEjectingDisk:(DADiskRef)disk 146 - (void)didFinishEjectingDisk:(DADiskRef)disk
160 withDissenter:(DADissenterRef)dissenter { 147 withDissenter:(DADissenterRef)dissenter {
161 DASessionSetDispatchQueue(session_, NULL); 148 DASessionSetDispatchQueue(session_, NULL);
162 dispatch_release(unpack_dq_); 149 dispatch_release(unpack_dq_);
163 CFRelease(session_); 150 CFRelease(session_);
164 NSError* error = nil; 151 NSError* error = nil;
165 if (dissenter) { 152 if (dissenter) {
166 DAReturn status = DADissenterGetStatus(dissenter); 153 DAReturn status = DADissenterGetStatus(dissenter);
167 error = [NSError 154 error = [NSError
168 errorWithDomain:@"ChromeErrorDomain" 155 errorWithDomain:@"ChromeErrorDomain"
169 code:err_get_code(status) 156 code:err_get_code(status)
170 userInfo:@{ 157 userInfo:@{
171 NSLocalizedDescriptionKey : 158 NSLocalizedDescriptionKey :
172 (__bridge NSString*)DADissenterGetStatusString(dissenter) 159 (__bridge NSString*)DADissenterGetStatusString(dissenter)
173 }]; 160 }];
174 [delegate_ unpacker:self onUnmountFailure:error]; 161 [delegate_ unpacker:self onUnmountFailure:error];
175 } else { 162 } else {
176 [self cleanUp]; 163 [self cleanUp];
177 [delegate_ unpacker:self onUnmountSuccess:mountPath_]; 164 [delegate_ unpacker:self onUnmountSuccess:mountPath_];
178 } 165 }
179 } 166 }
180 167
181 @end 168 @end
OLDNEW
« no previous file with comments | « chrome/installer/mac/app/AppDelegate.m ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698