1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #include "base/scoped_native_library.h" 6*635a8641SAndroid Build Coastguard Worker 7*635a8641SAndroid Build Coastguard Worker namespace base { 8*635a8641SAndroid Build Coastguard Worker ScopedNativeLibrary()9*635a8641SAndroid Build Coastguard WorkerScopedNativeLibrary::ScopedNativeLibrary() : library_(nullptr) {} 10*635a8641SAndroid Build Coastguard Worker ScopedNativeLibrary(NativeLibrary library)11*635a8641SAndroid Build Coastguard WorkerScopedNativeLibrary::ScopedNativeLibrary(NativeLibrary library) 12*635a8641SAndroid Build Coastguard Worker : library_(library) { 13*635a8641SAndroid Build Coastguard Worker } 14*635a8641SAndroid Build Coastguard Worker ScopedNativeLibrary(const FilePath & library_path)15*635a8641SAndroid Build Coastguard WorkerScopedNativeLibrary::ScopedNativeLibrary(const FilePath& library_path) { 16*635a8641SAndroid Build Coastguard Worker library_ = base::LoadNativeLibrary(library_path, nullptr); 17*635a8641SAndroid Build Coastguard Worker } 18*635a8641SAndroid Build Coastguard Worker ~ScopedNativeLibrary()19*635a8641SAndroid Build Coastguard WorkerScopedNativeLibrary::~ScopedNativeLibrary() { 20*635a8641SAndroid Build Coastguard Worker if (library_) 21*635a8641SAndroid Build Coastguard Worker base::UnloadNativeLibrary(library_); 22*635a8641SAndroid Build Coastguard Worker } 23*635a8641SAndroid Build Coastguard Worker GetFunctionPointer(const char * function_name) const24*635a8641SAndroid Build Coastguard Workervoid* ScopedNativeLibrary::GetFunctionPointer( 25*635a8641SAndroid Build Coastguard Worker const char* function_name) const { 26*635a8641SAndroid Build Coastguard Worker if (!library_) 27*635a8641SAndroid Build Coastguard Worker return nullptr; 28*635a8641SAndroid Build Coastguard Worker return base::GetFunctionPointerFromNativeLibrary(library_, function_name); 29*635a8641SAndroid Build Coastguard Worker } 30*635a8641SAndroid Build Coastguard Worker Reset(NativeLibrary library)31*635a8641SAndroid Build Coastguard Workervoid ScopedNativeLibrary::Reset(NativeLibrary library) { 32*635a8641SAndroid Build Coastguard Worker if (library_) 33*635a8641SAndroid Build Coastguard Worker base::UnloadNativeLibrary(library_); 34*635a8641SAndroid Build Coastguard Worker library_ = library; 35*635a8641SAndroid Build Coastguard Worker } 36*635a8641SAndroid Build Coastguard Worker Release()37*635a8641SAndroid Build Coastguard WorkerNativeLibrary ScopedNativeLibrary::Release() { 38*635a8641SAndroid Build Coastguard Worker NativeLibrary result = library_; 39*635a8641SAndroid Build Coastguard Worker library_ = nullptr; 40*635a8641SAndroid Build Coastguard Worker return result; 41*635a8641SAndroid Build Coastguard Worker } 42*635a8641SAndroid Build Coastguard Worker 43*635a8641SAndroid Build Coastguard Worker } // namespace base 44