| 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 "base/base_paths_mac.h" | 5 // Defines base::PathProviderMac which implements paths specific to |
| 6 // base_paths_mac.h and replaces base::PathProviderPosix for OS_MAXOSX in |
| 7 // base/path_service.cc. |
| 6 | 8 |
| 7 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 8 #import <Foundation/Foundation.h> | 10 #import <Foundation/Foundation.h> |
| 9 #include <mach-o/dyld.h> | 11 #include <mach-o/dyld.h> |
| 10 | 12 |
| 13 #include "base/base_paths.h" |
| 14 #include "base/base_paths_mac.h" |
| 15 #include "base/base_paths_posix.h" |
| 11 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 12 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 19 #include "base/logging.h" |
| 15 #include "base/mac/foundation_util.h" | 20 #include "base/mac/foundation_util.h" |
| 16 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 17 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 18 | 23 |
| 19 namespace { | 24 namespace { |
| 20 | 25 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 namespace base { | 55 namespace base { |
| 51 | 56 |
| 52 bool PathProviderMac(int key, FilePath* result) { | 57 bool PathProviderMac(int key, FilePath* result) { |
| 53 switch (key) { | 58 switch (key) { |
| 54 case base::FILE_EXE: | 59 case base::FILE_EXE: |
| 55 GetNSExecutablePath(result); | 60 GetNSExecutablePath(result); |
| 56 return true; | 61 return true; |
| 57 case base::FILE_MODULE: | 62 case base::FILE_MODULE: |
| 58 return GetModulePathForAddress(result, | 63 return GetModulePathForAddress(result, |
| 59 reinterpret_cast<const void*>(&base::PathProviderMac)); | 64 reinterpret_cast<const void*>(&base::PathProviderMac)); |
| 60 case base::DIR_CACHE: | |
| 61 return base::mac::GetUserDirectory(NSCachesDirectory, result); | |
| 62 case base::DIR_APP_DATA: { | 65 case base::DIR_APP_DATA: { |
| 63 bool success = base::mac::GetUserDirectory(NSApplicationSupportDirectory, | 66 bool success = base::mac::GetUserDirectory(NSApplicationSupportDirectory, |
| 64 result); | 67 result); |
| 65 #if defined(OS_IOS) | 68 #if defined(OS_IOS) |
| 66 // On IOS, this directory does not exist unless it is created explicitly. | 69 // On IOS, this directory does not exist unless it is created explicitly. |
| 67 if (success && !file_util::PathExists(*result)) | 70 if (success && !file_util::PathExists(*result)) |
| 68 success = file_util::CreateDirectory(*result); | 71 success = file_util::CreateDirectory(*result); |
| 69 #endif // defined(OS_IOS) | 72 #endif // defined(OS_IOS) |
| 70 return success; | 73 return success; |
| 71 } | 74 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 84 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium | 87 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium |
| 85 *result = result->DirName().DirName().DirName().DirName().DirName(); | 88 *result = result->DirName().DirName().DirName().DirName().DirName(); |
| 86 } else { | 89 } else { |
| 87 // Unit tests execute two levels deep from the source root, eg: | 90 // Unit tests execute two levels deep from the source root, eg: |
| 88 // src/xcodebuild/{Debug|Release}/base_unittests | 91 // src/xcodebuild/{Debug|Release}/base_unittests |
| 89 *result = result->DirName().DirName(); | 92 *result = result->DirName().DirName(); |
| 90 } | 93 } |
| 91 #endif | 94 #endif |
| 92 return true; | 95 return true; |
| 93 } | 96 } |
| 97 case base::DIR_USER_DESKTOP: { |
| 98 return base::mac::GetUserDirectory(NSDesktopDirectory, result); |
| 99 } |
| 100 case base::DIR_CACHE: |
| 101 return base::mac::GetUserDirectory(NSCachesDirectory, result); |
| 94 case base::DIR_HOME: { | 102 case base::DIR_HOME: { |
| 95 *result = base::mac::NSStringToFilePath(NSHomeDirectory()); | 103 *result = base::mac::NSStringToFilePath(NSHomeDirectory()); |
| 96 return true; | 104 return true; |
| 97 } | 105 } |
| 98 default: | 106 default: |
| 99 return false; | 107 return false; |
| 100 } | 108 } |
| 101 } | 109 } |
| 102 | 110 |
| 103 } // namespace base | 111 } // namespace base |
| OLD | NEW |