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 <sys/stat.h> | 7 #include <sys/stat.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 GURL LocalFetcher::GetRedirectURL() const { | 52 GURL LocalFetcher::GetRedirectURL() const { |
53 return GURL::EmptyGURL(); | 53 return GURL::EmptyGURL(); |
54 } | 54 } |
55 | 55 |
56 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, | 56 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, |
57 uint32_t skip) { | 57 uint32_t skip) { |
58 mojo::URLResponsePtr response(mojo::URLResponse::New()); | 58 mojo::URLResponsePtr response(mojo::URLResponse::New()); |
59 response->url = mojo::String::From(url_); | 59 response->url = mojo::String::From(url_); |
60 mojo::DataPipe data_pipe; | 60 mojo::DataPipe data_pipe; |
61 response->body = data_pipe.consumer_handle.Pass(); | 61 response->body = data_pipe.consumer_handle.Pass(); |
62 #if defined(OS_MACOSX) | |
viettrungluu
2015/09/10 18:11:09
You should include build/build_config.h.
| |
63 struct stat stat_result; | |
64 if (stat(path_.value().c_str(), &stat_result) == 0) { | |
65 #else | |
62 base::stat_wrapper_t stat_result; | 66 base::stat_wrapper_t stat_result; |
viettrungluu
2015/09/10 18:11:09
Probably we should just use "struct stat64" here,
| |
63 if (stat64(path_.value().c_str(), &stat_result) == 0) { | 67 if (stat64(path_.value().c_str(), &stat_result) == 0) { |
68 #endif | |
64 auto content_length_header = mojo::HttpHeader::New(); | 69 auto content_length_header = mojo::HttpHeader::New(); |
65 content_length_header->name = "Content-Length"; | 70 content_length_header->name = "Content-Length"; |
66 content_length_header->value = | 71 content_length_header->value = |
67 base::StringPrintf("%" PRId64, stat_result.st_size); | 72 base::StringPrintf("%" PRId64, stat_result.st_size); |
68 response->headers.push_back(content_length_header.Pass()); | 73 response->headers.push_back(content_length_header.Pass()); |
69 auto etag_header = mojo::HttpHeader::New(); | 74 auto etag_header = mojo::HttpHeader::New(); |
70 etag_header->name = "ETag"; | 75 etag_header->name = "ETag"; |
71 etag_header->value = base::StringPrintf( | 76 etag_header->value = base::StringPrintf( |
72 "\"%" PRId64 "-%" PRId64 "-%" PRId64 "\"", stat_result.st_dev, | 77 "\"%" PRId64 "-%" PRId64 "-%" PRId64 "\"", |
73 stat_result.st_ino, static_cast<uint64_t>(stat_result.st_mtime)); | 78 static_cast<uint64_t>(stat_result.st_dev), stat_result.st_ino, |
79 static_cast<uint64_t>(stat_result.st_mtime)); | |
74 response->headers.push_back(etag_header.Pass()); | 80 response->headers.push_back(etag_header.Pass()); |
75 } | 81 } |
76 mojo::common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, | 82 mojo::common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, |
77 task_runner, base::Bind(&IgnoreResult)); | 83 task_runner, base::Bind(&IgnoreResult)); |
78 return response.Pass(); | 84 return response.Pass(); |
79 } | 85 } |
80 | 86 |
81 void LocalFetcher::AsPath( | 87 void LocalFetcher::AsPath( |
82 base::TaskRunner* task_runner, | 88 base::TaskRunner* task_runner, |
83 base::Callback<void(const base::FilePath&, bool)> callback) { | 89 base::Callback<void(const base::FilePath&, bool)> callback) { |
(...skipping 16 matching lines...) Expand all Loading... | |
100 std::string start_of_file; | 106 std::string start_of_file; |
101 ReadFileToString(path_, &start_of_file, kMaxShebangLength); | 107 ReadFileToString(path_, &start_of_file, kMaxShebangLength); |
102 size_t return_position = start_of_file.find('\n'); | 108 size_t return_position = start_of_file.find('\n'); |
103 if (return_position == std::string::npos) | 109 if (return_position == std::string::npos) |
104 return false; | 110 return false; |
105 *line = start_of_file.substr(0, return_position + 1); | 111 *line = start_of_file.substr(0, return_position + 1); |
106 return true; | 112 return true; |
107 } | 113 } |
108 | 114 |
109 } // namespace shell | 115 } // namespace shell |
OLD | NEW |