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

Side by Side Diff: base/android/apk_assets.cc

Issue 2772343003: Android: Remove GetApplicationContext part 1 (Closed)
Patch Set: rebase Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/android/build_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <jni.h> 5 #include <jni.h>
6 6
7 #include "base/android/apk_assets.h" 7 #include "base/android/apk_assets.h"
8 8
9 #include "base/android/context_utils.h"
10 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
12 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
13 #include "base/file_descriptor_store.h" 12 #include "base/file_descriptor_store.h"
14 #include "jni/ApkAssets_jni.h" 13 #include "jni/ApkAssets_jni.h"
15 14
16 namespace base { 15 namespace base {
17 namespace android { 16 namespace android {
18 17
19 int OpenApkAsset(const std::string& file_path, 18 int OpenApkAsset(const std::string& file_path,
20 base::MemoryMappedFile::Region* region) { 19 base::MemoryMappedFile::Region* region) {
21 // The AssetManager API of the NDK does not expose a method for accessing raw 20 // The AssetManager API of the NDK does not expose a method for accessing raw
22 // resources :( 21 // resources :(
23 JNIEnv* env = base::android::AttachCurrentThread(); 22 JNIEnv* env = base::android::AttachCurrentThread();
24 ScopedJavaLocalRef<jlongArray> jarr = Java_ApkAssets_open( 23 ScopedJavaLocalRef<jlongArray> jarr = Java_ApkAssets_open(
25 env, base::android::GetApplicationContext(), 24 env, base::android::ConvertUTF8ToJavaString(env, file_path));
26 base::android::ConvertUTF8ToJavaString(env, file_path));
27 std::vector<jlong> results; 25 std::vector<jlong> results;
28 base::android::JavaLongArrayToLongVector(env, jarr.obj(), &results); 26 base::android::JavaLongArrayToLongVector(env, jarr.obj(), &results);
29 CHECK_EQ(3U, results.size()); 27 CHECK_EQ(3U, results.size());
30 int fd = static_cast<int>(results[0]); 28 int fd = static_cast<int>(results[0]);
31 region->offset = results[1]; 29 region->offset = results[1];
32 region->size = results[2]; 30 region->size = results[2];
33 return fd; 31 return fd;
34 } 32 }
35 33
36 bool RegisterApkAssetWithFileDescriptorStore(const std::string& key, 34 bool RegisterApkAssetWithFileDescriptorStore(const std::string& key,
37 const base::FilePath& file_path) { 35 const base::FilePath& file_path) {
38 base::MemoryMappedFile::Region region = 36 base::MemoryMappedFile::Region region =
39 base::MemoryMappedFile::Region::kWholeFile; 37 base::MemoryMappedFile::Region::kWholeFile;
40 int asset_fd = OpenApkAsset(file_path.value(), &region); 38 int asset_fd = OpenApkAsset(file_path.value(), &region);
41 if (asset_fd == -1) 39 if (asset_fd == -1)
42 return false; 40 return false;
43 base::FileDescriptorStore::GetInstance().Set(key, base::ScopedFD(asset_fd), 41 base::FileDescriptorStore::GetInstance().Set(key, base::ScopedFD(asset_fd),
44 region); 42 region);
45 return true; 43 return true;
46 } 44 }
47 45
48 } // namespace android 46 } // namespace android
49 } // namespace base 47 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/android/build_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698