Rename MojoURLResolver to URLResolver

BUG=
R=aa@chromium.org

Review URL: https://codereview.chromium.org/868283006
diff --git a/services/window_manager/window_manager_api_unittest.cc b/services/window_manager/window_manager_api_unittest.cc
index 544286b..a8f8d6a 100644
--- a/services/window_manager/window_manager_api_unittest.cc
+++ b/services/window_manager/window_manager_api_unittest.cc
@@ -178,8 +178,8 @@
   void SetUp() override {
     test_helper_.reset(new mojo::shell::ShellTestHelper);
     test_helper_->Init();
-    test_helper_->AddCustomMapping(GURL("mojo:window_manager"),
-                                   GURL("mojo:core_window_manager"));
+    test_helper_->AddURLMapping(GURL("mojo:window_manager"),
+                                GURL("mojo:core_window_manager"));
     test_helper_->SetLoaderForURL(
         scoped_ptr<mojo::ApplicationLoader>(
             new TestApplicationLoader(base::Bind(
diff --git a/shell/BUILD.gn b/shell/BUILD.gn
index 3f4838a..0637989 100644
--- a/shell/BUILD.gn
+++ b/shell/BUILD.gn
@@ -158,10 +158,10 @@
     "filename_util.h",
     "incoming_connection_listener.cc",
     "incoming_connection_listener.h",
-    "mojo_url_resolver.cc",
-    "mojo_url_resolver.h",
     "out_of_process_dynamic_service_runner.cc",
     "out_of_process_dynamic_service_runner.h",
+    "url_resolver.cc",
+    "url_resolver.h",
     "switches.cc",
     "switches.h",
     "task_runners.cc",
@@ -406,12 +406,12 @@
     "data_pipe_peek_unittest.cc",
     "dynamic_application_loader_unittest.cc",
     "in_process_dynamic_service_runner_unittest.cc",
-    "mojo_url_resolver_unittest.cc",
     "shell_test_base.cc",
     "shell_test_base_android.cc",
     "shell_test_base.h",
     "shell_test_base_unittest.cc",
     "shell_test_main.cc",
+    "url_resolver_unittest.cc",
   ]
 
   deps = [
diff --git a/shell/android/mojo_main.cc b/shell/android/mojo_main.cc
index 86ae823..9a894be 100644
--- a/shell/android/mojo_main.cc
+++ b/shell/android/mojo_main.cc
@@ -85,7 +85,7 @@
       GURL("mojo:android_handler"));
 
   // By default, the keyboard is handled by the native_viewport_service.
-  context->mojo_url_resolver()->AddCustomMapping(
+  context->url_resolver()->AddURLMapping(
       GURL("mojo:keyboard"), GURL("mojo:native_viewport_service"));
 }
 
diff --git a/shell/context.cc b/shell/context.cc
index 21caefa..c7e3d02 100644
--- a/shell/context.cc
+++ b/shell/context.cc
@@ -105,7 +105,7 @@
 
 bool ConfigureURLMappings(base::CommandLine* command_line,
                           Context* context) {
-  MojoURLResolver* resolver = context->mojo_url_resolver();
+  URLResolver* resolver = context->url_resolver();
 
   // Configure the resolution of unknown mojo: URLs.
   GURL base_url;
@@ -118,12 +118,12 @@
   if (!base_url.is_valid())
     return false;
 
-  resolver->SetBaseURL(base_url);
+  resolver->SetMojoBaseURL(base_url);
 
   // The network service must be loaded from the filesystem.
   // This mapping is done before the command line URL mapping are processed, so
   // that it can be overridden.
-  resolver->AddCustomMapping(
+  resolver->AddURLMapping(
       GURL("mojo:network_service"),
       context->ResolveShellFileURL("file:network_service.mojo"));
 
@@ -141,7 +141,7 @@
       const GURL to = context->ResolveCommandLineURL(pair.second);
       if (!from.is_valid() || !to.is_valid())
         return false;
-      resolver->AddCustomMapping(from, to);
+      resolver->AddURLMapping(from, to);
     }
   }
   return true;
@@ -271,11 +271,11 @@
 }
 
 GURL Context::ResolveURL(const GURL& url) {
-  return mojo_url_resolver_.Resolve(url);
+  return url_resolver_.ResolveMojoURL(url);
 }
 
 GURL Context::ResolveMappings(const GURL& url) {
-  return mojo_url_resolver_.ApplyCustomMappings(url);
+  return url_resolver_.ApplyURLMappings(url);
 }
 
 void Context::Run(const GURL& url) {
diff --git a/shell/context.h b/shell/context.h
index d672e1a..0b7d295 100644
--- a/shell/context.h
+++ b/shell/context.h
@@ -9,8 +9,8 @@
 
 #include "base/macros.h"
 #include "shell/application_manager/application_manager.h"
-#include "shell/mojo_url_resolver.h"
 #include "shell/task_runners.h"
+#include "shell/url_resolver.h"
 
 namespace mojo {
 
@@ -53,7 +53,7 @@
 
   TaskRunners* task_runners() { return task_runners_.get(); }
   ApplicationManager* application_manager() { return &application_manager_; }
-  MojoURLResolver* mojo_url_resolver() { return &mojo_url_resolver_; }
+  URLResolver* url_resolver() { return &url_resolver_; }
 
  private:
   class NativeViewportApplicationLoader;
@@ -67,7 +67,7 @@
   scoped_ptr<TaskRunners> task_runners_;
   scoped_ptr<ExternalApplicationListener> listener_;
   ApplicationManager application_manager_;
-  MojoURLResolver mojo_url_resolver_;
+  URLResolver url_resolver_;
   GURL shell_file_root_;
   GURL command_line_cwd_;
 
diff --git a/shell/mojo_url_resolver.cc b/shell/mojo_url_resolver.cc
deleted file mode 100644
index 9e93aa1..0000000
--- a/shell/mojo_url_resolver.cc
+++ /dev/null
@@ -1,61 +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 "shell/mojo_url_resolver.h"
-
-#include "base/base_paths.h"
-#include "base/files/file_path.h"
-#include "base/logging.h"
-#include "shell/filename_util.h"
-#include "url/url_util.h"
-
-namespace mojo {
-namespace shell {
-
-MojoURLResolver::MojoURLResolver() {
-  // Needed to treat first component of mojo URLs as host, not path.
-  url::AddStandardScheme("mojo");
-}
-
-MojoURLResolver::~MojoURLResolver() {
-}
-
-void MojoURLResolver::SetBaseURL(const GURL& base_url) {
-  DCHECK(base_url.is_valid());
-  // Force a trailing slash on the base_url to simplify resolving
-  // relative files and URLs below.
-  base_url_ = AddTrailingSlashIfNeeded(base_url);
-}
-
-void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
-                                       const GURL& resolved_url) {
-  url_map_[mojo_url] = resolved_url;
-}
-
-GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
-  const GURL mapped_url(ApplyCustomMappings(mojo_url));
-
-  if (mapped_url.scheme() != "mojo") {
-    // The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
-    return mapped_url;
-  } else {
-    // It's still a mojo: URL, use the default mapping scheme.
-    std::string lib = mapped_url.host() + ".mojo";
-    return base_url_.Resolve(lib);
-  }
-}
-
-GURL MojoURLResolver::ApplyCustomMappings(const GURL& url) const {
-  GURL mapped_url(url);
-  for (;;) {
-    std::map<GURL, GURL>::const_iterator it = url_map_.find(mapped_url);
-    if (it == url_map_.end())
-      break;
-    mapped_url = it->second;
-  }
-  return mapped_url;
-}
-
-}  // namespace shell
-}  // namespace mojo
diff --git a/shell/mojo_url_resolver.h b/shell/mojo_url_resolver.h
deleted file mode 100644
index c1db8f7..0000000
--- a/shell/mojo_url_resolver.h
+++ /dev/null
@@ -1,55 +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.
-
-#ifndef SHELL_MOJO_URL_RESOLVER_H_
-#define SHELL_MOJO_URL_RESOLVER_H_
-
-#include <map>
-#include <set>
-
-#include "base/basictypes.h"
-#include "base/files/file_path.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace shell {
-
-// This class resolves "mojo:" URLs to physical URLs (e.g., "file:" and
-// "https:" URLs). By default, "mojo:" URLs resolve to a file location, but
-// that resolution can be customized via the AddCustomMapping method.
-class MojoURLResolver {
- public:
-  MojoURLResolver();
-  ~MojoURLResolver();
-
-  // If specified, then unknown "mojo:" URLs will be resolved relative to this
-  // base URL. That is, the portion after the colon will be appeneded to
-  // |base_url| with platform-specific shared library prefix and suffix
-  // inserted.
-  void SetBaseURL(const GURL& base_url);
-
-  // Add a custom mapping for a particular "mojo:" URL. If |resolved_url| is
-  // itself a mojo url normal resolution rules apply.
-  void AddCustomMapping(const GURL& mojo_url, const GURL& resolved_url);
-
-  // Resolve the given "mojo:" URL to the URL that should be used to fetch the
-  // code for the corresponding Mojo App.
-  GURL Resolve(const GURL& mojo_url) const;
-
-  // Applies all custom mappings for |url|, returning the last non-mapped url.
-  // For example, if 'a' maps to 'b' and 'b' maps to 'c' calling this with 'a'
-  // returns 'c'.
-  GURL ApplyCustomMappings(const GURL& url) const;
-
- private:
-  std::map<GURL, GURL> url_map_;
-  GURL base_url_;
-
-  DISALLOW_COPY_AND_ASSIGN(MojoURLResolver);
-};
-
-}  // namespace shell
-}  // namespace mojo
-
-#endif  // SHELL_MOJO_URL_RESOLVER_H_
diff --git a/shell/shell_test_base.cc b/shell/shell_test_base.cc
index b0c74e0..6e4f18c 100644
--- a/shell/shell_test_base.cc
+++ b/shell/shell_test_base.cc
@@ -37,14 +37,13 @@
 
 #if !defined(OS_ANDROID)
 void ShellTestBase::SetUpTestApplications() {
-  // Set the MojoURLResolver origin to be the same as the base file path for
+  // Set the URLResolver origin to be the same as the base file path for
   // local files. This is primarily for test convenience, so that references
   // to unknown mojo: urls that do not have specific local file or custom
   // mappings registered on the URL resolver are treated as shared libraries.
   base::FilePath service_dir;
   CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
-  shell_context_.mojo_url_resolver()->SetBaseURL(
-      FilePathToFileURL(service_dir));
+  shell_context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir));
 }
 #endif
 
