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

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

Issue 1109993002: Adds support for mojo apps to live in their own directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge to trunk and move filename_util to own dir Created 5 years, 7 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
« no previous file with comments | « mojo/shell/local_fetcher.h ('k') | mojo/util/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/local_fetcher.h" 5 #include "mojo/shell/local_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
14 #include "mojo/common/common_type_converters.h" 13 #include "mojo/common/common_type_converters.h"
15 #include "mojo/common/data_pipe_utils.h" 14 #include "mojo/common/data_pipe_utils.h"
16 #include "mojo/common/url_type_converters.h" 15 #include "mojo/common/url_type_converters.h"
16 #include "mojo/util/filename_util.h"
17 #include "url/url_util.h" 17 #include "url/url_util.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace shell { 20 namespace shell {
21 21
22 namespace { 22 namespace {
23 23
24 void IgnoreResult(bool result) { 24 void IgnoreResult(bool result) {
25 } 25 }
26 26
27 } // namespace 27 } // namespace
28 28
29 // A loader for local files. 29 // A loader for local files.
30 LocalFetcher::LocalFetcher(const GURL& url, 30 LocalFetcher::LocalFetcher(const GURL& url,
31 const GURL& url_without_query, 31 const GURL& url_without_query,
32 const FetchCallback& loader_callback) 32 const FetchCallback& loader_callback)
33 : Fetcher(loader_callback), url_(url), path_(UrlToFile(url_without_query)) { 33 : Fetcher(loader_callback),
34 url_(url),
35 path_(util::UrlToFilePath(url_without_query)) {
34 TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec()); 36 TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec());
35 loader_callback_.Run(make_scoped_ptr(this)); 37 loader_callback_.Run(make_scoped_ptr(this));
36 } 38 }
37 39
38 base::FilePath LocalFetcher::UrlToFile(const GURL& url) {
39 DCHECK(url.SchemeIsFile());
40 url::RawCanonOutputW<1024> output;
41 url::DecodeURLEscapeSequences(url.path().data(),
42 static_cast<int>(url.path().length()), &output);
43 base::string16 decoded_path = base::string16(output.data(), output.length());
44 #if defined(OS_WIN)
45 base::TrimString(decoded_path, L"/", &decoded_path);
46 base::FilePath path(decoded_path);
47 #else
48 base::FilePath path(base::UTF16ToUTF8(decoded_path));
49 #endif
50 return path;
51 }
52
53 const GURL& LocalFetcher::GetURL() const { 40 const GURL& LocalFetcher::GetURL() const {
54 return url_; 41 return url_;
55 } 42 }
56 43
57 GURL LocalFetcher::GetRedirectURL() const { 44 GURL LocalFetcher::GetRedirectURL() const {
58 return GURL::EmptyGURL(); 45 return GURL::EmptyGURL();
59 } 46 }
60 47
61 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, 48 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
62 uint32_t skip) { 49 uint32_t skip) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ReadFileToString(path_, &start_of_file, kMaxShebangLength); 85 ReadFileToString(path_, &start_of_file, kMaxShebangLength);
99 size_t return_position = start_of_file.find('\n'); 86 size_t return_position = start_of_file.find('\n');
100 if (return_position == std::string::npos) 87 if (return_position == std::string::npos)
101 return false; 88 return false;
102 *line = start_of_file.substr(0, return_position + 1); 89 *line = start_of_file.substr(0, return_position + 1);
103 return true; 90 return true;
104 } 91 }
105 92
106 } // namespace shell 93 } // namespace shell
107 } // namespace mojo 94 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/local_fetcher.h ('k') | mojo/util/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698