From 2ca8d5c4308699918efe940cfb5d1e0e1fbe112e Mon Sep 17 00:00:00 2001 From: erikchen Date: Wed, 5 Oct 2016 16:04:33 -0700 Subject: [PATCH] Remove deprecated FSRef-manipulation methods. The replacement methods had already been added to applefilesystem.mm, they just weren't being used on macOS. BUG=webrtc:6028 Review-Url: https://codereview.webrtc.org/2395593002 Cr-Commit-Position: refs/heads/master@{#14535} --- webrtc/base/proxydetect.cc | 19 +++++------------ webrtc/base/unixfilesystem.cc | 39 +++++++++++++---------------------- webrtc/base/unixfilesystem.h | 4 ++-- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/webrtc/base/proxydetect.cc b/webrtc/base/proxydetect.cc index 111cf4b020..7f298de790 100644 --- a/webrtc/base/proxydetect.cc +++ b/webrtc/base/proxydetect.cc @@ -21,6 +21,7 @@ #include #include #include "macconversion.h" +#include "webrtc/base/unixfilesystem.h" #endif #ifdef WEBRTC_IOS @@ -392,20 +393,10 @@ bool GetFirefoxProfilePath(Pathname* path) { path->AppendFolder("Mozilla"); path->AppendFolder("Firefox"); #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) - FSRef fr; - if (0 != FSFindFolder(kUserDomain, kApplicationSupportFolderType, - kCreateFolder, &fr)) { - LOG(LS_ERROR) << "FSFindFolder failed"; - return false; - } - char buffer[NAME_MAX + 1]; - if (0 != FSRefMakePath(&fr, reinterpret_cast(buffer), - arraysize(buffer))) { - LOG(LS_ERROR) << "FSRefMakePath failed"; - return false; - } - path->SetFolder(std::string(buffer)); - path->AppendFolder("Firefox"); + rtc::UnixFilesystem filesystem; + filesystem.SetApplicationName("Firefox"); + bool result = filesystem.GetAppDataFolder(path, true); + return result; #else char* user_home = getenv("HOME"); if (user_home == NULL) { diff --git a/webrtc/base/unixfilesystem.cc b/webrtc/base/unixfilesystem.cc index 61d03619a1..a756ae515e 100644 --- a/webrtc/base/unixfilesystem.cc +++ b/webrtc/base/unixfilesystem.cc @@ -61,7 +61,7 @@ void AppleAppName(rtc::Pathname* path); namespace rtc { -#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) +#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC) char* UnixFilesystem::app_temp_path_ = NULL; #else char* UnixFilesystem::provided_app_data_folder_ = NULL; @@ -79,7 +79,7 @@ void UnixFilesystem::SetAppTempFolder(const std::string& folder) { #endif UnixFilesystem::UnixFilesystem() { -#if defined(WEBRTC_IOS) +#if defined(WEBRTC_MAC) if (!provided_app_data_folder_) provided_app_data_folder_ = AppleDataDirectory(); if (!provided_app_temp_folder_) @@ -171,7 +171,7 @@ bool UnixFilesystem::DeleteEmptyFolder(const Pathname &folder) { bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, const std::string *append) { -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) ASSERT(provided_app_temp_folder_ != NULL); pathname.SetPathname(provided_app_temp_folder_, ""); #else @@ -281,18 +281,18 @@ bool UnixFilesystem::CopyFile(const Pathname &old_path, } bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) { -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) ASSERT(provided_app_temp_folder_ != NULL); #endif const char* const kTempPrefixes[] = { -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) provided_app_temp_folder_, -#else - "/tmp/", "/var/tmp/", #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) "/private/tmp/", "/private/var/tmp/", "/private/var/folders/", #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) +#else + "/tmp/", "/var/tmp/", #endif // WEBRTC_ANDROID || WEBRTC_IOS }; for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) { @@ -365,29 +365,18 @@ bool UnixFilesystem::GetAppPathname(Pathname* path) { } bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { + // On macOS and iOS, there is no requirement that the path contains the + // organization. +#if !defined(WEBRTC_MAC) ASSERT(!organization_name_.empty()); +#endif ASSERT(!application_name_.empty()); // First get the base directory for app data. -#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) - if (per_user) { - // Use ~/Library/Application Support/// - FSRef fr; - if (0 != FSFindFolder(kUserDomain, kApplicationSupportFolderType, - kCreateFolder, &fr)) - return false; - unsigned char buffer[NAME_MAX+1]; - if (0 != FSRefMakePath(&fr, buffer, arraysize(buffer))) - return false; - path->SetPathname(reinterpret_cast(buffer), ""); - } else { - // TODO - return false; - } -#elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) // && !WEBRTC_MAC || WEBRTC_IOS +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) ASSERT(provided_app_data_folder_ != NULL); path->SetPathname(provided_app_data_folder_, ""); -#elif defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) // && !WEBRTC_MAC && !WEBRTC_IOS && !WEBRTC_ANDROID +#elif defined(WEBRTC_LINUX) // && !WEBRTC_MAC && !WEBRTC_ANDROID if (per_user) { // We follow the recommendations in // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -451,7 +440,7 @@ bool UnixFilesystem::GetAppDataFolder(Pathname* path, bool per_user) { } bool UnixFilesystem::GetAppTempFolder(Pathname* path) { -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) ASSERT(provided_app_temp_folder_ != NULL); path->SetPathname(provided_app_temp_folder_); return true; diff --git a/webrtc/base/unixfilesystem.h b/webrtc/base/unixfilesystem.h index dbfbaf0a7d..78351e8489 100644 --- a/webrtc/base/unixfilesystem.h +++ b/webrtc/base/unixfilesystem.h @@ -22,7 +22,7 @@ class UnixFilesystem : public FilesystemInterface { UnixFilesystem(); ~UnixFilesystem() override; -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) // Android does not have a native code API to fetch the app data or temp // folders. That needs to be passed into this class from Java. Similarly, iOS // only supports an Objective-C API for fetching the folder locations, so that @@ -113,7 +113,7 @@ class UnixFilesystem : public FilesystemInterface { Pathname GetCurrentDirectory() override; private: -#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC) static char* provided_app_data_folder_; static char* provided_app_temp_folder_; #else