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

Side by Side Diff: mojo/shell/mojo_url_resolver.cc

Issue 397733003: mojo: kill app_thread before unloading main app library and add tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: also service_manager_unittests Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/shell/mojo_url_resolver.h ('k') | mojo/shell/shell_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/shell/mojo_url_resolver.h" 5 #include "mojo/shell/mojo_url_resolver.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 20 matching lines...) Expand all
31 } // namespace 31 } // namespace
32 32
33 MojoURLResolver::MojoURLResolver() { 33 MojoURLResolver::MojoURLResolver() {
34 // Needed to treat first component of mojo URLs as host, not path. 34 // Needed to treat first component of mojo URLs as host, not path.
35 url::AddStandardScheme("mojo"); 35 url::AddStandardScheme("mojo");
36 } 36 }
37 37
38 MojoURLResolver::~MojoURLResolver() { 38 MojoURLResolver::~MojoURLResolver() {
39 } 39 }
40 40
41 void MojoURLResolver::SetBaseURL(const GURL& base_url) {
42 DCHECK(base_url.is_valid());
43 base_url_ = base_url;
44 // Force a trailing slash on the base_url to simplify resolving
45 // relative files and URLs below.
46 if (base_url.has_path() && *base_url.path().rbegin() != '/') {
47 std::string path(base_url.path() + '/');
48 GURL::Replacements replacements;
49 replacements.SetPathStr(path);
50 base_url_ = base_url_.ReplaceComponents(replacements);
51 }
52 }
53
41 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, 54 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
42 const GURL& resolved_url) { 55 const GURL& resolved_url) {
43 url_map_[mojo_url] = resolved_url; 56 url_map_[mojo_url] = resolved_url;
44 } 57 }
45 58
46 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { 59 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) {
47 local_file_set_.insert(mojo_url); 60 local_file_set_.insert(mojo_url);
48 } 61 }
49 62
50 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { 63 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
51 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); 64 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url);
52 if (it != url_map_.end()) 65 if (it != url_map_.end())
53 return it->second; 66 return it->second;
54 67
55 std::string lib = MakeSharedLibraryName(mojo_url.host()); 68 std::string lib = MakeSharedLibraryName(mojo_url.host());
56 69
57 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { 70 if (local_file_set_.find(mojo_url) != local_file_set_.end()) {
58 // Resolve to a local file URL. 71 // Resolve to a local file URL.
59 base::FilePath path; 72 base::FilePath path;
60 PathService::Get(base::DIR_MODULE, &path); 73 PathService::Get(base::DIR_MODULE, &path);
61 path = path.Append(base::FilePath::FromUTF8Unsafe(lib)); 74 path = path.Append(base::FilePath::FromUTF8Unsafe(lib));
62 return net::FilePathToFileURL(path); 75 return net::FilePathToFileURL(path);
63 } 76 }
64 77
65 // Otherwise, resolve to an URL relative to origin_. 78 // Otherwise, resolve to an URL relative to base_url_.
66 return GURL(origin_ + "/" + lib); 79 return base_url_.Resolve(lib);
67 } 80 }
68 81
69 } // namespace shell 82 } // namespace shell
70 } // namespace mojo 83 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/mojo_url_resolver.h ('k') | mojo/shell/shell_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698