diff --git a/shell/shell_test_base_android.cc b/shell/shell_test_base_android.cc
index 4f4a6c7..493ccbf 100644
--- a/shell/shell_test_base_android.cc
+++ b/shell/shell_test_base_android.cc
@@ -37,7 +37,7 @@
   base::android::ScopedJavaLocalRef<jstring> service_dir(
       Java_ShellTestBase_extractMojoApplications(
           env, base::android::GetApplicationContext()));
-  shell_context_.mojo_url_resolver()->SetBaseURL(
+  shell_context_.url_resolver()->SetMojoBaseURL(
       FilePathToFileURL(base::FilePath(
           base::android::ConvertJavaStringToUTF8(env, service_dir.obj()))));
 }
diff --git a/shell/shell_test_helper.cc b/shell/shell_test_helper.cc
index dc1364d..b411849 100644
--- a/shell/shell_test_helper.cc
+++ b/shell/shell_test_helper.cc
@@ -11,7 +11,7 @@
 #include "base/path_service.h"
 #include "shell/filename_util.h"
 #include "shell/init.h"
-#include "shell/mojo_url_resolver.h"
+#include "shell/url_resolver.h"
 
 namespace mojo {
 namespace shell {
@@ -30,7 +30,7 @@
       new ApplicationManager::TestAPI(context_.application_manager()));
   base::FilePath service_dir;
   CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
-  context_.mojo_url_resolver()->SetBaseURL(FilePathToFileURL(service_dir));
+  context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir));
 }
 
 void ShellTestHelper::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
