| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/file_metadata.h" | 5 #include "chrome/browser/cocoa/file_metadata.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Foundation/Foundation.h> | 8 #include <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/scoped_cftyperef.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/mac_util.h" | 12 #include "base/mac_util.h" |
| 13 #include "base/mac/mac/scoped_cftyperef.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 | 15 |
| 16 namespace file_metadata { | 16 namespace file_metadata { |
| 17 | 17 |
| 18 // As of Mac OS X 10.4 ("Tiger"), files can be tagged with metadata describing | 18 // As of Mac OS X 10.4 ("Tiger"), files can be tagged with metadata describing |
| 19 // various attributes. Metadata is integrated with the system's Spotlight | 19 // various attributes. Metadata is integrated with the system's Spotlight |
| 20 // feature and is searchable. Ordinarily, metadata can only be set by | 20 // feature and is searchable. Ordinarily, metadata can only be set by |
| 21 // Spotlight importers, which requires that the importer own the target file. | 21 // Spotlight importers, which requires that the importer own the target file. |
| 22 // However, there's an attribute intended to describe the origin of a | 22 // However, there's an attribute intended to describe the origin of a |
| 23 // file, that can store the source URL and referrer of a downloaded file. | 23 // file, that can store the source URL and referrer of a downloaded file. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 CFSTR("MDItemSetAttribute")); | 62 CFSTR("MDItemSetAttribute")); |
| 63 } | 63 } |
| 64 if (!md_item_set_attribute_func) | 64 if (!md_item_set_attribute_func) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 NSString* file_path = | 67 NSString* file_path = |
| 68 [NSString stringWithUTF8String:file.value().c_str()]; | 68 [NSString stringWithUTF8String:file.value().c_str()]; |
| 69 if (!file_path) | 69 if (!file_path) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 scoped_cftyperef<MDItemRef> md_item( | 72 base::mac::ScopedCFTypeRef<MDItemRef> md_item( |
| 73 MDItemCreate(NULL, reinterpret_cast<CFStringRef>(file_path))); | 73 MDItemCreate(NULL, reinterpret_cast<CFStringRef>(file_path))); |
| 74 if (!md_item) | 74 if (!md_item) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 // We won't put any more than 2 items into the attribute. | 77 // We won't put any more than 2 items into the attribute. |
| 78 NSMutableArray* list = [NSMutableArray arrayWithCapacity:2]; | 78 NSMutableArray* list = [NSMutableArray arrayWithCapacity:2]; |
| 79 | 79 |
| 80 // Follow Safari's lead: the first item in the list is the source URL of | 80 // Follow Safari's lead: the first item in the list is the source URL of |
| 81 // the downloaded file. If the referrer is known, store that, too. | 81 // the downloaded file. If the referrer is known, store that, too. |
| 82 NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()]; | 82 NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()]; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 OSStatus os_error = LSSetItemAttribute(&file_ref, kLSRolesAll, | 158 OSStatus os_error = LSSetItemAttribute(&file_ref, kLSRolesAll, |
| 159 kLSItemQuarantineProperties, | 159 kLSItemQuarantineProperties, |
| 160 quarantine_properties); | 160 quarantine_properties); |
| 161 if (os_error != noErr) { | 161 if (os_error != noErr) { |
| 162 LOG(WARNING) << "Unable to set quarantine attributes on file " | 162 LOG(WARNING) << "Unable to set quarantine attributes on file " |
| 163 << file.value(); | 163 << file.value(); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace file_metadata | 167 } // namespace file_metadata |
| OLD | NEW |