Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(952)

Unified Diff: mojo/shell/mojo_url_resolver.cc

Issue 323593002: Mojo: Use network service to load non-local Mojo Apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/mojo_url_resolver.h ('k') | mojo/shell/network_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/mojo_url_resolver.cc
diff --git a/mojo/shell/mojo_url_resolver.cc b/mojo/shell/mojo_url_resolver.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63a8b570330b1650bd4dd4bc9f94abf78b3fcd32
--- /dev/null
+++ b/mojo/shell/mojo_url_resolver.cc
@@ -0,0 +1,70 @@
+// 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/shell/mojo_url_resolver.h"
+
+#include "base/base_paths.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "net/base/filename_util.h"
+
+namespace mojo {
+namespace shell {
+namespace {
+
+std::string MakeSharedLibraryName(const std::string& file_name) {
+#if defined(OS_WIN)
+ return file_name + ".dll";
+#elif defined(OS_LINUX)
+ return "lib" + file_name + ".so";
+#elif defined(OS_MACOSX)
+ return "lib" + file_name + ".dylib";
+#else
+ NOTREACHED() << "dynamic loading of services not supported";
+ return std::string();
+#endif
+}
+
+} // namespace
+
+MojoURLResolver::MojoURLResolver() {
+}
+
+MojoURLResolver::~MojoURLResolver() {
+}
+
+void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
+ const GURL& resolved_url) {
+ url_map_[mojo_url] = resolved_url;
+}
+
+void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) {
+ local_file_set_.insert(mojo_url);
+}
+
+GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
+ std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url);
+ if (it != url_map_.end())
+ return it->second;
+
+ std::string lib = MakeSharedLibraryName(mojo_url.ExtractFileName());
+
+ if (local_file_set_.find(mojo_url) != local_file_set_.end()) {
+ // Resolve to a local file URL.
+ base::FilePath path;
+ PathService::Get(base::DIR_EXE, &path);
+#if !defined(OS_WIN)
+ path = path.Append(FILE_PATH_LITERAL("lib"));
+#endif
+ path = path.Append(base::FilePath::FromUTF8Unsafe(lib));
+ return net::FilePathToFileURL(path);
+ }
+
+ // Otherwise, resolve to an URL relative to origin_.
+ return GURL(origin_ + "/" + lib);
+}
+
+} // namespace shell
+} // namespace mojo
« no previous file with comments | « mojo/shell/mojo_url_resolver.h ('k') | mojo/shell/network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698