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

Unified Diff: base/native_library_mac.mm

Issue 115896: Making the browser tests work on Unix (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/native_library_mac.mm
===================================================================
--- base/native_library_mac.mm (revision 17736)
+++ base/native_library_mac.mm (working copy)
@@ -4,15 +4,28 @@
#include "base/native_library.h"
+#include <dlfcn.h>
#import <Carbon/Carbon.h>
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/scoped_cftyperef.h"
+#include "base/string_util.h"
namespace base {
// static
NativeLibrary LoadNativeLibrary(const FilePath& library_path) {
+ if (library_path.Extension() == "dylib" ||
+ !file_util::DirectoryExists(library_path)) {
+ void* dylib = dlopen(library_path.value().c_str(), RTLD_LAZY);
+ if (!dylib)
+ return NULL;
+ NativeLibrary native_lib = new NativeLibraryStruct();
+ native_lib->type = DYNAMIC_LIB;
+ native_lib->dylib = dylib;
+ return native_lib;
+ }
scoped_cftyperef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault,
(const UInt8*)library_path.value().c_str(),
@@ -20,19 +33,39 @@
true));
if (!url)
return NULL;
+ CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url.get());
+ if (!bundle)
+ return NULL;
- return CFBundleCreate(kCFAllocatorDefault, url.get());
+ NativeLibrary native_lib = new NativeLibraryStruct();
+ native_lib->type = BUNDLE;
+ native_lib->bundle = bundle;
+ return native_lib;
}
// static
void UnloadNativeLibrary(NativeLibrary library) {
- CFRelease(library);
+ if (library->type == BUNDLE)
+ CFRelease(library->bundle);
+ else
+ dlclose(library->dylib);
+ delete library;
}
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
- NativeLibraryFunctionNameType name) {
- return CFBundleGetFunctionPointerForName(library, name);
+ const char* name) {
+ if (library->type == BUNDLE)
+ return CFBundleGetFunctionPointerForName(library->bundle,
+ CFStringCreateWithCString(kCFAllocatorDefault, name,
+ kCFStringEncodingUTF8));
+
+ return dlsym(library->dylib, name);
}
+// static
+string16 GetNativeLibraryName(const string16& name) {
+ return name + ASCIIToUTF16(".dylib");
+}
+
} // namespace base
« no previous file with comments | « base/native_library_linux.cc ('k') | base/native_library_win.cc » ('j') | chrome/chrome.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698