Build libraries for a number of services.

Build libraries additionally to mojo applications for the following services:
- services/files
- services/icu_data
- services/tracing
- services/ui/input_manager
- services/ui/launcher

R=ppi@chromium.org

Review URL: https://codereview.chromium.org/1987363004 .
diff --git a/services/files/BUILD.gn b/services/files/BUILD.gn
index e00eb06..d804042 100644
--- a/services/files/BUILD.gn
+++ b/services/files/BUILD.gn
@@ -6,15 +6,27 @@
 
 mojo_native_application("files") {
   sources = [
+    "main.cc",
+  ]
+
+  deps = [
+    ":lib",
+    "//mojo/application",
+  ]
+}
+
+source_set("lib") {
+  sources = [
     "directory_impl.cc",
     "directory_impl.h",
     "file_impl.cc",
     "file_impl.h",
+    "files_app.cc",
+    "files_app.h",
     "files_impl.cc",
     "files_impl.h",
     "futimens.h",
     "futimens_android.cc",
-    "main.cc",
     "shared_impl.cc",
     "shared_impl.h",
     "util.cc",
diff --git a/services/files/files_app.cc b/services/files/files_app.cc
new file mode 100644
index 0000000..368b5a0
--- /dev/null
+++ b/services/files/files_app.cc
@@ -0,0 +1,27 @@
+// Copyright 2016 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.
+
+#include "services/files/files_app.h"
+
+#include "mojo/services/files/interfaces/files.mojom.h"
+#include "services/files/files_impl.h"
+
+namespace mojo {
+namespace files {
+
+FilesApp::FilesApp() {}
+FilesApp::~FilesApp() {}
+
+bool FilesApp::ConfigureIncomingConnection(
+    ServiceProviderImpl* service_provider_impl) {
+  service_provider_impl->AddService<Files>(
+      [](const ConnectionContext& connection_context,
+         InterfaceRequest<Files> files_request) {
+        new FilesImpl(connection_context, files_request.Pass());
+      });
+  return true;
+}
+
+}  // namespace files
+}  // namespace mojo
diff --git a/services/files/files_app.h b/services/files/files_app.h
new file mode 100644
index 0000000..3bd7810
--- /dev/null
+++ b/services/files/files_app.h
@@ -0,0 +1,31 @@
+// Copyright 2016 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 SERVICES_FILES_FILES_APP_H_
+#define SERVICES_FILES_FILES_APP_H_
+
+#include "base/macros.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/service_provider_impl.h"
+
+namespace mojo {
+namespace files {
+
+class FilesApp : public ApplicationDelegate {
+ public:
+  FilesApp();
+  ~FilesApp() override;
+
+ private:
+  // |ApplicationDelegate| override:
+  bool ConfigureIncomingConnection(
+      ServiceProviderImpl* service_provider_impl) override;
+
+  DISALLOW_COPY_AND_ASSIGN(FilesApp);
+};
+
+}  // namespace files
+}  // namespace mojo
+
+#endif  // SERVICES_FILES_FILES_APP_H_
diff --git a/services/files/main.cc b/services/files/main.cc
index 04f61a9..07effcf 100644
--- a/services/files/main.cc
+++ b/services/files/main.cc
@@ -2,39 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/macros.h"
 #include "mojo/application/application_runner_chromium.h"
 #include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/services/files/interfaces/files.mojom.h"
-#include "services/files/files_impl.h"
-
-namespace mojo {
-namespace files {
-
-class FilesApp : public ApplicationDelegate {
- public:
-  FilesApp() {}
-  ~FilesApp() override {}
-
- private:
-  // |ApplicationDelegate| override:
-  bool ConfigureIncomingConnection(
-      ServiceProviderImpl* service_provider_impl) override {
-    service_provider_impl->AddService<Files>(
-        [](const ConnectionContext& connection_context,
-           InterfaceRequest<Files> files_request) {
-          new FilesImpl(connection_context, files_request.Pass());
-        });
-    return true;
-  }
-
-  DISALLOW_COPY_AND_ASSIGN(FilesApp);
-};
-
-}  // namespace files
-}  // namespace mojo
+#include "services/files/files_app.h"
 
 MojoResult MojoMain(MojoHandle application_request) {
   mojo::ApplicationRunnerChromium runner(new mojo::files::FilesApp());
diff --git a/services/icu_data/BUILD.gn b/services/icu_data/BUILD.gn
index 094f32c..9e29c2c 100644
--- a/services/icu_data/BUILD.gn
+++ b/services/icu_data/BUILD.gn
@@ -18,6 +18,17 @@
 
 mojo_native_application("icu_data") {
   sources = [
+    "main.cc",
+  ]
+
+  deps = [
+    ":lib",
+    "//mojo/application",
+  ]
+}
+
+source_set("lib") {
+  sources = [
     "icu_data_impl.cc",
   ]
 
diff --git a/services/icu_data/icu_data_impl.cc b/services/icu_data/icu_data_impl.cc
index c1566f6..48614fe 100644
--- a/services/icu_data/icu_data_impl.cc
+++ b/services/icu_data/icu_data_impl.cc
@@ -2,69 +2,53 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/common/binding_set.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
+#include "services/icu_data/icu_data_impl.h"
+
 #include "mojo/public/cpp/bindings/interface_ptr.h"
-#include "mojo/services/icu_data/interfaces/icu_data.mojom.h"
 #include "services/icu_data/kICUData.h"
 
 namespace icu_data {
 
-class ICUDataImpl : public mojo::ApplicationDelegate, public ICUData {
- public:
-  ICUDataImpl() {}
-  ~ICUDataImpl() override {}
+ICUDataImpl::ICUDataImpl() {}
+ICUDataImpl::~ICUDataImpl() {}
 
-  // mojo::ApplicationDelegate implementation.
-  bool ConfigureIncomingConnection(
-      mojo::ServiceProviderImpl* service_provider_impl) override {
-    service_provider_impl->AddService<ICUData>(
-        [this](const mojo::ConnectionContext& connection_context,
-               mojo::InterfaceRequest<ICUData> icu_data_request) {
-          bindings_.AddBinding(this, icu_data_request.Pass());
-        });
+bool ICUDataImpl::ConfigureIncomingConnection(
+    mojo::ServiceProviderImpl* service_provider_impl) {
+  service_provider_impl->AddService<ICUData>(
+      [this](const mojo::ConnectionContext& connection_context,
+             mojo::InterfaceRequest<ICUData> icu_data_request) {
+        bindings_.AddBinding(this, icu_data_request.Pass());
+      });
 
-    return true;
-  }
-
-  void Map(const mojo::String& sha1hash,
-           const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
-      override {
-    if (std::string(sha1hash) != std::string(kICUData.hash)) {
-      LOG(WARNING) << "Failed to match sha1sum. Expected " << kICUData.hash;
-      callback.Run(mojo::ScopedSharedBufferHandle());
-      return;
-    }
-    EnsureBuffer();
-    mojo::ScopedSharedBufferHandle handle;
-    // FIXME: We should create a read-only duplicate of the handle.
-    mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
-    callback.Run(handle.Pass());
-  }
-
- private:
-  void EnsureBuffer() {
-    if (buffer_)
-      return;
-    buffer_.reset(new mojo::SharedBuffer(kICUData.size));
-    void* ptr = nullptr;
-    MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kICUData.size,
-                                    &ptr, MOJO_MAP_BUFFER_FLAG_NONE);
-    CHECK_EQ(rv, MOJO_RESULT_OK);
-    memcpy(ptr, kICUData.data, kICUData.size);
-    rv = mojo::UnmapBuffer(ptr);
-    CHECK_EQ(rv, MOJO_RESULT_OK);
-  }
-
-  scoped_ptr<mojo::SharedBuffer> buffer_;
-  mojo::BindingSet<ICUData> bindings_;
-};
+  return true;
 }
 
-MojoResult MojoMain(MojoHandle application_request) {
-  mojo::ApplicationRunnerChromium runner(new icu_data::ICUDataImpl);
-  return runner.Run(application_request);
+void ICUDataImpl::Map(
+    const mojo::String& sha1hash,
+    const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback) {
+  if (std::string(sha1hash) != std::string(kICUData.hash)) {
+    LOG(WARNING) << "Failed to match sha1sum. Expected " << kICUData.hash;
+    callback.Run(mojo::ScopedSharedBufferHandle());
+    return;
+  }
+  EnsureBuffer();
+  mojo::ScopedSharedBufferHandle handle;
+  // FIXME: We should create a read-only duplicate of the handle.
+  mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
+  callback.Run(handle.Pass());
 }
+
+void ICUDataImpl::EnsureBuffer() {
+  if (buffer_)
+    return;
+  buffer_.reset(new mojo::SharedBuffer(kICUData.size));
+  void* ptr = nullptr;
+  MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kICUData.size, &ptr,
+                                  MOJO_MAP_BUFFER_FLAG_NONE);
+  CHECK_EQ(rv, MOJO_RESULT_OK);
+  memcpy(ptr, kICUData.data, kICUData.size);
+  rv = mojo::UnmapBuffer(ptr);
+  CHECK_EQ(rv, MOJO_RESULT_OK);
+}
+
+}  // namespace icu_data
diff --git a/services/icu_data/icu_data_impl.h b/services/icu_data/icu_data_impl.h
new file mode 100644
index 0000000..6c81120
--- /dev/null
+++ b/services/icu_data/icu_data_impl.h
@@ -0,0 +1,33 @@
+// Copyright 2016 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.
+
+#include "base/memory/scoped_ptr.h"
+#include "mojo/common/binding_set.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/service_provider_impl.h"
+#include "mojo/services/icu_data/interfaces/icu_data.mojom.h"
+
+namespace icu_data {
+
+class ICUDataImpl : public mojo::ApplicationDelegate, public ICUData {
+ public:
+  ICUDataImpl();
+  ~ICUDataImpl() override;
+
+  // mojo::ApplicationDelegate implementation.
+  bool ConfigureIncomingConnection(
+      mojo::ServiceProviderImpl* service_provider_impl) override;
+
+  void Map(const mojo::String& sha1hash,
+           const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
+      override;
+
+ private:
+  void EnsureBuffer();
+
+  scoped_ptr<mojo::SharedBuffer> buffer_;
+  mojo::BindingSet<ICUData> bindings_;
+};
+
+}  // namespace icu_data;
diff --git a/services/icu_data/main.cc b/services/icu_data/main.cc
new file mode 100644
index 0000000..a10d795
--- /dev/null
+++ b/services/icu_data/main.cc
@@ -0,0 +1,12 @@
+// Copyright 2016 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.
+
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/public/c/system/main.h"
+#include "services/icu_data/icu_data_impl.h"
+
+MojoResult MojoMain(MojoHandle application_request) {
+  mojo::ApplicationRunnerChromium runner(new icu_data::ICUDataImpl);
+  return runner.Run(application_request);
+}
diff --git a/services/tracing/BUILD.gn b/services/tracing/BUILD.gn
index ae3e221..346db9d 100644
--- a/services/tracing/BUILD.gn
+++ b/services/tracing/BUILD.gn
@@ -8,6 +8,16 @@
 mojo_native_application("tracing") {
   sources = [
     "main.cc",
+  ]
+
+  deps = [
+    ":lib",
+    "//mojo/application",
+  ]
+}
+
+source_set("lib") {
+  sources = [
     "trace_data_sink.cc",
     "trace_data_sink.h",
     "trace_recorder_impl.cc",
diff --git a/services/ui/input_manager/BUILD.gn b/services/ui/input_manager/BUILD.gn
index 0fd3ecf..a9bc0f8 100644
--- a/services/ui/input_manager/BUILD.gn
+++ b/services/ui/input_manager/BUILD.gn
@@ -9,6 +9,17 @@
   output_name = "input_manager_service"
 
   sources = [
+    "main.cc",
+  ]
+
+  deps = [
+    ":lib",
+    "//mojo/application",
+  ]
+}
+
+source_set("lib") {
+  sources = [
     "input_associate.cc",
     "input_associate.h",
     "input_connection_impl.cc",
@@ -17,7 +28,6 @@
     "input_dispatcher_impl.h",
     "input_manager_app.cc",
     "input_manager_app.h",
-    "main.cc",
   ]
 
   deps = [
diff --git a/services/ui/launcher/BUILD.gn b/services/ui/launcher/BUILD.gn
index db8ef8e..3ea007b 100644
--- a/services/ui/launcher/BUILD.gn
+++ b/services/ui/launcher/BUILD.gn
@@ -8,13 +8,23 @@
 
 mojo_native_application("launcher") {
   sources = [
+    "main.cc",
+  ]
+
+  deps = [
+    ":lib",
+    "//mojo/application",
+  ]
+}
+
+source_set("lib") {
+  sources = [
     "launch_instance.cc",
     "launch_instance.h",
     "launcher_app.cc",
     "launcher_app.h",
     "launcher_view_tree.cc",
     "launcher_view_tree.h",
-    "main.cc",
   ]
 
   deps = [