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

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

Issue 1327033004: Allow building mojo_shell and non-graphical apps/services on a Mac (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review feedback Created 5 years, 3 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 | « shell/BUILD.gn ('k') | shell/application_manager/network_fetcher.cc » ('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 "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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "build/build_config.h"
17 #include "mojo/converters/url/url_type_converters.h" 18 #include "mojo/converters/url/url_type_converters.h"
18 #include "mojo/data_pipe_utils/data_pipe_utils.h" 19 #include "mojo/data_pipe_utils/data_pipe_utils.h"
19 #include "url/url_util.h" 20 #include "url/url_util.h"
20 21
21 namespace shell { 22 namespace shell {
22 23
23 namespace { 24 namespace {
24 25
25 void IgnoreResult(bool result) { 26 void IgnoreResult(bool result) {
26 } 27 }
(...skipping 26 matching lines...) Expand all
53 return GURL::EmptyGURL(); 54 return GURL::EmptyGURL();
54 } 55 }
55 56
56 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, 57 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
57 uint32_t skip) { 58 uint32_t skip) {
58 mojo::URLResponsePtr response(mojo::URLResponse::New()); 59 mojo::URLResponsePtr response(mojo::URLResponse::New());
59 response->url = mojo::String::From(url_); 60 response->url = mojo::String::From(url_);
60 mojo::DataPipe data_pipe; 61 mojo::DataPipe data_pipe;
61 response->body = data_pipe.consumer_handle.Pass(); 62 response->body = data_pipe.consumer_handle.Pass();
62 base::stat_wrapper_t stat_result; 63 base::stat_wrapper_t stat_result;
64 #if defined(OS_MACOSX)
65 if (stat(path_.value().c_str(), &stat_result) == 0) {
66 #else
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
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
OLDNEW
« no previous file with comments | « shell/BUILD.gn ('k') | shell/application_manager/network_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698