|
28 | 28 | #include <list> |
29 | 29 | #include <map> |
30 | 30 | #include <string> |
31 | | -#include <vector> |
32 | 31 | #include <utility> |
| 32 | +#include <vector> |
33 | 33 |
|
34 | 34 | #include "app/app_resources.h" |
35 | 35 | #include "app/src/app_common.h" |
| 36 | +#include "app/src/embedded_file.h" |
36 | 37 | #include "app/src/log.h" |
37 | 38 |
|
38 | 39 | #if !defined(FIREBASE_NAMESPACE) |
@@ -269,15 +270,6 @@ static const char kMissingJavaMethodFieldError[] = |
269 | 270 | "in your app."; |
270 | 271 | // LINT.ThenChange(//depot_firebase_cpp/app/client/unity/src/swig/app.SWIG) |
271 | 272 |
|
272 | | -std::vector<EmbeddedFile> ArrayToEmbeddedFiles(const char* filename, |
273 | | - const unsigned char* data, |
274 | | - size_t size) { |
275 | | - std::vector<EmbeddedFile> embedded_files; |
276 | | - EmbeddedFile embedded_file = {filename, data, size}; |
277 | | - embedded_files.push_back(embedded_file); |
278 | | - return embedded_files; |
279 | | -} |
280 | | - |
281 | 273 | // Create a global reference to the specified class loader add it to the |
282 | 274 | // list |
283 | 275 | // of class loaders and release the local reference. |
@@ -507,11 +499,12 @@ bool Initialize(JNIEnv* env, jobject activity_object) { |
507 | 499 | #endif // defined(FIREBASE_ANDROID_FOR_DESKTOP) |
508 | 500 |
|
509 | 501 | // Cache embedded files and load embedded classes. |
510 | | - const std::vector<EmbeddedFile> embedded_files = util::CacheEmbeddedFiles( |
511 | | - env, activity_object, |
512 | | - ArrayToEmbeddedFiles(firebase_app::app_resources_filename, |
513 | | - firebase_app::app_resources_data, |
514 | | - firebase_app::app_resources_size)); |
| 502 | + const std::vector<internal::EmbeddedFile> embedded_files = |
| 503 | + util::CacheEmbeddedFiles( |
| 504 | + env, activity_object, |
| 505 | + internal::EmbeddedFile::ToVector(firebase_app::app_resources_filename, |
| 506 | + firebase_app::app_resources_data, |
| 507 | + firebase_app::app_resources_size)); |
515 | 508 |
|
516 | 509 | // Cache the Log class and register the native log method. |
517 | 510 | if (!(log::CacheClassFromFiles(env, activity_object, &embedded_files) != |
@@ -1348,7 +1341,7 @@ bool JavaThreadContext::AcquireExecuteCancelLock() { |
1348 | 1341 |
|
1349 | 1342 | bool JavaThreadContext::Initialize( |
1350 | 1343 | JNIEnv* env, jobject activity_object, |
1351 | | - const std::vector<EmbeddedFile>& embedded_files) { |
| 1344 | + const std::vector<internal::EmbeddedFile>& embedded_files) { |
1352 | 1345 | static const JNINativeMethod kCppThreadMethods[] = { |
1353 | 1346 | {"nativeFunction", "(JJ)V", |
1354 | 1347 | reinterpret_cast<void*>(CppThreadDispatcherContext_nativeFunction)}}; |
@@ -1483,9 +1476,10 @@ void CancelCallbacks(JNIEnv* env, const char* api_identifier) { |
1483 | 1476 |
|
1484 | 1477 | // Find a class and retrieve a global reference to it. |
1485 | 1478 | // NOTE: This method will assert if the class isn't found. |
1486 | | -jclass FindClassGlobal(JNIEnv* env, jobject activity_object, |
1487 | | - const std::vector<EmbeddedFile>* embedded_files, |
1488 | | - const char* class_name, ClassRequirement optional) { |
| 1479 | +jclass FindClassGlobal( |
| 1480 | + JNIEnv* env, jobject activity_object, |
| 1481 | + const std::vector<internal::EmbeddedFile>* embedded_files, |
| 1482 | + const char* class_name, ClassRequirement optional) { |
1489 | 1483 | LogDebug("Looking up class %s", class_name); |
1490 | 1484 | jclass local_class = FindClass(env, class_name); |
1491 | 1485 | if (!local_class && embedded_files) { |
@@ -1529,14 +1523,14 @@ jclass FindClass(JNIEnv* env, const char* class_name) { |
1529 | 1523 | } |
1530 | 1524 |
|
1531 | 1525 | // Cache a list of embedded files to the activity's cache directory. |
1532 | | -const std::vector<EmbeddedFile>& CacheEmbeddedFiles( |
| 1526 | +const std::vector<internal::EmbeddedFile>& CacheEmbeddedFiles( |
1533 | 1527 | JNIEnv* env, jobject activity_object, |
1534 | | - const std::vector<EmbeddedFile>& embedded_files) { |
| 1528 | + const std::vector<internal::EmbeddedFile>& embedded_files) { |
1535 | 1529 | jobject cache_dir = env->CallObjectMethod( |
1536 | 1530 | activity_object, activity::GetMethodId(activity::kGetCacheDir)); |
1537 | 1531 | CheckAndClearJniExceptions(env); |
1538 | 1532 | // Write each file in the resources to the cache. |
1539 | | - for (std::vector<util::EmbeddedFile>::const_iterator it = |
| 1533 | + for (std::vector<internal::EmbeddedFile>::const_iterator it = |
1540 | 1534 | embedded_files.begin(); |
1541 | 1535 | it != embedded_files.end(); ++it) { |
1542 | 1536 | LogDebug("Caching %s", it->name); |
@@ -1582,9 +1576,10 @@ const std::vector<EmbeddedFile>& CacheEmbeddedFiles( |
1582 | 1576 |
|
1583 | 1577 | // Attempt to load a class from a set of files which have been cached to local |
1584 | 1578 | // storage using CacheEmbeddedFiles(). |
1585 | | -jclass FindClassInFiles(JNIEnv* env, jobject activity_object, |
1586 | | - const std::vector<EmbeddedFile>& embedded_files, |
1587 | | - const char* class_name) { |
| 1579 | +jclass FindClassInFiles( |
| 1580 | + JNIEnv* env, jobject activity_object, |
| 1581 | + const std::vector<internal::EmbeddedFile>& embedded_files, |
| 1582 | + const char* class_name) { |
1588 | 1583 | if (!embedded_files.size()) { |
1589 | 1584 | return nullptr; |
1590 | 1585 | } |
@@ -1657,7 +1652,7 @@ jclass FindClassInFiles(JNIEnv* env, jobject activity_object, |
1657 | 1652 | env->DeleteLocalRef(cache_dir); |
1658 | 1653 |
|
1659 | 1654 | std::string dex_path; |
1660 | | - for (std::vector<util::EmbeddedFile>::const_iterator it = |
| 1655 | + for (std::vector<internal::EmbeddedFile>::const_iterator it = |
1661 | 1656 | embedded_files.begin(); |
1662 | 1657 | it != embedded_files.end(); ++it) { |
1663 | 1658 | dex_path += cache_dir_path + kPathSeparator + std::string(it->name); |
|
0 commit comments