@@ -38,9 +38,8 @@
   context_.application_manager()->SetLoaderForURL(loader.Pass(), url);
 }
 
-void ShellTestHelper::AddCustomMapping(const GURL& mojo_url,
-                                       const GURL& resolved_url) {
-  context_.mojo_url_resolver()->AddCustomMapping(mojo_url, resolved_url);
+void ShellTestHelper::AddURLMapping(const GURL& url, const GURL& resolved_url) {
+  context_.url_resolver()->AddURLMapping(url, resolved_url);
 }
 
 }  // namespace shell
diff --git a/shell/shell_test_helper.h b/shell/shell_test_helper.h
index 4a29818..92455ec 100644
--- a/shell/shell_test_helper.h
+++ b/shell/shell_test_helper.h
@@ -36,9 +36,9 @@
   // the thread this class spawns.
   void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
 
-  // Adds a mapping that is used when resolving mojo urls. See MojoURLResolver
+  // Adds a mapping that is used when resolving mojo urls. See URLResolver
   // for details.
-  void AddCustomMapping(const GURL& mojo_url, const GURL& resolved_url);
+  void AddURLMapping(const GURL& url, const GURL& resolved_url);
 
  private:
   Context context_;
diff --git a/shell/switches.cc b/shell/switches.cc
index e89e768..930517c 100644
--- a/shell/switches.cc
+++ b/shell/switches.cc
@@ -46,7 +46,7 @@
 const char kHelp[] = "help";
 
 // Map mojo: URLs to a shared library of similar name at this origin. See
