Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/native_library.h" | 5 #include "base/native_library.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #import <Carbon/Carbon.h> | 8 #import <Carbon/Carbon.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 true)); | 33 true)); |
| 34 if (!url) | 34 if (!url) |
| 35 return NULL; | 35 return NULL; |
| 36 CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url.get()); | 36 CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url.get()); |
| 37 if (!bundle) | 37 if (!bundle) |
| 38 return NULL; | 38 return NULL; |
| 39 | 39 |
| 40 NativeLibrary native_lib = new NativeLibraryStruct(); | 40 NativeLibrary native_lib = new NativeLibraryStruct(); |
| 41 native_lib->type = BUNDLE; | 41 native_lib->type = BUNDLE; |
| 42 native_lib->bundle = bundle; | 42 native_lib->bundle = bundle; |
| 43 native_lib->bundle_resource_ref = CFBundleOpenBundleResourceMap(bundle); | |
| 43 return native_lib; | 44 return native_lib; |
| 44 } | 45 } |
| 45 | 46 |
| 46 // static | 47 // static |
| 47 void UnloadNativeLibrary(NativeLibrary library) { | 48 void UnloadNativeLibrary(NativeLibrary library) { |
| 48 if (library->type == BUNDLE) | 49 if (library->type == BUNDLE) { |
| 50 CFBundleCloseBundleResourceMap(library->bundle, | |
| 51 library->bundle_resource_ref); | |
|
Avi (use Gerrit)
2010/01/28 14:46:47
What if there was no resource map and the open cal
stuartmorgan
2010/01/28 15:24:37
The docs say nothing about returning -1 (or anythi
| |
| 49 CFRelease(library->bundle); | 52 CFRelease(library->bundle); |
| 50 else | 53 } else { |
| 51 dlclose(library->dylib); | 54 dlclose(library->dylib); |
| 55 } | |
| 52 delete library; | 56 delete library; |
| 53 } | 57 } |
| 54 | 58 |
| 55 // static | 59 // static |
| 56 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, | 60 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
| 57 const char* name) { | 61 const char* name) { |
| 58 if (library->type == BUNDLE) { | 62 if (library->type == BUNDLE) { |
| 59 scoped_cftyperef<CFStringRef> symbol_name( | 63 scoped_cftyperef<CFStringRef> symbol_name( |
| 60 CFStringCreateWithCString(kCFAllocatorDefault, name, | 64 CFStringCreateWithCString(kCFAllocatorDefault, name, |
| 61 kCFStringEncodingUTF8)); | 65 kCFStringEncodingUTF8)); |
| 62 return CFBundleGetFunctionPointerForName(library->bundle, symbol_name); | 66 return CFBundleGetFunctionPointerForName(library->bundle, symbol_name); |
| 63 } | 67 } |
| 64 return dlsym(library->dylib, name); | 68 return dlsym(library->dylib, name); |
| 65 } | 69 } |
| 66 | 70 |
| 67 // static | 71 // static |
| 68 string16 GetNativeLibraryName(const string16& name) { | 72 string16 GetNativeLibraryName(const string16& name) { |
| 69 return name + ASCIIToUTF16(".dylib"); | 73 return name + ASCIIToUTF16(".dylib"); |
| 70 } | 74 } |
| 71 | 75 |
| 72 } // namespace base | 76 } // namespace base |
| OLD | NEW |