OLD | NEW |
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 "shell/application_manager/local_fetcher.h" | 5 #include "shell/application_manager/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" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
15 #include "mojo/common/data_pipe_utils.h" | 15 #include "mojo/common/data_pipe_utils.h" |
16 #include "url/url_util.h" | 16 #include "url/url_util.h" |
17 | 17 |
18 namespace mojo { | |
19 namespace shell { | 18 namespace shell { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 void IgnoreResult(bool result) { | 22 void IgnoreResult(bool result) { |
24 } | 23 } |
25 | 24 |
26 } // namespace | 25 } // namespace |
27 | 26 |
28 // A loader for local files. | 27 // A loader for local files. |
(...skipping 15 matching lines...) Expand all Loading... |
44 } | 43 } |
45 | 44 |
46 const GURL& LocalFetcher::GetURL() const { | 45 const GURL& LocalFetcher::GetURL() const { |
47 return url_; | 46 return url_; |
48 } | 47 } |
49 | 48 |
50 GURL LocalFetcher::GetRedirectURL() const { | 49 GURL LocalFetcher::GetRedirectURL() const { |
51 return GURL::EmptyGURL(); | 50 return GURL::EmptyGURL(); |
52 } | 51 } |
53 | 52 |
54 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, | 53 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, |
55 uint32_t skip) { | 54 uint32_t skip) { |
56 URLResponsePtr response(URLResponse::New()); | 55 mojo::URLResponsePtr response(mojo::URLResponse::New()); |
57 response->url = String::From(url_); | 56 response->url = mojo::String::From(url_); |
58 DataPipe data_pipe; | 57 mojo::DataPipe data_pipe; |
59 response->body = data_pipe.consumer_handle.Pass(); | 58 response->body = data_pipe.consumer_handle.Pass(); |
60 int64 file_size; | 59 int64 file_size; |
61 if (base::GetFileSize(path_, &file_size)) { | 60 if (base::GetFileSize(path_, &file_size)) { |
62 response->headers = Array<String>(1); | 61 response->headers = mojo::Array<mojo::String>(1); |
63 response->headers[0] = | 62 response->headers[0] = |
64 base::StringPrintf("Content-Length: %" PRId64, file_size); | 63 base::StringPrintf("Content-Length: %" PRId64, file_size); |
65 } | 64 } |
66 common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, | 65 mojo::common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, |
67 task_runner, base::Bind(&IgnoreResult)); | 66 task_runner, base::Bind(&IgnoreResult)); |
68 return response.Pass(); | 67 return response.Pass(); |
69 } | 68 } |
70 | 69 |
71 void LocalFetcher::AsPath( | 70 void LocalFetcher::AsPath( |
72 base::TaskRunner* task_runner, | 71 base::TaskRunner* task_runner, |
73 base::Callback<void(const base::FilePath&, bool)> callback) { | 72 base::Callback<void(const base::FilePath&, bool)> callback) { |
74 // Async for consistency with network case. | 73 // Async for consistency with network case. |
75 base::MessageLoop::current()->PostTask( | 74 base::MessageLoop::current()->PostTask( |
76 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); | 75 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); |
77 } | 76 } |
(...skipping 12 matching lines...) Expand all Loading... |
90 std::string start_of_file; | 89 std::string start_of_file; |
91 ReadFileToString(path_, &start_of_file, kMaxShebangLength); | 90 ReadFileToString(path_, &start_of_file, kMaxShebangLength); |
92 size_t return_position = start_of_file.find('\n'); | 91 size_t return_position = start_of_file.find('\n'); |
93 if (return_position == std::string::npos) | 92 if (return_position == std::string::npos) |
94 return false; | 93 return false; |
95 *line = start_of_file.substr(0, return_position + 1); | 94 *line = start_of_file.substr(0, return_position + 1); |
96 return true; | 95 return true; |
97 } | 96 } |
98 | 97 |
99 } // namespace shell | 98 } // namespace shell |
100 } // namespace mojo | |
OLD | NEW |