Chromium Code Reviews| Index: shell/android/android_handler.cc |
| diff --git a/shell/android/android_handler.cc b/shell/android/android_handler.cc |
| index 036be298e6fa9131bf64ce63a762dabcfda2f27a..14c450d580bbf44eb01e1d861ac7f68871726692 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; |
| @@ -83,6 +84,11 @@ AndroidHandler::AndroidHandler() : content_handler_factory_(this) { |
| AndroidHandler::~AndroidHandler() { |
| } |
| +void RunClosure(scoped_refptr<base::SingleThreadTaskRunner> runner, |
| + const base::Closure& closure) { |
| + runner->PostTask(FROM_HERE, closure); |
| +} |
| + |
| void AndroidHandler::RunApplication( |
| mojo::InterfaceRequest<mojo::Application> application_request, |
| mojo::URLResponsePtr response) { |
| @@ -90,20 +96,35 @@ 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; |
| + 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(&RunClosure, loop.task_runner(), |
| + base::MessageLoop::QuitWhenIdleClosure()))); |
| + base::RunLoop().Run(); |
|
DaveMoore
2015/05/05 21:20:59
What makes this runloop exit?
qsr
2015/05/06 08:13:49
In the previous line, the callback to ExtractAppli
|
| + } |
| - 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 +134,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); |
| } |