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

Side by Side Diff: chrome/common/chrome_paths_mac.mm

Issue 2066004: Mac: app mode loader (shim). (Closed)
Patch Set: more changes per mark + merged ToT Created 10 years, 7 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 | « chrome/common/chrome_paths_internal.h ('k') | no next file » | 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 "chrome/common/chrome_paths_internal.h" 5 #include "chrome/common/chrome_paths_internal.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac_util.h" 11 #include "base/mac_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
14 14
15 namespace {
16 const FilePath* g_override_versioned_directory = NULL;
17 } // namespace
18
15 namespace chrome { 19 namespace chrome {
16 20
17 bool GetDefaultUserDataDirectory(FilePath* result) { 21 bool GetDefaultUserDataDirectory(FilePath* result) {
18 bool success = false; 22 bool success = false;
19 if (result && PathService::Get(base::DIR_APP_DATA, result)) { 23 if (result && PathService::Get(base::DIR_APP_DATA, result)) {
20 #if defined(GOOGLE_CHROME_BUILD) 24 #if defined(GOOGLE_CHROME_BUILD)
21 *result = result->Append("Google").Append("Chrome"); 25 *result = result->Append("Google").Append("Chrome");
22 #else 26 #else
23 *result = result->Append("Chromium"); 27 *result = result->Append("Chromium");
24 #endif 28 #endif
(...skipping 21 matching lines...) Expand all
46 50
47 bool GetUserDownloadsDirectory(FilePath* result) { 51 bool GetUserDownloadsDirectory(FilePath* result) {
48 return mac_util::GetUserDirectory(NSDownloadsDirectory, result); 52 return mac_util::GetUserDirectory(NSDownloadsDirectory, result);
49 } 53 }
50 54
51 bool GetUserDesktop(FilePath* result) { 55 bool GetUserDesktop(FilePath* result) {
52 return mac_util::GetUserDirectory(NSDesktopDirectory, result); 56 return mac_util::GetUserDirectory(NSDesktopDirectory, result);
53 } 57 }
54 58
55 FilePath GetVersionedDirectory() { 59 FilePath GetVersionedDirectory() {
60 if (g_override_versioned_directory)
61 return *g_override_versioned_directory;
62
56 // Start out with the path to the running executable. 63 // Start out with the path to the running executable.
57 FilePath path; 64 FilePath path;
58 PathService::Get(base::FILE_EXE, &path); 65 PathService::Get(base::FILE_EXE, &path);
59 66
60 // One step up to MacOS, another to Contents. 67 // One step up to MacOS, another to Contents.
61 path = path.DirName().DirName(); 68 path = path.DirName().DirName();
62 DCHECK_EQ(path.BaseName().value(), "Contents"); 69 DCHECK_EQ(path.BaseName().value(), "Contents");
63 70
64 if (mac_util::IsBackgroundOnlyProcess()) { 71 if (mac_util::IsBackgroundOnlyProcess()) {
65 // path identifies the helper .app's Contents directory in the browser 72 // path identifies the helper .app's Contents directory in the browser
66 // .app's versioned directory. Go up two steps to get to the browser 73 // .app's versioned directory. Go up two steps to get to the browser
67 // .app's versioned directory. 74 // .app's versioned directory.
68 path = path.DirName().DirName(); 75 path = path.DirName().DirName();
69 DCHECK_EQ(path.BaseName().value(), kChromeVersion); 76 DCHECK_EQ(path.BaseName().value(), kChromeVersion);
70 } else { 77 } else {
71 // Go into the versioned directory. 78 // Go into the versioned directory.
72 path = path.Append("Versions").Append(kChromeVersion); 79 path = path.Append("Versions").Append(kChromeVersion);
73 } 80 }
74 81
75 return path; 82 return path;
76 } 83 }
77 84
85 void SetOverrideVersionedDirectory(const FilePath* path) {
86 if (path != g_override_versioned_directory) {
87 delete g_override_versioned_directory;
88 g_override_versioned_directory = path;
89 }
90 }
91
78 FilePath GetFrameworkBundlePath() { 92 FilePath GetFrameworkBundlePath() {
79 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really 93 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really
80 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating 94 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating
81 // that it may be more efficient than +bundleForClass:. +bundleForClass: 95 // that it may be more efficient than +bundleForClass:. +bundleForClass:
82 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand, 96 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand,
83 // essentially takes no time at all, at least when the bundle has already 97 // essentially takes no time at all, at least when the bundle has already
84 // been loaded as it will have been in this case. The FilePath operations 98 // been loaded as it will have been in this case. The FilePath operations
85 // needed to compute the framework's path are also effectively free, so that 99 // needed to compute the framework's path are also effectively free, so that
86 // is the approach that is used here. NSBundle is also documented as being 100 // is the approach that is used here. NSBundle is also documented as being
87 // not thread-safe, and thread safety may be a concern here. 101 // not thread-safe, and thread safety may be a concern here.
88 102
89 // The framework bundle is at a known path and name from the browser .app's 103 // The framework bundle is at a known path and name from the browser .app's
90 // versioned directory. 104 // versioned directory.
91 return GetVersionedDirectory().Append(kFrameworkName); 105 return GetVersionedDirectory().Append(kFrameworkName);
92 } 106 }
93 107
94 } // namespace chrome 108 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/common/chrome_paths_internal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698