1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_ANDROID_APK_ASSETS_H_
6 #define BASE_ANDROID_APK_ASSETS_H_
10 #include "base/android/jni_android.h"
11 #include "base/files/file_path.h"
12 #include "base/files/memory_mapped_file.h"
17 // Opens an asset (e.g. a .pak file) from the apk.
18 // Can be used from renderer process.
19 // Fails if the asset is not stored uncompressed within the .apk.
20 // Returns: The File Descriptor of the asset, or -1 upon failure.
22 // - |file_path|: Path to file within .apk. e.g.: assets/foo.pak
23 // - |split_name|: If non-empty, refers to the split where the asset is located.
25 // - |region|: size & offset (in bytes) within the .apk of the asset.
26 BASE_EXPORT int OpenApkAsset(const std::string& file_path,
27 const std::string& split_name,
28 base::MemoryMappedFile::Region* region);
29 BASE_EXPORT int OpenApkAsset(
30 const std::string& file_path,
31 base::MemoryMappedFile::Region* region);
33 // Registers an uncompressed asset from within the apk in the
34 // FileDescriptorStore.
35 // Returns: true in case of success, false otherwise.
36 BASE_EXPORT bool RegisterApkAssetWithFileDescriptorStore(
37 const std::string& key,
38 const base::FilePath& file_path);
40 // If one of the above methods failed, call this to perform a
41 // `DumpWithoutCrashing` containing errors relevant to the failure.
42 BASE_EXPORT void DumpLastOpenApkAssetFailure();
44 } // namespace android
47 #endif // BASE_ANDROID_APK_ASSETS_H_