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

Side by Side Diff: base/base_paths_mac.mm

Issue 2145003004: Add ScopedAllowIO to allow get of FILE_EXE etc paths from non-IO-thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include Created 4 years, 5 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 | « no previous file | 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) 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 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac 5 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac
6 // in base/path_service.cc. 6 // in base/path_service.cc.
7 7
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #include <mach-o/dyld.h> 10 #include <mach-o/dyld.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 12
13 #include "base/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/threading/thread_restrictions.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 23
23 namespace { 24 namespace {
24 25
25 void GetNSExecutablePath(base::FilePath* path) { 26 void GetNSExecutablePath(base::FilePath* path) {
26 DCHECK(path); 27 DCHECK(path);
27 // Executable path can have relative references ("..") depending on 28 // Executable path can have relative references ("..") depending on
28 // how the app was launched. 29 // how the app was launched.
29 uint32_t executable_length = 0; 30 uint32_t executable_length = 0;
30 _NSGetExecutablePath(NULL, &executable_length); 31 _NSGetExecutablePath(NULL, &executable_length);
31 DCHECK_GT(executable_length, 1u); 32 DCHECK_GT(executable_length, 1u);
32 std::string executable_path; 33 std::string executable_path;
33 int rv = _NSGetExecutablePath( 34 int rv = _NSGetExecutablePath(
34 base::WriteInto(&executable_path, executable_length), 35 base::WriteInto(&executable_path, executable_length),
35 &executable_length); 36 &executable_length);
36 DCHECK_EQ(rv, 0); 37 DCHECK_EQ(rv, 0);
37 38
38 // _NSGetExecutablePath may return paths containing ./ or ../ which makes 39 // _NSGetExecutablePath may return paths containing ./ or ../ which makes
39 // FilePath::DirName() work incorrectly, convert it to absolute path so that 40 // FilePath::DirName() work incorrectly, convert it to absolute path so that
40 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to 41 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to
41 // be returned here. 42 // be returned here.
43 // TODO(bauerb): http://crbug.com/259796, http://crbug.com/373477
44 base::ThreadRestrictions::ScopedAllowIO allow_io;
42 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); 45 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path));
43 } 46 }
44 47
45 // Returns true if the module for |address| is found. |path| will contain 48 // Returns true if the module for |address| is found. |path| will contain
46 // the path to the module. Note that |path| may not be absolute. 49 // the path to the module. Note that |path| may not be absolute.
47 bool GetModulePathForAddress(base::FilePath* path, 50 bool GetModulePathForAddress(base::FilePath* path,
48 const void* address) WARN_UNUSED_RESULT; 51 const void* address) WARN_UNUSED_RESULT;
49 52
50 bool GetModulePathForAddress(base::FilePath* path, const void* address) { 53 bool GetModulePathForAddress(base::FilePath* path, const void* address) {
51 Dl_info info; 54 Dl_info info;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return base::mac::GetUserDirectory(NSDesktopDirectory, result); 110 return base::mac::GetUserDirectory(NSDesktopDirectory, result);
108 #endif 111 #endif
109 case base::DIR_CACHE: 112 case base::DIR_CACHE:
110 return base::mac::GetUserDirectory(NSCachesDirectory, result); 113 return base::mac::GetUserDirectory(NSCachesDirectory, result);
111 default: 114 default:
112 return false; 115 return false;
113 } 116 }
114 } 117 }
115 118
116 } // namespace base 119 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698