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 "mojo/fetcher/local_fetcher.h" | 5 #include "mojo/fetcher/local_fetcher.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
10 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
14 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
15 #include "mojo/common/common_type_converters.h" | 17 #include "mojo/common/common_type_converters.h" |
16 #include "mojo/common/data_pipe_utils.h" | 18 #include "mojo/common/data_pipe_utils.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 96 |
95 GURL LocalFetcher::GetRedirectReferer() const { | 97 GURL LocalFetcher::GetRedirectReferer() const { |
96 return GURL::EmptyGURL(); | 98 return GURL::EmptyGURL(); |
97 } | 99 } |
98 | 100 |
99 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, | 101 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, |
100 uint32_t skip) { | 102 uint32_t skip) { |
101 URLResponsePtr response(URLResponse::New()); | 103 URLResponsePtr response(URLResponse::New()); |
102 response->url = String::From(url_); | 104 response->url = String::From(url_); |
103 DataPipe data_pipe; | 105 DataPipe data_pipe; |
104 response->body = data_pipe.consumer_handle.Pass(); | 106 response->body = std::move(data_pipe.consumer_handle); |
105 int64 file_size; | 107 int64 file_size; |
106 if (base::GetFileSize(path_, &file_size)) { | 108 if (base::GetFileSize(path_, &file_size)) { |
107 response->headers = Array<HttpHeaderPtr>(1); | 109 response->headers = Array<HttpHeaderPtr>(1); |
108 HttpHeaderPtr header = HttpHeader::New(); | 110 HttpHeaderPtr header = HttpHeader::New(); |
109 header->name = "Content-Length"; | 111 header->name = "Content-Length"; |
110 header->value = base::StringPrintf("%" PRId64, file_size); | 112 header->value = base::StringPrintf("%" PRId64, file_size); |
111 response->headers[0] = header.Pass(); | 113 response->headers[0] = std::move(header); |
112 } | 114 } |
113 response->mime_type = String::From(MimeType()); | 115 response->mime_type = String::From(MimeType()); |
114 common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, | 116 common::CopyFromFile(path_, std::move(data_pipe.producer_handle), skip, |
115 task_runner, base::Bind(&IgnoreResult)); | 117 task_runner, base::Bind(&IgnoreResult)); |
116 return response.Pass(); | 118 return response; |
117 } | 119 } |
118 | 120 |
119 void LocalFetcher::AsPath( | 121 void LocalFetcher::AsPath( |
120 base::TaskRunner* task_runner, | 122 base::TaskRunner* task_runner, |
121 base::Callback<void(const base::FilePath&, bool)> callback) { | 123 base::Callback<void(const base::FilePath&, bool)> callback) { |
122 // Async for consistency with network case. | 124 // Async for consistency with network case. |
123 base::MessageLoop::current()->PostTask( | 125 base::MessageLoop::current()->PostTask( |
124 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); | 126 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); |
125 } | 127 } |
126 | 128 |
(...skipping 12 matching lines...) Expand all Loading... |
139 ReadFileToString(path_, &start_of_file, kMaxShebangLength); | 141 ReadFileToString(path_, &start_of_file, kMaxShebangLength); |
140 size_t return_position = start_of_file.find('\n'); | 142 size_t return_position = start_of_file.find('\n'); |
141 if (return_position == std::string::npos) | 143 if (return_position == std::string::npos) |
142 return false; | 144 return false; |
143 *line = start_of_file.substr(0, return_position + 1); | 145 *line = start_of_file.substr(0, return_position + 1); |
144 return true; | 146 return true; |
145 } | 147 } |
146 | 148 |
147 } // namespace fetcher | 149 } // namespace fetcher |
148 } // namespace mojo | 150 } // namespace mojo |
OLD | NEW |