Do some plumbing.

* Move execution options for native apps into its own independent
  struct (rather than be NativeRunnerFactory::Options).
* Plumb this all the way down, using it appropriately (this requires
  adding fields to the options struct).
* E.g., require_32_bit is now one of the options.
* In ApplicationManager, replace SetNativeOptionsForURL() with something
  that returns a (non-const) reference to the options struct for the
  give URL. This is useful since we sometimes want to fiddle with
  various options independently.
* Add a "allow_new_privs" option. When running in multiprocess, we may
  or may not want the child to acquire new privileges (typically not,
  but sometimes -- e.g., without it, you can't run sudo/screen/other
  setuid programs through mojo:native_support).
* Hack in hardcoded support to set allow_new_privs for
  mojo:native_support.
* In general, we need a better, more complete, more consistent way of
  setting options for native apps (e.g., sandboxing options).

R=vardhan@google.com

Review URL: https://codereview.chromium.org/1378303005 .
diff --git a/shell/application_manager/BUILD.gn b/shell/application_manager/BUILD.gn
index b51332a..273b5fe 100644
--- a/shell/application_manager/BUILD.gn
+++ b/shell/application_manager/BUILD.gn
@@ -19,6 +19,7 @@
     "identity.h",
     "local_fetcher.cc",
     "local_fetcher.h",
+    "native_application_options.h",
     "native_runner.h",
     "network_fetcher.cc",
     "network_fetcher.h",
diff --git a/shell/application_manager/application_manager.cc b/shell/application_manager/application_manager.cc
index 3d411a7..8fcfdd5 100644
--- a/shell/application_manager/application_manager.cc
+++ b/shell/application_manager/application_manager.cc
@@ -352,7 +352,7 @@
   // TODO(vtl): (Maybe this should be done by the factory/runner?)
 
   GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr);
-  NativeRunnerFactory::Options options;
+  NativeApplicationOptions options;
   if (url_to_native_options_.find(base_resolved_url) !=
       url_to_native_options_.end()) {
     DVLOG(2) << "Applying stored native options to resolved URL "
@@ -371,7 +371,7 @@
 
 void ApplicationManager::RunNativeApplication(
     InterfaceRequest<Application> application_request,
-    const NativeRunnerFactory::Options& options,
+    const NativeApplicationOptions& options,
     scoped_ptr<Fetcher> fetcher,
     const base::FilePath& path,
     bool path_exists) {
@@ -448,19 +448,16 @@
   }
 }
 
-void ApplicationManager::SetNativeOptionsForURL(
-    const NativeRunnerFactory::Options& options,
+NativeApplicationOptions* ApplicationManager::GetNativeApplicationOptionsForURL(
     const GURL& url) {
   DCHECK(!url.has_query());  // Precondition.
   // Apply mappings and resolution to get the resolved URL.
   GURL resolved_url =
       delegate_->ResolveMojoURL(delegate_->ResolveMappings(url));
-  DCHECK(!resolved_url.has_query());  // Still shouldn't have query.
   // TODO(vtl): We should probably also remove/disregard the query string (and
   // maybe canonicalize in other ways).
-  DVLOG(2) << "Storing native options for resolved URL " << resolved_url
-           << " (original URL " << url << ")";
-  url_to_native_options_[resolved_url] = options;
+  DCHECK(!resolved_url.has_query());  // Still shouldn't have query.
+  return &url_to_native_options_[resolved_url];
 }
 
 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
diff --git a/shell/application_manager/application_manager.h b/shell/application_manager/application_manager.h
index d1fc338..9365ef4 100644
--- a/shell/application_manager/application_manager.h
+++ b/shell/application_manager/application_manager.h
@@ -18,6 +18,7 @@
 #include "mojo/services/url_response_disk_cache/public/interfaces/url_response_disk_cache.mojom.h"
 #include "shell/application_manager/application_loader.h"
 #include "shell/application_manager/identity.h"
+#include "shell/application_manager/native_application_options.h"
 #include "shell/application_manager/native_runner.h"
 #include "shell/native_application_support.h"
 #include "url/gurl.h"
@@ -117,18 +118,18 @@
                           const std::string& scheme);
   // These strings will be passed to the Initialize() method when an Application
   // is instantiated.
-  // TODO(vtl): Maybe we should store/compare resolved URLs, like
-  // SetNativeOptionsForURL() below?
+  // TODO(vtl): Maybe we should store/compare resolved URLs?
   void SetArgsForURL(const std::vector<std::string>& args, const GURL& url);
   // These options will be used in running any native application at |url|
   // (which shouldn't contain a query string). (|url| will be mapped and
   // resolved, and any application whose base resolved URL matches it will have
   // |options| applied.)