-// mojo_url_resolver.cc for details.
+// url_resolver.cc for details.
 const char kOrigin[] = "origin";
 
 // Specifies a set of mappings to apply when resolving urls. The value is set of
diff --git a/shell/url_resolver.cc b/shell/url_resolver.cc
new file mode 100644
index 0000000..e1ceb99
--- /dev/null
+++ b/shell/url_resolver.cc
@@ -0,0 +1,58 @@
+// 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 "shell/url_resolver.h"
+
+#include "base/base_paths.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "shell/filename_util.h"
+#include "url/url_util.h"
+
+namespace mojo {
+namespace shell {
+
+URLResolver::URLResolver() {
+  // Needed to treat first component of mojo URLs as host, not path.
+  url::AddStandardScheme("mojo");
+}
+
+URLResolver::~URLResolver() {
+}
+
+void URLResolver::AddURLMapping(const GURL& url, const GURL& resolved_url) {
+  url_map_[url] = resolved_url;
+}
+
+GURL URLResolver::ApplyURLMappings(const GURL& url) const {
+  GURL mapped_url(url);
+  for (;;) {
+    const auto& it = url_map_.find(mapped_url);
+    if (it == url_map_.end())
+      break;
+    mapped_url = it->second;
+  }
+  return mapped_url;
+}
+
+void URLResolver::SetMojoBaseURL(const GURL& mojo_base_url) {
+  DCHECK(mojo_base_url.is_valid());
+  // Force a trailing slash on the base_url to simplify resolving
+  // relative files and URLs below.
+  mojo_base_url_ = AddTrailingSlashIfNeeded(mojo_base_url);
+}
+
+GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const {
+  if (mojo_url.scheme() != "mojo") {
+    // The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
+    return mojo_url;
+  } else {
+    // It's still a mojo: URL, use the default mapping scheme.
+    std::string lib = mojo_url.host() + ".mojo";
+    return mojo_base_url_.Resolve(lib);
+  }
+}
+
+}  // namespace shell
+}  // namespace mojo
diff --git a/shell/url_resolver.h b/shell/url_resolver.h
new file mode 100644
index 0000000..4cb02be
--- /dev/null
+++ b/shell/url_resolver.h
@@ -0,0 +1,56 @@
+// 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.
+
+#ifndef SHELL_URL_RESOLVER_H_
+#define SHELL_URL_RESOLVER_H_
+
+#include <map>
+#include <set>
+
+#include "base/basictypes.h"
+#include "base/files/file_path.h"
+#include "url/gurl.h"
+
+namespace mojo {
+namespace shell {
+
+// This class supports the mapping of URLs to other URLs.
+// It's commonly used with mojo: URL, to provide a physical location (i.e.
+// file: or https:) but works with any URL.
+// By default, "mojo:" URLs resolve to a file location, with ".mojo" appended,
+// but that resolution can be customized via the AddCustomMapping method.
+class URLResolver {
+ public:
+  URLResolver();
+  ~URLResolver();
+
+  // Add a custom mapping for a particular URL. If |resolved_url| is
+  // itself a mojo url normal resolution rules apply.
+  void AddURLMapping(const GURL& url, const GURL& resolved_url);
+
+  // Applies all custom mappings for |url|, returning the last non-mapped url.
+  // For example, if 'a' maps to 'b' and 'b' maps to 'c' calling this with 'a'
+  // returns 'c'.
+  GURL ApplyURLMappings(const GURL& url) const;
+
+  // If specified, then "mojo:" URLs will be resolved relative to this
+  // URL. That is, the portion after the colon will be appeneded to
+  // |mojo_base_url| with .mojo appended.
+  void SetMojoBaseURL(const GURL& mojo_base_url);
+
+  // Resolve the given "mojo:" URL to the URL that should be used to fetch the
+  // code for the corresponding Mojo App.
+  GURL ResolveMojoURL(const GURL& mojo_url) const;
+
+ private:
+  std::map<GURL, GURL> url_map_;
+  GURL mojo_base_url_;
+
+  DISALLOW_COPY_AND_ASSIGN(URLResolver);
+};
+
+}  // namespace shell
+}  // namespace mojo
+
+#endif  // SHELL_URL_RESOLVER_H_
diff --git a/shell/mojo_url_resolver_unittest.cc b/shell/url_resolver_unittest.cc
similarity index 63%
rename from shell/mojo_url_resolver_unittest.cc
rename to shell/url_resolver_unittest.cc
index 77d97db..1f9df8b 100644
--- a/shell/mojo_url_resolver_unittest.cc
+++ b/shell/url_resolver_unittest.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "shell/mojo_url_resolver.h"
+#include "shell/url_resolver.h"
 
 #include "base/logging.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -12,14 +12,15 @@
 namespace test {
 namespace {
 
-typedef testing::Test MojoURLResolverTest;
+typedef testing::Test URLResolverTest;
 
-TEST_F(MojoURLResolverTest, MojoURLsFallThrough) {
-  MojoURLResolver resolver;
-  resolver.AddCustomMapping(GURL("mojo:test"), GURL("mojo:foo"));
+TEST_F(URLResolverTest, MojoURLsFallThrough) {
+  URLResolver resolver;
+  resolver.AddURLMapping(GURL("mojo:test"), GURL("mojo:foo"));
   const GURL base_url("file:/base");
-  resolver.SetBaseURL(base_url);
-  std::string resolved(resolver.Resolve(GURL("mojo:test")).spec());
+  resolver.SetMojoBaseURL(base_url);
+  GURL mapped_url = resolver.ApplyURLMappings(GURL("mojo:test"));
+  std::string resolved(resolver.ResolveMojoURL(mapped_url).spec());
   // Resolved must start with |base_url|.
   EXPECT_EQ(base_url.spec(), resolved.substr(0, base_url.spec().size()));
   // And must contain foo.