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

Side by Side Diff: shell/android/android_handler.cc

Issue 1046013002: Split LoadAndRunNativeApplication() ... (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 5 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 | « shell/BUILD.gn ('k') | shell/app_child_process.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "shell/android/android_handler.h" 5 #include "shell/android/android_handler.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/scoped_native_library.h" 11 #include "base/scoped_native_library.h"
12 #include "jni/AndroidHandler_jni.h" 12 #include "jni/AndroidHandler_jni.h"
13 #include "mojo/common/data_pipe_utils.h" 13 #include "mojo/common/data_pipe_utils.h"
14 #include "mojo/public/c/system/main.h" 14 #include "mojo/public/c/system/main.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "shell/android/run_android_application_function.h" 16 #include "shell/android/run_android_application_function.h"
17 #include "shell/dynamic_service_runner.h" 17 #include "shell/native_application_support.h"
18 18
19 using base::android::AttachCurrentThread; 19 using base::android::AttachCurrentThread;
20 using base::android::ScopedJavaLocalRef; 20 using base::android::ScopedJavaLocalRef;
21 using base::android::ConvertJavaStringToUTF8; 21 using base::android::ConvertJavaStringToUTF8;
22 using base::android::ConvertUTF8ToJavaString; 22 using base::android::ConvertUTF8ToJavaString;
23 using base::android::GetApplicationContext; 23 using base::android::GetApplicationContext;
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace shell { 26 namespace shell {
27 27
28 namespace { 28 namespace {
29 29
30 // This function loads the application library, sets the application context and 30 // This function loads the application library, sets the application context and
31 // thunks and calls into the application MojoMain. To ensure that the thunks are 31 // thunks and calls into the application MojoMain. To ensure that the thunks are
32 // set correctly we keep it in the Mojo shell .so and pass the function pointer 32 // set correctly we keep it in the Mojo shell .so and pass the function pointer
33 // to the helper libbootstrap.so. 33 // to the helper libbootstrap.so.
34 void RunAndroidApplication(JNIEnv* env, 34 void RunAndroidApplication(JNIEnv* env,
35 jobject j_context, 35 jobject j_context,
36 const base::FilePath& app_path, 36 const base::FilePath& app_path,
37 jint j_handle) { 37 jint j_handle) {
38 InterfaceRequest<Application> application_request = 38 InterfaceRequest<Application> application_request =
39 MakeRequest<Application>(MakeScopedHandle(MessagePipeHandle(j_handle))); 39 MakeRequest<Application>(MakeScopedHandle(MessagePipeHandle(j_handle)));
40 40
41 // Load the library, so that we can set the application context there if 41 // Load the library, so that we can set the application context there if
42 // needed. 42 // needed.
43 base::NativeLibraryLoadError error; 43 // TODO(vtl): We'd use a ScopedNativeLibrary, but it doesn't have .get()!
44 base::ScopedNativeLibrary app_library( 44 base::NativeLibrary app_library =
45 base::LoadNativeLibrary(app_path, &error)); 45 LoadNativeApplication(app_path, NativeApplicationCleanup::DELETE);
46 if (!app_library.is_valid()) { 46 if (!app_library)
47 LOG(ERROR) << "Failed to load app library (error: " << error.ToString()
48 << ")";
49 return; 47 return;
50 }
51 48
52 // Set the application context if needed. Most applications will need to 49 // Set the application context if needed. Most applications will need to
53 // access the Android ApplicationContext in which they are run. If the 50 // access the Android ApplicationContext in which they are run. If the
54 // application library exports the InitApplicationContext function, we will 51 // application library exports the InitApplicationContext function, we will
55 // set it there. 52 // set it there.
56 const char* init_application_context_name = "InitApplicationContext"; 53 const char* init_application_context_name = "InitApplicationContext";
57 typedef void (*InitApplicationContextFn)( 54 typedef void (*InitApplicationContextFn)(
58 const base::android::JavaRef<jobject>&); 55 const base::android::JavaRef<jobject>&);
59 InitApplicationContextFn init_application_context = 56 InitApplicationContextFn init_application_context =
60 reinterpret_cast<InitApplicationContextFn>( 57 reinterpret_cast<InitApplicationContextFn>(
61 app_library.GetFunctionPointer(init_application_context_name)); 58 base::GetFunctionPointerFromNativeLibrary(
59 app_library, init_application_context_name));
62 if (init_application_context) { 60 if (init_application_context) {
63 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, j_context); 61 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, j_context);
64 init_application_context(scoped_context); 62 init_application_context(scoped_context);
65 } 63 }
66 64
67 // Run the application. 65 // Run the application.
68 base::ScopedNativeLibrary app_library_from_runner(LoadAndRunNativeApplication( 66 RunNativeApplication(app_library, application_request.Pass());
69 app_path, NativeRunner::DeleteAppPath, application_request.Pass())); 67 // TODO(vtl): See note about unloading and thread-local destructors above
68 // declaration of |LoadNativeApplication()|.
69 base::UnloadNativeLibrary(app_library);
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 AndroidHandler::AndroidHandler() : content_handler_factory_(this) { 74 AndroidHandler::AndroidHandler() : content_handler_factory_(this) {
75 } 75 }
76 76
77 AndroidHandler::~AndroidHandler() { 77 AndroidHandler::~AndroidHandler() {
78 } 78 }
79 79
(...skipping 22 matching lines...) Expand all
102 connection->AddService(&content_handler_factory_); 102 connection->AddService(&content_handler_factory_);
103 return true; 103 return true;
104 } 104 }
105 105
106 bool RegisterAndroidHandlerJni(JNIEnv* env) { 106 bool RegisterAndroidHandlerJni(JNIEnv* env) {
107 return RegisterNativesImpl(env); 107 return RegisterNativesImpl(env);
108 } 108 }
109 109
110 } // namespace shell 110 } // namespace shell
111 } // namespace mojo 111 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/BUILD.gn ('k') | shell/app_child_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698