+  // Note: Calling this for a URL will add (default) options for that URL if
+  // necessary.
   // TODO(vtl): This may not do what's desired if the resolved URL results in an
   // HTTP redirect. Really, we want options to be identified with a particular
   // implementation, maybe via a signed manifest or something like that.
-  void SetNativeOptionsForURL(const NativeRunnerFactory::Options& options,
-                              const GURL& url);
+  NativeApplicationOptions* GetNativeApplicationOptionsForURL(const GURL& url);
 
   // Destroys all Shell-ends of connections established with Applications.
   // Applications connected by this ApplicationManager will observe pipe errors
@@ -141,15 +142,15 @@
  private:
   class ContentHandlerConnection;
 
-  typedef std::map<GURL, scoped_ptr<ApplicationLoader>> URLToLoaderMap;
-  typedef std::map<std::string, scoped_ptr<ApplicationLoader>>
-      SchemeToLoaderMap;
-  typedef std::map<Identity, scoped_ptr<ShellImpl>> IdentityToShellImplMap;
-  typedef std::map<GURL, scoped_ptr<ContentHandlerConnection>>
-      URLToContentHandlerMap;
-  typedef std::map<GURL, std::vector<std::string>> URLToArgsMap;
-  typedef std::map<std::string, GURL> MimeTypeToURLMap;
-  typedef std::map<GURL, NativeRunnerFactory::Options> URLToNativeOptionsMap;
+  using URLToLoaderMap = std::map<GURL, scoped_ptr<ApplicationLoader>>;
+  using SchemeToLoaderMap =
+      std::map<std::string, scoped_ptr<ApplicationLoader>>;
+  using IdentityToShellImplMap = std::map<Identity, scoped_ptr<ShellImpl>>;
+  using URLToContentHandlerMap =
+      std::map<GURL, scoped_ptr<ContentHandlerConnection>>;
+  using URLToArgsMap = std::map<GURL, std::vector<std::string>>;
+  using MimeTypeToURLMap = std::map<std::string, GURL>;
+  using URLToNativeOptionsMap = std::map<GURL, NativeApplicationOptions>;
 
   void ConnectToApplicationWithParameters(
       const GURL& application_url,
@@ -201,7 +202,7 @@
 
   void RunNativeApplication(
       mojo::InterfaceRequest<mojo::Application> application_request,
-      const NativeRunnerFactory::Options& options,
+      const NativeApplicationOptions& options,
       scoped_ptr<Fetcher> fetcher,
       const base::FilePath& file_path,
       bool path_exists);
diff --git a/shell/application_manager/native_application_options.h b/shell/application_manager/native_application_options.h
new file mode 100644
index 0000000..f4c71c4
--- /dev/null
+++ b/shell/application_manager/native_application_options.h
@@ -0,0 +1,22 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHELL_APPLICATION_MANAGER_NATIVE_APPLICATION_OPTIONS_H_
+#define SHELL_APPLICATION_MANAGER_NATIVE_APPLICATION_OPTIONS_H_
+
+namespace shell {
+
+// Options relevant to running native applications. (Note that some of these may
+// be set at different stages, as more is learned about the application.)
+// TODO(vtl): Maybe these some of these should be tristate (unknown/true/false)
+// instead of of booleans.
+struct NativeApplicationOptions {
+  bool force_in_process = false;
+  bool require_32_bit = false;
+  bool allow_new_privs = false;
+};
+
+}  // namespace shell
+
+#endif  // SHELL_APPLICATION_MANAGER_NATIVE_APPLICATION_OPTIONS_H_
diff --git a/shell/application_manager/native_runner.h b/shell/application_manager/native_runner.h
index e50bb08..886bfc9 100644
--- a/shell/application_manager/native_runner.h
+++ b/shell/application_manager/native_runner.h
@@ -17,6 +17,8 @@
 
 namespace shell {
 
+struct NativeApplicationOptions;
+
 // ApplicationManager requires implementations of NativeRunner and
 // NativeRunnerFactory to run native applications.
 class NativeRunner {
@@ -39,17 +41,9 @@
 
 class NativeRunnerFactory {
  public:
-  // Options for running the native app. (This will contain, e.g., information
-  // about the sandbox profile, etc.)
-  struct Options {
-    // Constructs with default options.
-    Options() : force_in_process(false) {}
-
-    bool force_in_process;
-  };
-
   virtual ~NativeRunnerFactory() {}
-  virtual scoped_ptr<NativeRunner> Create(const Options& options) = 0;
+  virtual scoped_ptr<NativeRunner> Create(
+      const NativeApplicationOptions& options) = 0;
 };
 
 }  // namespace shell