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

Side by Side Diff: base/base_paths_mac.mm

Issue 174053: Set OS X cache directory to ~/Library/Caches/[app name]/[profile name] (Closed)
Patch Set: Addressed Mark's comments 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
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 // TODO(akalin): Export this function somewhere and use it in
Mark Mentovai 2009/09/16 18:33:41 Minor style nit. Leave a blank line after the nam
20 // chrome_paths_mac.mm and mac_util.mm. This is tricky because
21 // NSSearchPathDirectory is declared in an Objective C header so we
22 // cannot put it in one of the usual locations (where pure C++ files
23 // would include them).
24 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
25 NSArray* dirs =
26 NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES);
Mark Mentovai 2009/09/16 18:33:41 Minor style nit. Continuation lines get indented
27 if ([dirs count] < 1) {
28 return false;
29 }
30 NSString* path = [dirs objectAtIndex:0];
31 *result = FilePath([path fileSystemRepresentation]);
32 return true;
33 }
34 } // namespace
35
18 bool PathProviderMac(int key, FilePath* result) { 36 bool PathProviderMac(int key, FilePath* result) {
19 std::string cur; 37 std::string cur;
20 switch (key) { 38 switch (key) {
21 case base::FILE_EXE: 39 case base::FILE_EXE:
22 case base::FILE_MODULE: { 40 case base::FILE_MODULE: {
23 // Executable path can have relative references ("..") depending on 41 // Executable path can have relative references ("..") depending on
24 // how the app was launched. 42 // how the app was launched.
25 NSString* path = 43 NSString* path =
26 [[[NSBundle mainBundle] executablePath] stringByStandardizingPath]; 44 [[[NSBundle mainBundle] executablePath] stringByStandardizingPath];
27 cur = [path fileSystemRepresentation]; 45 cur = [path fileSystemRepresentation];
28 break; 46 break;
29 } 47 }
48 case base::DIR_CACHE:
49 return GetUserDirectory(NSCachesDirectory, result);
50 case base::DIR_APP_DATA:
51 return GetUserDirectory(NSApplicationSupportDirectory, result);
30 case base::DIR_SOURCE_ROOT: { 52 case base::DIR_SOURCE_ROOT: {
31 FilePath path; 53 FilePath path;
32 PathService::Get(base::DIR_EXE, &path); 54 PathService::Get(base::DIR_EXE, &path);
33 if (mac_util::AmIBundled()) { 55 if (mac_util::AmIBundled()) {
34 // The bundled app executables (Chromium, TestShell, etc) live five 56 // The bundled app executables (Chromium, TestShell, etc) live five
35 // levels down, eg: 57 // levels down, eg:
36 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium. 58 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium.
37 path = path.DirName(); 59 path = path.DirName();
38 path = path.DirName(); 60 path = path.DirName();
39 path = path.DirName(); 61 path = path.DirName();
40 path = path.DirName(); 62 path = path.DirName();
41 *result = path.DirName(); 63 *result = path.DirName();
42 } else { 64 } else {
43 // Unit tests execute two levels deep from the source root, eg: 65 // Unit tests execute two levels deep from the source root, eg:
44 // src/xcodebuild/{Debug|Release}/base_unittests 66 // src/xcodebuild/{Debug|Release}/base_unittests
45 path = path.DirName(); 67 path = path.DirName();
46 *result = path.DirName(); 68 *result = path.DirName();
47 } 69 }
48 return true; 70 return true;
49 } 71 }
50 default: 72 default:
51 return false; 73 return false;
52 } 74 }
53 75
54 *result = FilePath(cur); 76 *result = FilePath(cur);
55 return true; 77 return true;
56 } 78 }
57 79
58 } // namespace base 80 } // namespace base
OLDNEW
« no previous file with comments | « base/base_paths_mac.h ('k') | base/file_path.h » ('j') | base/file_path.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698