xref: /aosp_15_r20/external/libchrome/base/android/apk_assets.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2015 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 #ifndef BASE_ANDROID_APK_ASSETS_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_ANDROID_APK_ASSETS_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <string>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include "base/android/jni_android.h"
11*635a8641SAndroid Build Coastguard Worker #include "base/files/file_path.h"
12*635a8641SAndroid Build Coastguard Worker #include "base/files/memory_mapped_file.h"
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker namespace base {
15*635a8641SAndroid Build Coastguard Worker namespace android {
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker // Opens an asset (e.g. a .pak file) from the apk.
18*635a8641SAndroid Build Coastguard Worker // Can be used from renderer process.
19*635a8641SAndroid Build Coastguard Worker // Fails if the asset is not stored uncompressed within the .apk.
20*635a8641SAndroid Build Coastguard Worker // Returns: The File Descriptor of the asset, or -1 upon failure.
21*635a8641SAndroid Build Coastguard Worker // Input arguments:
22*635a8641SAndroid Build Coastguard Worker // - |file_path|: Path to file within .apk. e.g.: assets/foo.pak
23*635a8641SAndroid Build Coastguard Worker // Output arguments:
24*635a8641SAndroid Build Coastguard Worker // - |region|: size & offset (in bytes) within the .apk of the asset.
25*635a8641SAndroid Build Coastguard Worker BASE_EXPORT int OpenApkAsset(
26*635a8641SAndroid Build Coastguard Worker     const std::string& file_path,
27*635a8641SAndroid Build Coastguard Worker     base::MemoryMappedFile::Region* region);
28*635a8641SAndroid Build Coastguard Worker 
29*635a8641SAndroid Build Coastguard Worker // Registers an uncompressed asset from within the apk in the
30*635a8641SAndroid Build Coastguard Worker // FileDescriptorStore.
31*635a8641SAndroid Build Coastguard Worker // Returns: true in case of success, false otherwise.
32*635a8641SAndroid Build Coastguard Worker BASE_EXPORT bool RegisterApkAssetWithFileDescriptorStore(
33*635a8641SAndroid Build Coastguard Worker     const std::string& key,
34*635a8641SAndroid Build Coastguard Worker     const base::FilePath& file_path);
35*635a8641SAndroid Build Coastguard Worker 
36*635a8641SAndroid Build Coastguard Worker }  // namespace android
37*635a8641SAndroid Build Coastguard Worker }  // namespace base
38*635a8641SAndroid Build Coastguard Worker 
39*635a8641SAndroid Build Coastguard Worker #endif  // BASE_ANDROID_APK_ASSETS_H_
40