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

Side by Side Diff: webrtc/base/unixfilesystem.cc

Issue 2321493002: Reland of move all reference to carbon api (Closed)
Patch Set: fix chromium build issues Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « webrtc/base/proxydetect.cc ('k') | webrtc/engine_configurations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/unixfilesystem.h" 11 #include "webrtc/base/unixfilesystem.h"
12 12
13 #include <errno.h> 13 #include <errno.h>
14 #include <fcntl.h> 14 #include <fcntl.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <sys/stat.h> 16 #include <sys/stat.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 19 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
20 #include <Carbon/Carbon.h> 20 #include <CoreFoundation/CoreFoundation.h>
21 #include <IOKit/IOCFBundle.h> 21 #include <IOKit/IOCFBundle.h>
22 #include <sys/statvfs.h> 22 #include <sys/statvfs.h>
23 #include "webrtc/base/macutils.h" 23 #include "webrtc/base/macutils.h"
24 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) 24 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
25 25
26 #if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) || defined(WEBRTC_IOS) 26 #if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #if defined(WEBRTC_ANDROID) 28 #if defined(WEBRTC_ANDROID)
29 #include <sys/statfs.h> 29 #include <sys/statfs.h>
30 #elif !defined(__native_client__) 30 #elif !defined(__native_client__)
(...skipping 12 matching lines...) Expand all
43 #if defined(__native_client__) && !defined(__GLIBC__) 43 #if defined(__native_client__) && !defined(__GLIBC__)
44 #include <sys/syslimits.h> 44 #include <sys/syslimits.h>
45 #endif 45 #endif
46 46
47 #include "webrtc/base/arraysize.h" 47 #include "webrtc/base/arraysize.h"
48 #include "webrtc/base/fileutils.h" 48 #include "webrtc/base/fileutils.h"
49 #include "webrtc/base/pathutils.h" 49 #include "webrtc/base/pathutils.h"
50 #include "webrtc/base/stream.h" 50 #include "webrtc/base/stream.h"
51 #include "webrtc/base/stringutils.h" 51 #include "webrtc/base/stringutils.h"
52 52
53 #if defined(WEBRTC_IOS) 53 #if defined(WEBRTC_MAC)
54 // Defined in iosfilesystem.mm. No header file to discourage use 54 // Defined in applefilesystem.mm. No header file to discourage use
55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in 55 // elsewhere; other places should use GetApp{Data,Temp}Folder() in
56 // this file. Don't copy/paste. I mean it. 56 // this file. Don't copy/paste. I mean it.
57 char* IOSDataDirectory(); 57 char* AppleDataDirectory();
58 char* IOSTempDirectory(); 58 char* AppleTempDirectory();
59 void IOSAppName(rtc::Pathname* path); 59 void AppleAppName(rtc::Pathname* path);
60 #endif 60 #endif
61 61
62 namespace rtc { 62 namespace rtc {
63 63
64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS) 64 #if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
65 char* UnixFilesystem::app_temp_path_ = NULL; 65 char* UnixFilesystem::app_temp_path_ = NULL;
66 #else 66 #else
67 char* UnixFilesystem::provided_app_data_folder_ = NULL; 67 char* UnixFilesystem::provided_app_data_folder_ = NULL;
68 char* UnixFilesystem::provided_app_temp_folder_ = NULL; 68 char* UnixFilesystem::provided_app_temp_folder_ = NULL;
69 69
70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) { 70 void UnixFilesystem::SetAppDataFolder(const std::string& folder) {
71 delete [] provided_app_data_folder_; 71 delete [] provided_app_data_folder_;
72 provided_app_data_folder_ = CopyString(folder); 72 provided_app_data_folder_ = CopyString(folder);
73 } 73 }
74 74
75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) { 75 void UnixFilesystem::SetAppTempFolder(const std::string& folder) {
76 delete [] provided_app_temp_folder_; 76 delete [] provided_app_temp_folder_;
77 provided_app_temp_folder_ = CopyString(folder); 77 provided_app_temp_folder_ = CopyString(folder);
78 } 78 }
79 #endif 79 #endif
80 80
81 UnixFilesystem::UnixFilesystem() { 81 UnixFilesystem::UnixFilesystem() {
82 #if defined(WEBRTC_IOS) 82 #if defined(WEBRTC_IOS)
83 if (!provided_app_data_folder_) 83 if (!provided_app_data_folder_)
84 provided_app_data_folder_ = IOSDataDirectory(); 84 provided_app_data_folder_ = AppleDataDirectory();
85 if (!provided_app_temp_folder_) 85 if (!provided_app_temp_folder_)
86 provided_app_temp_folder_ = IOSTempDirectory(); 86 provided_app_temp_folder_ = AppleTempDirectory();
87 #endif 87 #endif
88 } 88 }
89 89
90 UnixFilesystem::~UnixFilesystem() {} 90 UnixFilesystem::~UnixFilesystem() {}
91 91
92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) { 92 bool UnixFilesystem::CreateFolder(const Pathname &path, mode_t mode) {
93 std::string pathname(path.pathname()); 93 std::string pathname(path.pathname());
94 int len = pathname.length(); 94 int len = pathname.length();
95 if ((len == 0) || (pathname[len - 1] != '/')) 95 if ((len == 0) || (pathname[len - 1] != '/'))
96 return false; 96 return false;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!IsFolder(folder)) { 164 if (!IsFolder(folder)) {
165 ASSERT(IsFolder(folder)); 165 ASSERT(IsFolder(folder));
166 return false; 166 return false;
167 } 167 }
168 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1); 168 std::string no_slash(folder.pathname(), 0, folder.pathname().length()-1);
169 return ::rmdir(no_slash.c_str()) == 0; 169 return ::rmdir(no_slash.c_str()) == 0;
170 } 170 }
171 171
172 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create, 172 bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create,
173 const std::string *append) { 173 const std::string *append) {
174 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 174 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
175 FSRef fr;
176 if (0 != FSFindFolder(kOnAppropriateDisk, kTemporaryFolderType,
177 kCreateFolder, &fr))
178 return false;
179 unsigned char buffer[NAME_MAX+1];
180 if (0 != FSRefMakePath(&fr, buffer, arraysize(buffer)))
181 return false;
182 pathname.SetPathname(reinterpret_cast<char*>(buffer), "");
183 #elif defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
184 ASSERT(provided_app_temp_folder_ != NULL); 175 ASSERT(provided_app_temp_folder_ != NULL);
185 pathname.SetPathname(provided_app_temp_folder_, ""); 176 pathname.SetPathname(provided_app_temp_folder_, "");
186 #else // !WEBRTC_MAC || WEBRTC_IOS && !WEBRTC_ANDROID 177 #else
187 if (const char* tmpdir = getenv("TMPDIR")) { 178 if (const char* tmpdir = getenv("TMPDIR")) {
188 pathname.SetPathname(tmpdir, ""); 179 pathname.SetPathname(tmpdir, "");
189 } else if (const char* tmp = getenv("TMP")) { 180 } else if (const char* tmp = getenv("TMP")) {
190 pathname.SetPathname(tmp, ""); 181 pathname.SetPathname(tmp, "");
191 } else { 182 } else {
192 #ifdef P_tmpdir 183 #ifdef P_tmpdir
193 pathname.SetPathname(P_tmpdir, ""); 184 pathname.SetPathname(P_tmpdir, "");
194 #else // !P_tmpdir 185 #else // !P_tmpdir
195 pathname.SetPathname("/tmp/", ""); 186 pathname.SetPathname("/tmp/", "");
196 #endif // !P_tmpdir 187 #endif // !P_tmpdir
197 } 188 }
198 #endif // !WEBRTC_MAC || WEBRTC_IOS && !WEBRTC_ANDROID 189 #endif // defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
199 if (append) { 190 if (append) {
200 ASSERT(!append->empty()); 191 ASSERT(!append->empty());
201 pathname.AppendFolder(*append); 192 pathname.AppendFolder(*append);
202 } 193 }
203 return !create || CreateFolder(pathname); 194 return !create || CreateFolder(pathname);
204 } 195 }
205 196
206 std::string UnixFilesystem::TempFilename(const Pathname &dir, 197 std::string UnixFilesystem::TempFilename(const Pathname &dir,
207 const std::string &prefix) { 198 const std::string &prefix) {
208 int len = dir.pathname().size() + prefix.size() + 2 + 6; 199 int len = dir.pathname().size() + prefix.size() + 2 + 6;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 case FTT_ACCESSED: 341 case FTT_ACCESSED:
351 *time = st.st_atime; 342 *time = st.st_atime;
352 break; 343 break;
353 default: 344 default:
354 return false; 345 return false;
355 } 346 }
356 return true; 347 return true;
357 } 348 }
358 349
359 bool UnixFilesystem::GetAppPathname(Pathname* path) { 350 bool UnixFilesystem::GetAppPathname(Pathname* path) {
360 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 351 #if defined(__native_client__)
361 ProcessSerialNumber psn = { 0, kCurrentProcess };
362 CFDictionaryRef procinfo = ProcessInformationCopyDictionary(&psn,
363 kProcessDictionaryIncludeAllInformationMask);
364 if (NULL == procinfo)
365 return false;
366 CFStringRef cfpath = (CFStringRef) CFDictionaryGetValue(procinfo,
367 kIOBundleExecutableKey);
368 std::string path8;
369 bool success = ToUtf8(cfpath, &path8);
370 CFRelease(procinfo);
371 if (success)
372 path->SetPathname(path8);
373 return success;
374 #elif defined(__native_client__)
375 return false; 352 return false;
376 #elif WEBRTC_IOS 353 #elif defined(WEBRTC_MAC)
377 IOSAppName(path); 354 AppleAppName(path);
378 return true; 355 return true;
379 #else // WEBRTC_MAC && !defined(WEBRTC_IOS) 356 #else // WEBRTC_MAC && !defined(WEBRTC_IOS)
380 char buffer[PATH_MAX + 2]; 357 char buffer[PATH_MAX + 2];
381 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1); 358 ssize_t len = readlink("/proc/self/exe", buffer, arraysize(buffer) - 1);
382 if ((len <= 0) || (len == PATH_MAX + 1)) 359 if ((len <= 0) || (len == PATH_MAX + 1))
383 return false; 360 return false;
384 buffer[len] = '\0'; 361 buffer[len] = '\0';
385 path->SetPathname(buffer); 362 path->SetPathname(buffer);
386 return true; 363 return true;
387 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) 364 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 542
566 } // namespace rtc 543 } // namespace rtc
567 544
568 #if defined(__native_client__) 545 #if defined(__native_client__)
569 extern "C" int __attribute__((weak)) 546 extern "C" int __attribute__((weak))
570 link(const char* oldpath, const char* newpath) { 547 link(const char* oldpath, const char* newpath) {
571 errno = EACCES; 548 errno = EACCES;
572 return -1; 549 return -1;
573 } 550 }
574 #endif 551 #endif
OLDNEW
« no previous file with comments | « webrtc/base/proxydetect.cc ('k') | webrtc/engine_configurations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698