Commit 6ae692d7 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

mac: Use @available instead of -Wunguarded-availability suppression where possible.

This works despite https://llvm.org/PR33796 here because these
functions are in an unnamed namespace.

Bug: 735328
Change-Id: Ia22c05303a0360573aa1a0385c6a3966767f84cd
Reviewed-on: https://chromium-review.googlesource.com/573113Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487023}
parent 414c18ea
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/availability.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
...@@ -76,6 +77,7 @@ bool SetQuarantinePropertiesDeprecated(const base::FilePath& file, ...@@ -76,6 +77,7 @@ bool SetQuarantinePropertiesDeprecated(const base::FilePath& file,
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
API_AVAILABLE(macos(10.10))
bool GetQuarantineProperties( bool GetQuarantineProperties(
const base::FilePath& file, const base::FilePath& file,
base::scoped_nsobject<NSMutableDictionary>* properties) { base::scoped_nsobject<NSMutableDictionary>* properties) {
...@@ -84,15 +86,11 @@ bool GetQuarantineProperties( ...@@ -84,15 +86,11 @@ bool GetQuarantineProperties(
if (!file_url) if (!file_url)
return false; return false;
// NSURLQuarantinePropertiesKey is only available on macOS 10.10+.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
NSError* error = nil; NSError* error = nil;
id quarantine_properties = nil; id quarantine_properties = nil;
BOOL success = [file_url getResourceValue:&quarantine_properties BOOL success = [file_url getResourceValue:&quarantine_properties
forKey:NSURLQuarantinePropertiesKey forKey:NSURLQuarantinePropertiesKey
error:&error]; error:&error];
#pragma clang diagnostic pop
if (!success) { if (!success) {
std::string error_message(error ? error.description.UTF8String : ""); std::string error_message(error ? error.description.UTF8String : "");
LOG(WARNING) << "Unable to get quarantine attributes for file " LOG(WARNING) << "Unable to get quarantine attributes for file "
...@@ -116,6 +114,7 @@ bool GetQuarantineProperties( ...@@ -116,6 +114,7 @@ bool GetQuarantineProperties(
return true; return true;
} }
API_AVAILABLE(macos(10.10))
bool SetQuarantineProperties(const base::FilePath& file, bool SetQuarantineProperties(const base::FilePath& file,
NSDictionary* properties) { NSDictionary* properties) {
base::scoped_nsobject<NSURL> file_url([[NSURL alloc] base::scoped_nsobject<NSURL> file_url([[NSURL alloc]
...@@ -123,14 +122,10 @@ bool SetQuarantineProperties(const base::FilePath& file, ...@@ -123,14 +122,10 @@ bool SetQuarantineProperties(const base::FilePath& file,
if (!file_url) if (!file_url)
return false; return false;
// NSURLQuarantinePropertiesKey is only available on macOS 10.10+.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
NSError* error = nil; NSError* error = nil;
bool success = [file_url setResourceValue:properties bool success = [file_url setResourceValue:properties
forKey:NSURLQuarantinePropertiesKey forKey:NSURLQuarantinePropertiesKey
error:&error]; error:&error];
#pragma clang diagnostic pop
if (!success) { if (!success) {
std::string error_message(error ? error.description.UTF8String : ""); std::string error_message(error ? error.description.UTF8String : "");
LOG(WARNING) << "Unable to set quarantine attributes on file " LOG(WARNING) << "Unable to set quarantine attributes on file "
...@@ -241,7 +236,7 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file, ...@@ -241,7 +236,7 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file,
base::ThreadRestrictions::AssertIOAllowed(); base::ThreadRestrictions::AssertIOAllowed();
base::scoped_nsobject<NSMutableDictionary> properties; base::scoped_nsobject<NSMutableDictionary> properties;
bool success = false; bool success = false;
if (base::mac::IsAtLeastOS10_10()) { if (@available(macos 10.10, *)) {
success = GetQuarantineProperties(file, &properties); success = GetQuarantineProperties(file, &properties);
} else { } else {
success = GetQuarantinePropertiesDeprecated(file, &properties); success = GetQuarantinePropertiesDeprecated(file, &properties);
...@@ -285,7 +280,7 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file, ...@@ -285,7 +280,7 @@ bool AddQuarantineMetadataToFile(const base::FilePath& file,
[properties setValue:origin_url forKey:(NSString*)kLSQuarantineDataURLKey]; [properties setValue:origin_url forKey:(NSString*)kLSQuarantineDataURLKey];
} }
if (base::mac::IsAtLeastOS10_10()) { if (@available(macos 10.10, *)) {
return SetQuarantineProperties(file, properties); return SetQuarantineProperties(file, properties);
} else { } else {
return SetQuarantinePropertiesDeprecated(file, properties); return SetQuarantinePropertiesDeprecated(file, properties);
...@@ -319,7 +314,7 @@ bool IsFileQuarantined(const base::FilePath& file, ...@@ -319,7 +314,7 @@ bool IsFileQuarantined(const base::FilePath& file,
base::scoped_nsobject<NSMutableDictionary> properties; base::scoped_nsobject<NSMutableDictionary> properties;
bool success = false; bool success = false;
if (base::mac::IsAtLeastOS10_10()) { if (@available(macos 10.10, *)) {
success = GetQuarantineProperties(file, &properties); success = GetQuarantineProperties(file, &properties);
} else { } else {
success = GetQuarantinePropertiesDeprecated(file, &properties); success = GetQuarantinePropertiesDeprecated(file, &properties);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/availability.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -29,10 +30,7 @@ class QuarantineMacTest : public testing::Test { ...@@ -29,10 +30,7 @@ class QuarantineMacTest : public testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
if (base::mac::IsAtMostOS10_9()) { if (@available(macos 10.10, *)) {
LOG(WARNING) << "Test suite requires Mac OS X 10.10 or later";
return;
}
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE( ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &test_file_)); base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &test_file_));
...@@ -41,20 +39,19 @@ class QuarantineMacTest : public testing::Test { ...@@ -41,20 +39,19 @@ class QuarantineMacTest : public testing::Test {
base::scoped_nsobject<NSMutableDictionary> properties( base::scoped_nsobject<NSMutableDictionary> properties(
[[NSMutableDictionary alloc] init]); [[NSMutableDictionary alloc] init]);
[properties [properties setValue:@"com.google.Chrome"
setValue:@"com.google.Chrome" forKey:static_cast<NSString*>(
forKey:static_cast<NSString*>(kLSQuarantineAgentBundleIdentifierKey)]; kLSQuarantineAgentBundleIdentifierKey)];
[properties setValue:@"Google Chrome.app" [properties setValue:@"Google Chrome.app"
forKey:static_cast<NSString*>(kLSQuarantineAgentNameKey)]; forKey:static_cast<NSString*>(kLSQuarantineAgentNameKey)];
[properties setValue:@(1) forKey:@"kLSQuarantineIsOwnedByCurrentUserKey"]; [properties setValue:@(1) forKey:@"kLSQuarantineIsOwnedByCurrentUserKey"];
// NSURLQuarantinePropertiesKey is only available on macOS 10.10+.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
bool success = [file_url_ setResourceValue:properties bool success = [file_url_ setResourceValue:properties
forKey:NSURLQuarantinePropertiesKey forKey:NSURLQuarantinePropertiesKey
error:nullptr]; error:nullptr];
#pragma clang diagnostic pop
ASSERT_TRUE(success); ASSERT_TRUE(success);
} else {
LOG(WARNING) << "Test suite requires Mac OS X 10.10 or later";
}
} }
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment