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

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

Issue 868463008: Remove Client relationship between mojo.Shell/mojo.Application (Closed) Base URL: git@github.com:domokit/mojo.git@app_impl_init
Patch Set: fix android Created 5 years, 11 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
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"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 // This function loads the application library, sets the application context and 28 // This function loads the application library, sets the application context and
29 // thunks and calls into the application MojoMain. To ensure that the thunks are 29 // thunks and calls into the application MojoMain. To ensure that the thunks are
30 // set correctly we keep it in the Mojo shell .so and pass the function pointer 30 // set correctly we keep it in the Mojo shell .so and pass the function pointer
31 // to the helper libbootstrap.so. 31 // to the helper libbootstrap.so.
32 void RunAndroidApplication(JNIEnv* env, 32 void RunAndroidApplication(JNIEnv* env,
33 jobject j_context, 33 jobject j_context,
34 const base::FilePath& app_path, 34 const base::FilePath& app_path,
35 jint j_handle) { 35 jint j_handle) {
36 ScopedMessagePipeHandle handle((mojo::MessagePipeHandle(j_handle))); 36 InterfaceRequest<Application> application_request = MakeRequest<Application>(
37 MakeScopedHandle(mojo::MessagePipeHandle(j_handle)));
37 38
38 // Load the library, so that we can set the application context there if 39 // Load the library, so that we can set the application context there if
39 // needed. 40 // needed.
40 base::NativeLibraryLoadError error; 41 base::NativeLibraryLoadError error;
41 base::ScopedNativeLibrary app_library( 42 base::ScopedNativeLibrary app_library(
42 base::LoadNativeLibrary(app_path, &error)); 43 base::LoadNativeLibrary(app_path, &error));
43 if (!app_library.is_valid()) { 44 if (!app_library.is_valid()) {
44 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() 45 LOG(ERROR) << "Failed to load app library (error: " << error.ToString()
45 << ")"; 46 << ")";
46 return; 47 return;
47 } 48 }
48 49
49 // Set the application context if needed. Most applications will need to 50 // Set the application context if needed. Most applications will need to
50 // access the Android ApplicationContext in which they are run. If the 51 // access the Android ApplicationContext in which they are run. If the
51 // application library exports the InitApplicationContext function, we will 52 // application library exports the InitApplicationContext function, we will
52 // set it there. 53 // set it there.
53 const char* init_application_context_name = "InitApplicationContext"; 54 const char* init_application_context_name = "InitApplicationContext";
54 typedef void (*InitApplicationContextFn)( 55 typedef void (*InitApplicationContextFn)(
55 const base::android::JavaRef<jobject>&); 56 const base::android::JavaRef<jobject>&);
56 InitApplicationContextFn init_application_context = 57 InitApplicationContextFn init_application_context =
57 reinterpret_cast<InitApplicationContextFn>( 58 reinterpret_cast<InitApplicationContextFn>(
58 app_library.GetFunctionPointer(init_application_context_name)); 59 app_library.GetFunctionPointer(init_application_context_name));
59 if (init_application_context) { 60 if (init_application_context) {
60 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, j_context); 61 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, j_context);
61 init_application_context(scoped_context); 62 init_application_context(scoped_context);
62 } 63 }
63 64
64 // Run the application. 65 // Run the application.
65 base::ScopedNativeLibrary app_library_from_runner( 66 base::ScopedNativeLibrary app_library_from_runner(
66 shell::DynamicServiceRunner::LoadAndRunService(app_path, handle.Pass())); 67 shell::DynamicServiceRunner::LoadAndRunService(
68 app_path, application_request.Pass()));
67 } 69 }
68 } // namespace 70 } // namespace
69 71
70 AndroidHandler::AndroidHandler() : content_handler_factory_(this) { 72 AndroidHandler::AndroidHandler() : content_handler_factory_(this) {
71 } 73 }
72 74
73 AndroidHandler::~AndroidHandler() { 75 AndroidHandler::~AndroidHandler() {
74 } 76 }
75 77
76 void AndroidHandler::RunApplication(ShellPtr shell, URLResponsePtr response) { 78 void AndroidHandler::RunApplication(
79 InterfaceRequest<Application> application_request,
80 URLResponsePtr response) {
77 JNIEnv* env = AttachCurrentThread(); 81 JNIEnv* env = AttachCurrentThread();
78 ScopedJavaLocalRef<jstring> j_archive_path = 82 ScopedJavaLocalRef<jstring> j_archive_path =
79 Java_AndroidHandler_getNewTempArchivePath(env, GetApplicationContext()); 83 Java_AndroidHandler_getNewTempArchivePath(env, GetApplicationContext());
80 base::FilePath archive_path( 84 base::FilePath archive_path(
81 ConvertJavaStringToUTF8(env, j_archive_path.obj())); 85 ConvertJavaStringToUTF8(env, j_archive_path.obj()));
82 86
83 mojo::common::BlockingCopyToFile(response->body.Pass(), archive_path); 87 mojo::common::BlockingCopyToFile(response->body.Pass(), archive_path);
84 RunAndroidApplicationFn run_android_application_fn = &RunAndroidApplication; 88 RunAndroidApplicationFn run_android_application_fn = &RunAndroidApplication;
85 Java_AndroidHandler_bootstrap( 89 Java_AndroidHandler_bootstrap(
86 env, GetApplicationContext(), j_archive_path.obj(), 90 env, GetApplicationContext(), j_archive_path.obj(),
87 shell.PassMessagePipe().release().value(), 91 application_request.PassMessagePipe().release().value(),
88 reinterpret_cast<jlong>(run_android_application_fn)); 92 reinterpret_cast<jlong>(run_android_application_fn));
89 } 93 }
90 94
91 void AndroidHandler::Initialize(ApplicationImpl* app) { 95 void AndroidHandler::Initialize(ApplicationImpl* app) {
92 } 96 }
93 97
94 bool AndroidHandler::ConfigureIncomingConnection( 98 bool AndroidHandler::ConfigureIncomingConnection(
95 ApplicationConnection* connection) { 99 ApplicationConnection* connection) {
96 connection->AddService(&content_handler_factory_); 100 connection->AddService(&content_handler_factory_);
97 return true; 101 return true;
98 } 102 }
99 103
100 bool RegisterAndroidHandlerJni(JNIEnv* env) { 104 bool RegisterAndroidHandlerJni(JNIEnv* env) {
101 return RegisterNativesImpl(env); 105 return RegisterNativesImpl(env);
102 } 106 }
103 107
104 } // namespace mojo 108 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698