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

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

Issue 2203583002: Added unpacking step (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed some of Sidney's comments for the moment 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/mac/app/Unpacker.m
diff --git a/chrome/installer/mac/app/Unpacker.m b/chrome/installer/mac/app/Unpacker.m
new file mode 100644
index 0000000000000000000000000000000000000000..1177da6902f13a6c44020224f62e987c54a15872
--- /dev/null
+++ b/chrome/installer/mac/app/Unpacker.m
@@ -0,0 +1,122 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "Unpacker.h"
+
+// #include <copyfile.h>
+#include <DiskArbitration/DiskArbitration.h>
+#include <dispatch/dispatch.h>
+
+#import "Downloader.h"
+
+dispatch_semaphore_t mount_semaphore;
+
+@implementation Unpacker
+
+@synthesize delegate = delegate_;
+
+DASessionRef session;
+dispatch_queue_t unpack_dq;
Sidney San Martín 2016/08/08 18:43:17 These should be instance variables, not globals (l
Anna Zeng 2016/08/12 22:56:18 Done.
+
+static void unmount_callback(DADiskRef disk,
+ DADissenterRef dissenter,
+ void* context) {
+ if (dissenter) {
+ DAReturn status = DADissenterGetStatus(dissenter);
+ if (unix_err(status)) {
+ int code = err_get_code(status);
+ NSLog(@"Unmount error code %d", code);
+ // TODO: error handling
+ }
+ } else {
+ DADiskEject(disk, kDADiskEjectOptionDefault, eject_callback, context);
+ }
+}
+
+static void eject_callback(DADiskRef disk,
+ DADissenterRef dissenter,
+ void* context) {
+ NSError* error;
+ if (dissenter) {
+ DAReturn status = DADissenterGetStatus(dissenter);
+ if (unix_err(status)) {
+ int code = err_get_code(status);
+ NSLog(@"Eject error code %d", code);
+ // TODO: error handling
+ error = [NSError errorWithDomain:@"ChromeErrorDomain"
+ code:code
+ userInfo:@{
+ NSLocalizedDescriptionKey :
+ DADissenterGetStatusString(dissenter)
+ }];
+ }
+ }
+ Unpacker* unpacker = (__bridge Unpacker*)context;
+ [unpacker didFinishEjectingDisk:disk WithError:error];
+}
+
+- (void)mountDMG {
+ // TODO: how to find this from the PATH env variable?
Sidney San Martín 2016/08/08 18:43:17 TBH, since this is a system utility I think that h
Anna Zeng 2016/08/12 22:56:18 Done.
+ NSString* path = @"/usr/bin/hdiutil";
+ NSArray* args = @[
+ // TODO: break getDownloadsFilePath out of the downloader file
+ @"mount", [Downloader getDownloadsFilePath], @"-nobrowse", @"-mountpoint",
+ PATH_FROM_EXECUTABLE(@"tmp")
+ ];
+
+ NSTask* mountTask = [[NSTask alloc] init];
+ mountTask.launchPath = path;
+ mountTask.arguments = args;
+ mountTask.terminationHandler = ^void(NSTask* task) {
+ unpack_dq = dispatch_queue_create("com.google.chrome.unpack",
+ DISPATCH_QUEUE_SERIAL);
+ dispatch_async(unpack_dq, ^{
+ [self extractChrome];
+ });
+ };
+ [mountTask launch];
+ // TODO: how to error handling
+}
+
+- (void)extractChrome {
+ NSFileManager* fileManager = [NSFileManager defaultManager];
+ if (![fileManager
+ fileExistsAtPath:PATH_FROM_EXECUTABLE(@"tmp/Google Chrome.app")]) {
+ NSLog(@"File in DMG doesn't exist");
+ // TODO: error handling
+ }
+
+ // TODO: add progress
+ NSError* err;
+ if (![fileManager
+ copyItemAtPath:PATH_FROM_EXECUTABLE(@"tmp/Google Chrome.app")
+ toPath:@"/Applications/Google Chromo.app"
Sidney San Martín 2016/08/08 18:43:18 This path should come from outside (property, argu
Anna Zeng 2016/08/12 22:56:18 Done.
+ error:&err]) {
+ NSLog(@"%@", err);
+ }
+ dispatch_semaphore_signal(mount_semaphore);
+}
+
+- (void)unmountDMG {
+ session = DASessionCreate(nil);
+ DASessionSetDispatchQueue(session, unpack_dq);
+ DADiskRef child_disk = DADiskCreateFromVolumePath(
+ nil, session,
+ (CFURLRef)[NSURL URLWithString:PATH_FROM_EXECUTABLE(@"tmp")]);
+ DADiskRef whole_disk = DADiskCopyWholeDisk(child_disk);
+
+ DADiskUnmount(whole_disk, kDADiskUnmountOptionWhole, unmount_callback,
+ (void*)self);
+
+ CFRelease(whole_disk);
+ CFRelease(child_disk);
+}
+
+- (void)didFinishEjectingDisk:(DADiskRef)disk WithError:(NSError*)error {
+ DASessionSetDispatchQueue(session, NULL);
+ dispatch_release(unpack_dq);
+ [delegate_ onUnpackSuccess];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698