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

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

Issue 1088533003: Adding URLResponse Disk Cache to mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_enumerator.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
9 #include "base/format_macros.h" 10 #include "base/format_macros.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
14 #include "mojo/common/common_type_converters.h" 15 #include "mojo/common/common_type_converters.h"
15 #include "mojo/common/data_pipe_utils.h" 16 #include "mojo/common/data_pipe_utils.h"
17 #include <sys/stat.h>
16 #include "url/url_util.h" 18 #include "url/url_util.h"
17 19
18 namespace shell { 20 namespace shell {
19 21
20 namespace { 22 namespace {
21 23
22 void IgnoreResult(bool result) { 24 void IgnoreResult(bool result) {
23 } 25 }
24 26
25 } // namespace 27 } // namespace
(...skipping 23 matching lines...) Expand all
49 GURL LocalFetcher::GetRedirectURL() const { 51 GURL LocalFetcher::GetRedirectURL() const {
50 return GURL::EmptyGURL(); 52 return GURL::EmptyGURL();
51 } 53 }
52 54
53 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, 55 mojo::URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
54 uint32_t skip) { 56 uint32_t skip) {
55 mojo::URLResponsePtr response(mojo::URLResponse::New()); 57 mojo::URLResponsePtr response(mojo::URLResponse::New());
56 response->url = mojo::String::From(url_); 58 response->url = mojo::String::From(url_);
57 mojo::DataPipe data_pipe; 59 mojo::DataPipe data_pipe;
58 response->body = data_pipe.consumer_handle.Pass(); 60 response->body = data_pipe.consumer_handle.Pass();
59 int64 file_size; 61 base::stat_wrapper_t stat_result;
60 if (base::GetFileSize(path_, &file_size)) { 62 if (stat64(path_.value().c_str(), &stat_result) == 0) {
61 response->headers = mojo::Array<mojo::String>(1); 63 response->headers = mojo::Array<mojo::String>(2);
62 response->headers[0] = 64 response->headers[0] =
63 base::StringPrintf("Content-Length: %" PRId64, file_size); 65 base::StringPrintf("Content-Length: %" PRId64, stat_result.st_size);
66 response->headers[1] = base::StringPrintf(
67 "ETag: \"%" PRId64 "-%" PRId64 "\"", stat_result.st_ino,
blundell 2015/05/07 11:29:22 Should this include st_dev as well for completenes
qsr 2015/05/07 12:49:02 mtime is already a little overkill, but I guess th
68 static_cast<uint64_t>(stat_result.st_mtime));
64 } 69 }
65 mojo::common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, 70 mojo::common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip,
66 task_runner, base::Bind(&IgnoreResult)); 71 task_runner, base::Bind(&IgnoreResult));
67 return response.Pass(); 72 return response.Pass();
68 } 73 }
69 74
70 void LocalFetcher::AsPath( 75 void LocalFetcher::AsPath(
71 base::TaskRunner* task_runner, 76 base::TaskRunner* task_runner,
72 base::Callback<void(const base::FilePath&, bool)> callback) { 77 base::Callback<void(const base::FilePath&, bool)> callback) {
73 // Async for consistency with network case. 78 // Async for consistency with network case.
(...skipping 15 matching lines...) Expand all
89 std::string start_of_file; 94 std::string start_of_file;
90 ReadFileToString(path_, &start_of_file, kMaxShebangLength); 95 ReadFileToString(path_, &start_of_file, kMaxShebangLength);
91 size_t return_position = start_of_file.find('\n'); 96 size_t return_position = start_of_file.find('\n');
92 if (return_position == std::string::npos) 97 if (return_position == std::string::npos)
93 return false; 98 return false;
94 *line = start_of_file.substr(0, return_position + 1); 99 *line = start_of_file.substr(0, return_position + 1);
95 return true; 100 return true;
96 } 101 }
97 102
98 } // namespace shell 103 } // namespace shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698