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

Side by Side Diff: services/java_handler/java_handler.cc

Issue 2010283006: Almost done: ApplicationDelegate -> ApplicationImplBase conversion. (Closed) Base URL: https://github.com/domokit/mojo.git@work798-x-work797-x-work796_no_run_main_app
Patch Set: rebased Created 4 years, 6 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 | « services/java_handler/java_handler.h ('k') | services/js/pingpong_apptest.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 "services/java_handler/java_handler.h" 5 #include "services/java_handler/java_handler.h"
6 6
7 #include "base/android/base_jni_onload.h" 7 #include "base/android/base_jni_onload.h"
8 #include "base/android/base_jni_registrar.h" 8 #include "base/android/base_jni_registrar.h"
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/android/library_loader/library_loader_hooks.h" 11 #include "base/android/library_loader/library_loader_hooks.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/scoped_native_library.h" 16 #include "base/scoped_native_library.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "jni/JavaHandler_jni.h" 18 #include "jni/JavaHandler_jni.h"
19 #include "mojo/android/system/base_run_loop.h" 19 #include "mojo/android/system/base_run_loop.h"
20 #include "mojo/android/system/core_impl.h" 20 #include "mojo/android/system/core_impl.h"
21 #include "mojo/application/application_runner_chromium.h"
22 #include "mojo/application/content_handler_factory.h" 21 #include "mojo/application/content_handler_factory.h"
22 #include "mojo/environment/scoped_chromium_init.h"
23 #include "mojo/public/c/system/main.h" 23 #include "mojo/public/c/system/main.h"
24 #include "mojo/public/cpp/application/application_impl.h"
25 #include "mojo/public/cpp/application/connect.h" 24 #include "mojo/public/cpp/application/connect.h"
25 #include "mojo/public/cpp/application/run_application.h"
26 #include "mojo/public/cpp/application/service_provider_impl.h"
26 27
27 using base::android::AttachCurrentThread; 28 using base::android::AttachCurrentThread;
28 using base::android::ScopedJavaLocalRef; 29 using base::android::ScopedJavaLocalRef;
29 using base::android::ConvertJavaStringToUTF8; 30 using base::android::ConvertJavaStringToUTF8;
30 using base::android::ConvertUTF8ToJavaString; 31 using base::android::ConvertUTF8ToJavaString;
31 using base::android::GetApplicationContext; 32 using base::android::GetApplicationContext;
32 33
33 namespace { 34 namespace {
34 35
35 bool RegisterJNI(JNIEnv* env) { 36 bool RegisterJNI(JNIEnv* env) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 jobject context = base::android::GetApplicationContext(); 83 jobject context = base::android::GetApplicationContext();
83 ScopedJavaLocalRef<jstring> j_archive_path = 84 ScopedJavaLocalRef<jstring> j_archive_path =
84 ConvertUTF8ToJavaString(env, archive_path.value()); 85 ConvertUTF8ToJavaString(env, archive_path.value());
85 ScopedJavaLocalRef<jstring> j_cache_dir = 86 ScopedJavaLocalRef<jstring> j_cache_dir =
86 ConvertUTF8ToJavaString(env, cache_dir.value()); 87 ConvertUTF8ToJavaString(env, cache_dir.value());
87 Java_JavaHandler_bootstrap( 88 Java_JavaHandler_bootstrap(
88 env, context, j_archive_path.obj(), j_cache_dir.obj(), 89 env, context, j_archive_path.obj(), j_cache_dir.obj(),
89 application_request.PassMessagePipe().release().value()); 90 application_request.PassMessagePipe().release().value());
90 } 91 }
91 92
92 void JavaHandler::Initialize(mojo::ApplicationImpl* app) { 93 void JavaHandler::OnInitialize() {
93 tracing_.Initialize(app->shell(), &app->args()); 94 tracing_.Initialize(shell(), &args());
94 handler_task_runner_ = base::MessageLoop::current()->task_runner(); 95 handler_task_runner_ = base::MessageLoop::current()->task_runner();
95 mojo::ConnectToService(app->shell(), "mojo:url_response_disk_cache", 96 mojo::ConnectToService(shell(), "mojo:url_response_disk_cache",
96 GetProxy(&url_response_disk_cache_)); 97 GetProxy(&url_response_disk_cache_));
97 } 98 }
98 99
99 void JavaHandler::GetApplication(base::FilePath* archive_path, 100 void JavaHandler::GetApplication(base::FilePath* archive_path,
100 base::FilePath* cache_dir, 101 base::FilePath* cache_dir,
101 mojo::URLResponsePtr response, 102 mojo::URLResponsePtr response,
102 const base::Closure& callback) { 103 const base::Closure& callback) {
103 url_response_disk_cache_->UpdateAndGet( 104 url_response_disk_cache_->UpdateAndGet(
104 response.Pass(), 105 response.Pass(),
105 [archive_path, cache_dir, callback](mojo::Array<uint8_t> extracted_path, 106 [archive_path, cache_dir, callback](mojo::Array<uint8_t> extracted_path,
106 mojo::Array<uint8_t> cache_path) { 107 mojo::Array<uint8_t> cache_path) {
107 if (extracted_path.is_null()) { 108 if (extracted_path.is_null()) {
108 *archive_path = base::FilePath(); 109 *archive_path = base::FilePath();
109 *cache_dir = base::FilePath(); 110 *cache_dir = base::FilePath();
110 } else { 111 } else {
111 *archive_path = base::FilePath( 112 *archive_path = base::FilePath(
112 std::string(reinterpret_cast<char*>(&extracted_path.front()), 113 std::string(reinterpret_cast<char*>(&extracted_path.front()),
113 extracted_path.size())); 114 extracted_path.size()));
114 *cache_dir = base::FilePath(std::string( 115 *cache_dir = base::FilePath(std::string(
115 reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); 116 reinterpret_cast<char*>(&cache_path.front()), cache_path.size()));
116 } 117 }
117 callback.Run(); 118 callback.Run();
118 }); 119 });
119 } 120 }
120 121
121 bool JavaHandler::ConfigureIncomingConnection( 122 bool JavaHandler::OnAcceptConnection(
122 mojo::ServiceProviderImpl* service_provider_impl) { 123 mojo::ServiceProviderImpl* service_provider_impl) {
123 service_provider_impl->AddService<mojo::ContentHandler>( 124 service_provider_impl->AddService<mojo::ContentHandler>(
124 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this)); 125 mojo::ContentHandlerFactory::GetInterfaceRequestHandler(this));
125 return true; 126 return true;
126 } 127 }
127 128
128 void PreInvokeEvent(JNIEnv* env, jclass jcaller) { 129 void PreInvokeEvent(JNIEnv* env, jclass jcaller) {
129 TRACE_EVENT_END0("java_handler", "JavaHandler::RunApplication"); 130 TRACE_EVENT_END0("java_handler", "JavaHandler::RunApplication");
130 } 131 }
131 132
132 } // namespace android 133 } // namespace android
133 } // namespace services 134 } // namespace services
134 135
135 MojoResult MojoMain(MojoHandle application_request) { 136 MojoResult MojoMain(MojoHandle application_request) {
136 mojo::ApplicationRunnerChromium runner(new services::android::JavaHandler()); 137 mojo::ScopedChromiumInit init;
137 return runner.Run(application_request); 138 services::android::JavaHandler java_handler;
139 return mojo::RunApplication(application_request, &java_handler);
138 } 140 }
139 141
140 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 142 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
141 std::vector<base::android::RegisterCallback> register_callbacks; 143 std::vector<base::android::RegisterCallback> register_callbacks;
142 register_callbacks.push_back(base::Bind(&RegisterJNI)); 144 register_callbacks.push_back(base::Bind(&RegisterJNI));
143 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) || 145 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
144 !base::android::OnJNIOnLoadInit( 146 !base::android::OnJNIOnLoadInit(
145 std::vector<base::android::InitCallback>())) { 147 std::vector<base::android::InitCallback>())) {
146 return -1; 148 return -1;
147 } 149 }
148 150
149 // There cannot be two AtExit objects triggering at the same time. Remove the 151 // There cannot be two AtExit objects triggering at the same time. Remove the
150 // one from LibraryLoader as ApplicationRunnerChromium also uses one. 152 // one from LibraryLoader as ApplicationRunnerChromium also uses one.
151 base::android::LibraryLoaderExitHook(); 153 base::android::LibraryLoaderExitHook();
152 154
153 return JNI_VERSION_1_4; 155 return JNI_VERSION_1_4;
154 } 156 }
155 157
156 // This is needed because the application needs to access the application 158 // This is needed because the application needs to access the application
157 // context. 159 // context.
158 extern "C" JNI_EXPORT void InitApplicationContext( 160 extern "C" JNI_EXPORT void InitApplicationContext(
159 const base::android::JavaRef<jobject>& context) { 161 const base::android::JavaRef<jobject>& context) {
160 JNIEnv* env = base::android::AttachCurrentThread(); 162 JNIEnv* env = base::android::AttachCurrentThread();
161 base::android::InitApplicationContext(env, context); 163 base::android::InitApplicationContext(env, context);
162 } 164 }
OLDNEW
« no previous file with comments | « services/java_handler/java_handler.h ('k') | services/js/pingpong_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698