Index: shell/android/android_handler.cc |
diff --git a/shell/android/android_handler.cc b/shell/android/android_handler.cc |
index 036be298e6fa9131bf64ce63a762dabcfda2f27a..6410cdde602b0a4a0333fe2bfa87697567a35253 100644 |
--- a/shell/android/android_handler.cc |
+++ b/shell/android/android_handler.cc |
@@ -8,6 +8,8 @@ |
#include "base/android/jni_string.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
#include "base/scoped_native_library.h" |
#include "base/trace_event/trace_event.h" |
#include "jni/AndroidHandler_jni.h" |
@@ -43,8 +45,7 @@ void RunAndroidApplication(JNIEnv* env, |
// Load the library, so that we can set the application context there if |
// needed. |
// TODO(vtl): We'd use a ScopedNativeLibrary, but it doesn't have .get()! |
- base::NativeLibrary app_library = |
- LoadNativeApplication(app_path, NativeApplicationCleanup::DELETE); |
+ base::NativeLibrary app_library = LoadNativeApplication(app_path); |
if (!app_library) |
return; |
@@ -90,20 +91,37 @@ void AndroidHandler::RunApplication( |
uintptr_t tracing_id = reinterpret_cast<uintptr_t>(this); |
TRACE_EVENT_ASYNC_BEGIN1("android_handler", "AndroidHandler::RunApplication", |
tracing_id, "url", std::string(response->url)); |
- ScopedJavaLocalRef<jstring> j_archive_path = |
- Java_AndroidHandler_getNewTempArchivePath(env, GetApplicationContext()); |
- base::FilePath archive_path( |
- ConvertJavaStringToUTF8(env, j_archive_path.obj())); |
+ base::FilePath extracted_dir; |
+ base::FilePath cache_dir; |
+ { |
+ base::MessageLoop loop; |
blundell
2015/05/07 11:29:22
Any reason not to put the stuff from line 110 on i
qsr
2015/05/07 12:49:02
Because the runloop must die after line 108. We do
|
+ handler_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&AndroidHandler::ExtractApplication, base::Unretained(this), |
+ base::Unretained(&extracted_dir), |
+ base::Unretained(&cache_dir), base::Passed(response.Pass()), |
+ base::Bind(base::IgnoreResult( |
+ &base::SingleThreadTaskRunner::PostTask), |
+ loop.task_runner(), FROM_HERE, |
+ base::MessageLoop::QuitWhenIdleClosure()))); |
+ base::RunLoop().Run(); |
+ } |
- mojo::common::BlockingCopyToFile(response->body.Pass(), archive_path); |
+ ScopedJavaLocalRef<jstring> j_extracted_dir = |
+ ConvertUTF8ToJavaString(env, extracted_dir.value()); |
+ ScopedJavaLocalRef<jstring> j_cache_dir = |
+ ConvertUTF8ToJavaString(env, cache_dir.value()); |
RunAndroidApplicationFn run_android_application_fn = &RunAndroidApplication; |
Java_AndroidHandler_bootstrap( |
- env, GetApplicationContext(), tracing_id, j_archive_path.obj(), |
+ env, GetApplicationContext(), tracing_id, j_extracted_dir.obj(), |
+ j_cache_dir.obj(), |
application_request.PassMessagePipe().release().value(), |
reinterpret_cast<jlong>(run_android_application_fn)); |
} |
void AndroidHandler::Initialize(mojo::ApplicationImpl* app) { |
+ handler_task_runner_ = base::MessageLoop::current()->task_runner(); |
+ app->ConnectToService("mojo:service_cache", &service_cache_); |
} |
bool AndroidHandler::ConfigureIncomingConnection( |
@@ -113,6 +131,28 @@ bool AndroidHandler::ConfigureIncomingConnection( |
return true; |
} |
+void AndroidHandler::ExtractApplication(base::FilePath* extracted_dir, |
+ base::FilePath* cache_dir, |
+ mojo::URLResponsePtr response, |
+ const base::Closure& callback) { |
+ service_cache_->GetExtractedContent( |
+ response.Pass(), |
+ [extracted_dir, cache_dir, callback](mojo::Array<uint8_t> extracted_path, |
+ mojo::Array<uint8_t> cache_path) { |
+ if (extracted_path.is_null()) { |
+ *extracted_dir = base::FilePath(); |
+ *cache_dir = base::FilePath(); |
+ } else { |
+ *extracted_dir = base::FilePath( |
+ std::string(reinterpret_cast<char*>(&extracted_path.front()), |
+ extracted_path.size())); |
+ *cache_dir = base::FilePath(std::string( |
+ reinterpret_cast<char*>(&cache_path.front()), cache_path.size())); |
+ } |
+ callback.Run(); |
+ }); |
+} |
+ |
bool RegisterAndroidHandlerJni(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |