Split LoadAndRunNativeApplication() ...

(... to separate LoadNativeApplication() and RunNativeApplication()).

* This is to better support sandboxing in the near future. (Note: All
  the thunks are set in RunNativeApplication(). This should be fine with
  respect to sandboxing. More questionable is the calling of
  InitGoRuntime() (though this is supposedly temporary). We'll worry
  about that if it ever becomes a problem.)
* Also rename the files from dynamic_service_runner.* to
  native_application_support.*.
* Also make a separate native_application_support target. (The inclusion
  of dynamic_service_runner.* in the in_process_native_runner target was
  never really right anyway.
* Remove the (trivial -- just for an enum declaration) dependency of
  native_application_support.* on application_manager. This is so the
  future mojo_shell_child binary won't need to depend on half the world,
  and thus link in dynamic libraries it may not need.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/1046013002
diff --git a/shell/application_manager/BUILD.gn b/shell/application_manager/BUILD.gn
index d7119f0..72a90c8 100644
--- a/shell/application_manager/BUILD.gn
+++ b/shell/application_manager/BUILD.gn
@@ -42,6 +42,7 @@
     "//mojo/edk/system",
     "//mojo/environment:chromium",
     "//mojo/services/content_handler/public/interfaces",
+    "//shell:native_application_support",
     "//shell:switches",
   ]
 }
diff --git a/shell/application_manager/application_manager.cc b/shell/application_manager/application_manager.cc
index b8c4182..50d3468 100644
--- a/shell/application_manager/application_manager.cc
+++ b/shell/application_manager/application_manager.cc
@@ -182,22 +182,23 @@
       parameters);
 
   if (resolved_url.SchemeIsFile()) {
-    new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr),
-                     base::Bind(callback, NativeRunner::DontDeleteAppPath));
+    new LocalFetcher(
+        resolved_url, GetBaseURLAndQuery(resolved_url, nullptr),
+        base::Bind(callback, NativeApplicationCleanup::DONT_DELETE));
     return;
   }
 
   if (!network_service_)
     ConnectToService(GURL("mojo:network_service"), &network_service_);
 
-  const NativeRunner::CleanupBehavior cleanup_behavior =
+  const NativeApplicationCleanup cleanup =
       base::CommandLine::ForCurrentProcess()->HasSwitch(
           switches::kDontDeleteOnDownload)
-          ? NativeRunner::DontDeleteAppPath
-          : NativeRunner::DeleteAppPath;
+          ? NativeApplicationCleanup::DONT_DELETE
+          : NativeApplicationCleanup::DELETE;
 
   new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(),
-                     base::Bind(callback, cleanup_behavior));
+                     base::Bind(callback, cleanup));
 }
 
 bool ApplicationManager::ConnectToRunningApplication(
@@ -276,7 +277,7 @@
     ServiceProviderPtr exposed_services,
     const base::Closure& on_application_end,
     const std::vector<std::string>& parameters,
-    NativeRunner::CleanupBehavior cleanup_behavior,
+    NativeApplicationCleanup cleanup,
     scoped_ptr<Fetcher> fetcher) {
   if (!fetcher) {
     // Network error. Drop |application_request| to tell requestor.
@@ -344,13 +345,13 @@
       blocking_pool_,
       base::Bind(&ApplicationManager::RunNativeApplication,
                  weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()),
-                 options, cleanup_behavior, base::Passed(fetcher.Pass())));
+                 options, cleanup, base::Passed(fetcher.Pass())));
 }
 
 void ApplicationManager::RunNativeApplication(
     InterfaceRequest<Application> application_request,
     const NativeRunnerFactory::Options& options,
-    NativeRunner::CleanupBehavior cleanup_behavior,
+    NativeApplicationCleanup cleanup,
     scoped_ptr<Fetcher> fetcher,
     const base::FilePath& path,
     bool path_exists) {
@@ -369,7 +370,7 @@
                path.AsUTF8Unsafe());
   NativeRunner* runner = native_runner_factory_->Create(options).release();
   native_runners_.push_back(runner);
-  runner->Start(path, cleanup_behavior, application_request.Pass(),
+  runner->Start(path, cleanup, application_request.Pass(),
                 base::Bind(&ApplicationManager::CleanupRunner,
                            weak_ptr_factory_.GetWeakPtr(), runner));
 }
diff --git a/shell/application_manager/application_manager.h b/shell/application_manager/application_manager.h
index 3bcbc0c..5a72c85 100644
--- a/shell/application_manager/application_manager.h
+++ b/shell/application_manager/application_manager.h
@@ -18,6 +18,7 @@
 #include "shell/application_manager/application_loader.h"
 #include "shell/application_manager/identity.h"
 #include "shell/application_manager/native_runner.h"
+#include "shell/native_application_support.h"
 #include "url/gurl.h"
 
 namespace base {
@@ -182,12 +183,12 @@
                            ServiceProviderPtr exposed_services,
                            const base::Closure& on_application_end,
                            const std::vector<std::string>& parameters,
-                           NativeRunner::CleanupBehavior cleanup_behavior,
+                           NativeApplicationCleanup cleanup,
                            scoped_ptr<Fetcher> fetcher);
 
   void RunNativeApplication(InterfaceRequest<Application> application_request,
                             const NativeRunnerFactory::Options& options,
-                            NativeRunner::CleanupBehavior cleanup_behavior,
+                            NativeApplicationCleanup cleanup,
                             scoped_ptr<Fetcher> fetcher,
                             const base::FilePath& file_path,
                             bool path_exists);
diff --git a/shell/application_manager/native_runner.h b/shell/application_manager/native_runner.h
index b9b0304..abcff90 100644
--- a/shell/application_manager/native_runner.h
+++ b/shell/application_manager/native_runner.h
@@ -9,6 +9,7 @@
 #include "base/memory/scoped_ptr.h"
 #include "mojo/public/cpp/bindings/interface_request.h"
 #include "mojo/public/interfaces/application/application.mojom.h"
+#include "shell/native_application_support.h"
 
 namespace base {
 class FilePath;
@@ -21,20 +22,17 @@
 // NativeRunnerFactory to run native applications.
 class NativeRunner {
  public:
-  // Parameter for |Start()| to specify its cleanup behavior.
-  enum CleanupBehavior { DeleteAppPath, DontDeleteAppPath };
-
   virtual ~NativeRunner() {}
 
   // Loads the app in the file at |app_path| and runs it on some other
-  // thread/process. If |cleanup_behavior| is |true|, takes ownership of the
-  // file. |app_completed_callback| is posted (to the thread on which |Start()|
-  // was called) after |MojoMain()| completes.
-  // TODO(vtl): |app_path| and |cleanup_behavior| should probably be moved to
-  // the factory's Create(). Rationale: The factory may need information from
-  // the file to decide what kind of NativeRunner to make.
+  // thread/process. If |cleanup| is |DELETE|, this takes ownership of the file.
+  // |app_completed_callback| is posted (to the thread on which |Start()| was
+  // called) after |MojoMain()| completes.
+  // TODO(vtl): |app_path| and |cleanup| should probably be moved to the
+  // factory's Create(). Rationale: The factory may need information from the
+  // file to decide what kind of NativeRunner to make.
   virtual void Start(const base::FilePath& app_path,
-                     CleanupBehavior cleanup_behavior,
+                     NativeApplicationCleanup cleanup,
                      InterfaceRequest<Application> application_request,
                      const base::Closure& app_completed_callback) = 0;
 };