| 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/update_fetcher.h" | 5 #include "mojo/fetcher/update_fetcher.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 9 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 12 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
| 13 #include "mojo/common/data_pipe_utils.h" | 15 #include "mojo/common/data_pipe_utils.h" |
| 14 #include "mojo/common/url_type_converters.h" | 16 #include "mojo/common/url_type_converters.h" |
| 15 | 17 |
| 16 namespace mojo { | 18 namespace mojo { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 43 } | 45 } |
| 44 | 46 |
| 45 GURL UpdateFetcher::GetRedirectReferer() const { | 47 GURL UpdateFetcher::GetRedirectReferer() const { |
| 46 return GURL::EmptyGURL(); | 48 return GURL::EmptyGURL(); |
| 47 } | 49 } |
| 48 URLResponsePtr UpdateFetcher::AsURLResponse(base::TaskRunner* task_runner, | 50 URLResponsePtr UpdateFetcher::AsURLResponse(base::TaskRunner* task_runner, |
| 49 uint32_t skip) { | 51 uint32_t skip) { |
| 50 URLResponsePtr response(URLResponse::New()); | 52 URLResponsePtr response(URLResponse::New()); |
| 51 response->url = String::From(url_); | 53 response->url = String::From(url_); |
| 52 DataPipe data_pipe; | 54 DataPipe data_pipe; |
| 53 response->body = data_pipe.consumer_handle.Pass(); | 55 response->body = std::move(data_pipe.consumer_handle); |
| 54 int64 file_size; | 56 int64 file_size; |
| 55 if (base::GetFileSize(path_, &file_size)) { | 57 if (base::GetFileSize(path_, &file_size)) { |
| 56 response->headers = Array<HttpHeaderPtr>(1); | 58 response->headers = Array<HttpHeaderPtr>(1); |
| 57 HttpHeaderPtr header = HttpHeader::New(); | 59 HttpHeaderPtr header = HttpHeader::New(); |
| 58 header->name = "Content-Length"; | 60 header->name = "Content-Length"; |
| 59 header->value = base::StringPrintf("%" PRId64, file_size); | 61 header->value = base::StringPrintf("%" PRId64, file_size); |
| 60 response->headers[0] = header.Pass(); | 62 response->headers[0] = std::move(header); |
| 61 } | 63 } |
| 62 common::CopyFromFile(path_, data_pipe.producer_handle.Pass(), skip, | 64 common::CopyFromFile(path_, std::move(data_pipe.producer_handle), skip, |
| 63 task_runner, base::Bind(&IgnoreResult)); | 65 task_runner, base::Bind(&IgnoreResult)); |
| 64 return response.Pass(); | 66 return response; |
| 65 } | 67 } |
| 66 | 68 |
| 67 void UpdateFetcher::AsPath( | 69 void UpdateFetcher::AsPath( |
| 68 base::TaskRunner* task_runner, | 70 base::TaskRunner* task_runner, |
| 69 base::Callback<void(const base::FilePath&, bool)> callback) { | 71 base::Callback<void(const base::FilePath&, bool)> callback) { |
| 70 base::MessageLoop::current()->PostTask( | 72 base::MessageLoop::current()->PostTask( |
| 71 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); | 73 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); |
| 72 } | 74 } |
| 73 | 75 |
| 74 std::string UpdateFetcher::MimeType() { | 76 std::string UpdateFetcher::MimeType() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 return true; | 93 return true; |
| 92 } | 94 } |
| 93 | 95 |
| 94 void UpdateFetcher::OnGetAppPath(const mojo::String& path) { | 96 void UpdateFetcher::OnGetAppPath(const mojo::String& path) { |
| 95 path_ = base::FilePath::FromUTF8Unsafe(path); | 97 path_ = base::FilePath::FromUTF8Unsafe(path); |
| 96 loader_callback_.Run(make_scoped_ptr(this)); | 98 loader_callback_.Run(make_scoped_ptr(this)); |
| 97 } | 99 } |
| 98 | 100 |
| 99 } // namespace fetcher | 101 } // namespace fetcher |
| 100 } // namespace mojo | 102 } // namespace mojo |
| OLD | NEW |