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

Side by Side Diff: base/base_paths_mac.mm

Issue 204043: Set OS X cache directory to ~/Library/Caches/[app name]/[profile name] ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « base/base_paths_mac.h ('k') | base/file_path.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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "base/base_paths_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac_util.h" 12 #include "base/mac_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 namespace {
19
20 // TODO(akalin): Export this function somewhere and use it in
21 // chrome_paths_mac.mm and mac_util.mm. This is tricky because
22 // NSSearchPathDirectory is declared in an Objective C header so we
23 // cannot put it in one of the usual locations (where pure C++ files
24 // would include them).
25 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
26 NSArray* dirs =
27 NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
28 if ([dirs count] < 1) {
29 return false;
30 }
31 NSString* path = [dirs objectAtIndex:0];
32 *result = FilePath([path fileSystemRepresentation]);
33 return true;
34 }
35
36 } // namespace
37
18 bool PathProviderMac(int key, FilePath* result) { 38 bool PathProviderMac(int key, FilePath* result) {
19 std::string cur; 39 std::string cur;
20 switch (key) { 40 switch (key) {
21 case base::FILE_EXE: 41 case base::FILE_EXE:
22 case base::FILE_MODULE: { 42 case base::FILE_MODULE: {
23 // Executable path can have relative references ("..") depending on 43 // Executable path can have relative references ("..") depending on
24 // how the app was launched. 44 // how the app was launched.
25 NSString* path = 45 NSString* path =
26 [[[NSBundle mainBundle] executablePath] stringByStandardizingPath]; 46 [[[NSBundle mainBundle] executablePath] stringByStandardizingPath];
27 cur = [path fileSystemRepresentation]; 47 cur = [path fileSystemRepresentation];
28 break; 48 break;
29 } 49 }
50 case base::DIR_CACHE:
51 return GetUserDirectory(NSCachesDirectory, result);
52 case base::DIR_APP_DATA:
53 return GetUserDirectory(NSApplicationSupportDirectory, result);
30 case base::DIR_SOURCE_ROOT: { 54 case base::DIR_SOURCE_ROOT: {
31 FilePath path; 55 FilePath path;
32 PathService::Get(base::DIR_EXE, &path); 56 PathService::Get(base::DIR_EXE, &path);
33 if (mac_util::AmIBundled()) { 57 if (mac_util::AmIBundled()) {
34 // The bundled app executables (Chromium, TestShell, etc) live five 58 // The bundled app executables (Chromium, TestShell, etc) live five
35 // levels down, eg: 59 // levels down, eg:
36 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium. 60 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium.
37 path = path.DirName(); 61 path = path.DirName();
38 path = path.DirName(); 62 path = path.DirName();
39 path = path.DirName(); 63 path = path.DirName();
40 path = path.DirName(); 64 path = path.DirName();
41 *result = path.DirName(); 65 *result = path.DirName();
42 } else { 66 } else {
43 // Unit tests execute two levels deep from the source root, eg: 67 // Unit tests execute two levels deep from the source root, eg:
44 // src/xcodebuild/{Debug|Release}/base_unittests 68 // src/xcodebuild/{Debug|Release}/base_unittests
45 path = path.DirName(); 69 path = path.DirName();
46 *result = path.DirName(); 70 *result = path.DirName();
47 } 71 }
48 return true; 72 return true;
49 } 73 }
50 default: 74 default:
51 return false; 75 return false;
52 } 76 }
53 77
54 *result = FilePath(cur); 78 *result = FilePath(cur);
55 return true; 79 return true;
56 } 80 }
57 81
58 } // namespace base 82 } // namespace base
OLDNEW
« no previous file with comments | « base/base_paths_mac.h ('k') | base/file_path.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698