ApplicationConnection devolution, part 1.

Remove everything from ApplicationConnection other than
GetServiceProviderImpl() (which is a pure virtual method) and
AddService<I>() (which is a templated method).

R=vardhan@google.com

Review URL: https://codereview.chromium.org/1977043002 .
diff --git a/examples/bank_app/bank.cc b/examples/bank_app/bank.cc
index 7229c6f..4593b13 100644
--- a/examples/bank_app/bank.cc
+++ b/examples/bank_app/bank.cc
@@ -59,7 +59,8 @@
   // From ApplicationDelegate
   bool ConfigureIncomingConnection(
       mojo::ApplicationConnection* connection) override {
-    std::string url = connection->GetRemoteApplicationURL();
+    std::string url =
+        connection->GetServiceProviderImpl().connection_context().remote_url;
     if (url.length() > 0) {
       vanadium::AppInstanceNamePtr app(vanadium::AppInstanceName::New());
       app->url = url;
diff --git a/mojo/public/cpp/application/application_connection.h b/mojo/public/cpp/application/application_connection.h
index e665cd4..49a0da8 100644
--- a/mojo/public/cpp/application/application_connection.h
+++ b/mojo/public/cpp/application/application_connection.h
@@ -5,6 +5,7 @@
 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
 
+#include <memory>
 #include <string>
 
 #include "mojo/public/cpp/application/lib/interface_factory_connector.h"
@@ -46,33 +47,13 @@
   // |factory| will create implementations of Interface on demand.
   template <typename Interface>
   void AddService(InterfaceFactory<Interface>* factory) {
-    SetServiceConnectorForName(
-        new internal::InterfaceFactoryConnector<Interface>(factory),
+    GetServiceProviderImpl().AddServiceForName(
+        std::unique_ptr<ServiceConnector>(
+            new internal::InterfaceFactoryConnector<Interface>(factory)),
         Interface::Name_);
   }
 
   virtual ServiceProviderImpl& GetServiceProviderImpl() = 0;
-
-  virtual const ConnectionContext& GetConnectionContext() const = 0;
-
-  // Returns the URL that was used by the source application to establish a
-  // connection to the destination application.
-  //
-  // When ApplicationConnection is representing an incoming connection this can
-  // be different than the URL the application was initially loaded from, if the
-  // application handles multiple URLs. Note that this is the URL after all
-  // URL rewriting and HTTP redirects have been performed.
-  //
-  // When ApplicationConnection is representing and outgoing connection, this
-  // will be the same as the value returned by GetRemoveApplicationURL().
-  virtual const std::string& GetConnectionURL() = 0;
-
-  // Returns the URL identifying the remote application on this connection.
-  virtual const std::string& GetRemoteApplicationURL() = 0;
-
- private:
-  virtual void SetServiceConnectorForName(ServiceConnector* service_connector,
-                                          const std::string& name) = 0;
 };
 
 }  // namespace mojo
diff --git a/mojo/public/cpp/application/lib/service_registry.cc b/mojo/public/cpp/application/lib/service_registry.cc
index 74372d3..b36b63b 100644
--- a/mojo/public/cpp/application/lib/service_registry.cc
+++ b/mojo/public/cpp/application/lib/service_registry.cc
@@ -19,13 +19,6 @@
 
 ServiceRegistry::~ServiceRegistry() {}
 
-void ServiceRegistry::SetServiceConnectorForName(
-    ServiceConnector* service_connector,
-    const std::string& interface_name) {
-  service_provider_impl_.AddServiceForName(
-      std::unique_ptr<ServiceConnector>(service_connector), interface_name);
-}
-
 void ServiceRegistry::RemoveServiceConnectorForName(
     const std::string& interface_name) {
   service_provider_impl_.RemoveServiceForName(interface_name);
@@ -35,17 +28,5 @@
   return service_provider_impl_;
 }
 
-const ConnectionContext& ServiceRegistry::GetConnectionContext() const {
-  return service_provider_impl_.connection_context();
-}
-
-const std::string& ServiceRegistry::GetConnectionURL() {
-  return service_provider_impl_.connection_context().connection_url;
-}
-
-const std::string& ServiceRegistry::GetRemoteApplicationURL() {
-  return service_provider_impl_.connection_context().remote_url;
-}
-
 }  // namespace internal
 }  // namespace mojo
diff --git a/mojo/public/cpp/application/lib/service_registry.h b/mojo/public/cpp/application/lib/service_registry.h
index 26027f4..0e2789d 100644
--- a/mojo/public/cpp/application/lib/service_registry.h
+++ b/mojo/public/cpp/application/lib/service_registry.h
@@ -24,12 +24,7 @@
   ~ServiceRegistry() override;
 
   // ApplicationConnection overrides.
-  void SetServiceConnectorForName(ServiceConnector* service_connector,
-                                  const std::string& interface_name) override;
   ServiceProviderImpl& GetServiceProviderImpl() override;
-  const ConnectionContext& GetConnectionContext() const override;
-  const std::string& GetConnectionURL() override;
-  const std::string& GetRemoteApplicationURL() override;
 
   void RemoveServiceConnectorForName(const std::string& interface_name);
 
