Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/mac/install_from_dmg.h" | 5 #include "chrome/browser/mac/install_from_dmg.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 #include <ApplicationServices/ApplicationServices.h> | 8 #include <ApplicationServices/ApplicationServices.h> |
| 9 #include <CoreFoundation/CoreFoundation.h> | 9 #include <CoreFoundation/CoreFoundation.h> |
| 10 #include <CoreServices/CoreServices.h> | 10 #include <CoreServices/CoreServices.h> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 image_path->clear(); | 114 image_path->clear(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 base::mac::ScopedIOObject<io_service_t> hdix_drive( | 117 base::mac::ScopedIOObject<io_service_t> hdix_drive( |
| 118 CopyHDIXDriveServiceForMedia(media)); | 118 CopyHDIXDriveServiceForMedia(media)); |
| 119 if (!hdix_drive) { | 119 if (!hdix_drive) { |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 | 122 |
| 123 if (image_path) { | 123 if (image_path) { |
| 124 base::mac::ScopedCFTypeRef<CFTypeRef> image_path_cftyperef( | 124 base::ScopedCFTypeRef<CFTypeRef> image_path_cftyperef( |
| 125 IORegistryEntryCreateCFProperty(hdix_drive, | 125 IORegistryEntryCreateCFProperty( |
| 126 CFSTR("image-path"), | 126 hdix_drive, CFSTR("image-path"), NULL, 0)); |
|
Mark Mentovai
2013/06/21 20:29:40
Here’s another, although it’s arguably less of a “
| |
| 127 NULL, | |
| 128 0)); | |
| 129 if (!image_path_cftyperef) { | 127 if (!image_path_cftyperef) { |
| 130 LOG(ERROR) << "IORegistryEntryCreateCFProperty"; | 128 LOG(ERROR) << "IORegistryEntryCreateCFProperty"; |
| 131 return true; | 129 return true; |
| 132 } | 130 } |
| 133 if (CFGetTypeID(image_path_cftyperef) != CFDataGetTypeID()) { | 131 if (CFGetTypeID(image_path_cftyperef) != CFDataGetTypeID()) { |
| 134 base::mac::ScopedCFTypeRef<CFStringRef> observed_type_cf( | 132 base::ScopedCFTypeRef<CFStringRef> observed_type_cf( |
| 135 CFCopyTypeIDDescription(CFGetTypeID(image_path_cftyperef))); | 133 CFCopyTypeIDDescription(CFGetTypeID(image_path_cftyperef))); |
| 136 std::string observed_type; | 134 std::string observed_type; |
| 137 if (observed_type_cf) { | 135 if (observed_type_cf) { |
| 138 observed_type.assign(", observed "); | 136 observed_type.assign(", observed "); |
| 139 observed_type.append(base::SysCFStringRefToUTF8(observed_type_cf)); | 137 observed_type.append(base::SysCFStringRefToUTF8(observed_type_cf)); |
| 140 } | 138 } |
| 141 LOG(ERROR) << "image-path: expected CFData, observed " << observed_type; | 139 LOG(ERROR) << "image-path: expected CFData, observed " << observed_type; |
| 142 return true; | 140 return true; |
| 143 } | 141 } |
| 144 | 142 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 | 507 |
| 510 // A small structure used to ferry data between SynchronousDAOperation and | 508 // A small structure used to ferry data between SynchronousDAOperation and |
| 511 // SynchronousDACallbackAdapter. | 509 // SynchronousDACallbackAdapter. |
| 512 struct SynchronousDACallbackData { | 510 struct SynchronousDACallbackData { |
| 513 public: | 511 public: |
| 514 SynchronousDACallbackData() | 512 SynchronousDACallbackData() |
| 515 : callback_called(false), | 513 : callback_called(false), |
| 516 run_loop_running(false) { | 514 run_loop_running(false) { |
| 517 } | 515 } |
| 518 | 516 |
| 519 base::mac::ScopedCFTypeRef<DADissenterRef> dissenter; | 517 base::ScopedCFTypeRef<DADissenterRef> dissenter; |
| 520 bool callback_called; | 518 bool callback_called; |
| 521 bool run_loop_running; | 519 bool run_loop_running; |
| 522 | 520 |
| 523 private: | 521 private: |
| 524 DISALLOW_COPY_AND_ASSIGN(SynchronousDACallbackData); | 522 DISALLOW_COPY_AND_ASSIGN(SynchronousDACallbackData); |
| 525 }; | 523 }; |
| 526 | 524 |
| 527 // The callback target for SynchronousDAOperation. Set the fields in | 525 // The callback target for SynchronousDAOperation. Set the fields in |
| 528 // SynchronousDACallbackData properly and then stops the run loop so that | 526 // SynchronousDACallbackData properly and then stops the run loop so that |
| 529 // SynchronousDAOperation may proceed. | 527 // SynchronousDAOperation may proceed. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 // Calls DADiskEject synchronously, returning the result. | 596 // Calls DADiskEject synchronously, returning the result. |
| 599 bool SynchronousDADiskEject(DADiskRef disk, DADiskEjectOptions options) { | 597 bool SynchronousDADiskEject(DADiskRef disk, DADiskEjectOptions options) { |
| 600 SynchronousDACallbackData callback_data; | 598 SynchronousDACallbackData callback_data; |
| 601 DADiskEject(disk, options, SynchronousDACallbackAdapter, &callback_data); | 599 DADiskEject(disk, options, SynchronousDACallbackAdapter, &callback_data); |
| 602 return SynchronousDAOperation("DADiskEject", &callback_data); | 600 return SynchronousDAOperation("DADiskEject", &callback_data); |
| 603 } | 601 } |
| 604 | 602 |
| 605 } // namespace | 603 } // namespace |
| 606 | 604 |
| 607 void EjectAndTrashDiskImage(const std::string& dmg_bsd_device_name) { | 605 void EjectAndTrashDiskImage(const std::string& dmg_bsd_device_name) { |
| 608 base::mac::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(NULL)); | 606 base::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(NULL)); |
| 609 if (!session.get()) { | 607 if (!session.get()) { |
| 610 LOG(ERROR) << "DASessionCreate"; | 608 LOG(ERROR) << "DASessionCreate"; |
| 611 return; | 609 return; |
| 612 } | 610 } |
| 613 | 611 |
| 614 base::mac::ScopedCFTypeRef<DADiskRef> disk( | 612 base::ScopedCFTypeRef<DADiskRef> disk( |
| 615 DADiskCreateFromBSDName(NULL, session, dmg_bsd_device_name.c_str())); | 613 DADiskCreateFromBSDName(NULL, session, dmg_bsd_device_name.c_str())); |
| 616 if (!disk.get()) { | 614 if (!disk.get()) { |
| 617 LOG(ERROR) << "DADiskCreateFromBSDName"; | 615 LOG(ERROR) << "DADiskCreateFromBSDName"; |
| 618 return; | 616 return; |
| 619 } | 617 } |
| 620 | 618 |
| 621 // dmg_bsd_device_name may only refer to part of the disk: it may be a | 619 // dmg_bsd_device_name may only refer to part of the disk: it may be a |
| 622 // single filesystem on a larger disk. Use the "whole disk" object to | 620 // single filesystem on a larger disk. Use the "whole disk" object to |
| 623 // be able to unmount all mounted filesystems from the disk image, and eject | 621 // be able to unmount all mounted filesystems from the disk image, and eject |
| 624 // the image. This is harmless if dmg_bsd_device_name already referred to a | 622 // the image. This is harmless if dmg_bsd_device_name already referred to a |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 const UInt8* trash_path_u8 = reinterpret_cast<const UInt8*>( | 677 const UInt8* trash_path_u8 = reinterpret_cast<const UInt8*>( |
| 680 trash_path.value().c_str()); | 678 trash_path.value().c_str()); |
| 681 status = FNNotifyByPath(trash_path_u8, | 679 status = FNNotifyByPath(trash_path_u8, |
| 682 kFNDirectoryModifiedMessage, | 680 kFNDirectoryModifiedMessage, |
| 683 kNilOptions); | 681 kNilOptions); |
| 684 if (status != noErr) { | 682 if (status != noErr) { |
| 685 OSSTATUS_LOG(ERROR, status) << "FNNotifyByPath"; | 683 OSSTATUS_LOG(ERROR, status) << "FNNotifyByPath"; |
| 686 return; | 684 return; |
| 687 } | 685 } |
| 688 } | 686 } |
| OLD | NEW |