diff --git a/mojo/public/cpp/application/tests/BUILD.gn b/mojo/public/cpp/application/tests/BUILD.gn
index 284f54d..30f3c50 100644
--- a/mojo/public/cpp/application/tests/BUILD.gn
+++ b/mojo/public/cpp/application/tests/BUILD.gn
@@ -9,7 +9,6 @@
 
   sources = [
     "service_provider_impl_unittest.cc",
-    "service_registry_unittest.cc",
   ]
 
   deps = [
diff --git a/mojo/public/cpp/application/tests/service_registry_unittest.cc b/mojo/public/cpp/application/tests/service_registry_unittest.cc
deleted file mode 100644
index 304259e..0000000
--- a/mojo/public/cpp/application/tests/service_registry_unittest.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2014 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/public/cpp/application/lib/service_registry.h"
-
-#include "mojo/public/cpp/application/service_connector.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace internal {
-namespace {
-
-class TestConnector : public ServiceConnector {
- public:
-  explicit TestConnector(int* delete_count) : delete_count_(delete_count) {}
-  ~TestConnector() override { (*delete_count_)++; }
-  void ConnectToService(const ConnectionContext& connection_context,
-                        const std::string& interface_name,
-                        ScopedMessagePipeHandle client_handle) override {}
-
- private:
-  int* delete_count_;
-};
-
-TEST(ServiceRegistryTest, Ownership) {
-  int delete_count = 0;
-
-  // Destruction.
-  {
-    ServiceRegistry registry;
-    registry.SetServiceConnectorForName(new TestConnector(&delete_count),
-                                        "TC1");
-  }
-  EXPECT_EQ(1, delete_count);
-
-  // Removal.
-  {
-    ServiceRegistry registry;
-    ServiceConnector* c = new TestConnector(&delete_count);
-    registry.SetServiceConnectorForName(c, "TC1");
-    registry.RemoveServiceConnectorForName("TC1");
-    EXPECT_EQ(2, delete_count);
-  }
-
-  // Multiple.
-  {
-    ServiceRegistry registry;
-    registry.SetServiceConnectorForName(new TestConnector(&delete_count),
-                                        "TC1");
-    registry.SetServiceConnectorForName(new TestConnector(&delete_count),
-                                        "TC2");
-  }
-  EXPECT_EQ(4, delete_count);
-
-  // Re-addition.
-  {
-    ServiceRegistry registry;
-    registry.SetServiceConnectorForName(new TestConnector(&delete_count),
-                                        "TC1");
-    registry.SetServiceConnectorForName(new TestConnector(&delete_count),
-                                        "TC1");
-    EXPECT_EQ(5, delete_count);
-  }
-  EXPECT_EQ(6, delete_count);
-}
-
-}  // namespace
-}  // namespace internal
-}  // namespace mojo
diff --git a/services/dart/content_handler_main.cc b/services/dart/content_handler_main.cc
index 4808811..a8c6d2a 100644
--- a/services/dart/content_handler_main.cc
+++ b/services/dart/content_handler_main.cc
@@ -238,7 +238,9 @@
   // Overridden from ApplicationDelegate:
   bool ConfigureIncomingConnection(
       mojo::ApplicationConnection* connection) override {
-    bool strict = HasStrictQueryParam(connection->GetConnectionURL());
+    bool strict = HasStrictQueryParam(connection->GetServiceProviderImpl()
+                                          .connection_context()
+                                          .connection_url);
     if (default_strict_ || strict) {
       connection->AddService(&strict_content_handler_factory_);
     } else {
diff --git a/services/python/content_handler/content_handler_main.cc b/services/python/content_handler/content_handler_main.cc
index f52e2f2..be6897d 100644
--- a/services/python/content_handler/content_handler_main.cc
+++ b/services/python/content_handler/content_handler_main.cc
@@ -213,7 +213,9 @@
  private:
   // Overridden from ApplicationDelegate:
   bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
-    if (IsDebug(connection->GetConnectionURL()))
+    if (IsDebug(connection->GetServiceProviderImpl()
+                    .connection_context()
+                    .connection_url))
       connection->AddService(&debug_content_handler_factory_);
     else
       connection->AddService(&content_handler_factory_);
diff --git a/services/ui/launcher/launcher_app.cc b/services/ui/launcher/launcher_app.cc
index 918681e..d0f1377 100644
--- a/services/ui/launcher/launcher_app.cc
+++ b/services/ui/launcher/launcher_app.cc
@@ -39,7 +39,9 @@
 bool LauncherApp::ConfigureIncomingConnection(
     mojo::ApplicationConnection* connection) {
   // Only present the launcher interface to the shell.
-  if (connection->GetRemoteApplicationURL().empty()) {
+  if (connection->GetServiceProviderImpl()
+          .connection_context()
+          .remote_url.empty()) {
     connection->AddService<Launcher>(this);
   }
   return true;
diff --git a/shell/application_manager/application_manager_unittest.cc b/shell/application_manager/application_manager_unittest.cc
index 7dec43d..8ea79c0 100644
--- a/shell/application_manager/application_manager_unittest.cc
+++ b/shell/application_manager/application_manager_unittest.cc
@@ -314,15 +314,16 @@
   }
 
   bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
-    if (!requestor_url_.empty() &&
-        requestor_url_ != connection->GetRemoteApplicationURL()) {
+    const std::string& remote_url =
+        connection->GetServiceProviderImpl().connection_context().remote_url;
+    if (!requestor_url_.empty() && requestor_url_ != remote_url) {
       context_->set_tester_called_quit();
       context_->QuitSoon();
       base::MessageLoop::current()->Quit();
       return false;
     }
     // If we're coming from A, then add B, otherwise A.
-    if (connection->GetRemoteApplicationURL() == kTestAURLString)
+    if (remote_url == kTestAURLString)
       connection->AddService<TestB>(this);
     else
       connection->AddService<TestA>(this);