Commit df9fd16b authored by Bence Béky's avatar Bence Béky Committed by Commit Bot

Use CompletionOnceCallback in URLRequestSimpleJob.

Bug: 807724
Change-Id: I510e6b677606c30265956a1f290ae0b1ef9b0214
Reviewed-on: https://chromium-review.googlesource.com/1155089Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579377}
parent 1fe30363
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "extensions/common/file_util.h" #include "extensions/common/file_util.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/file_data_pipe_producer.h" #include "mojo/public/cpp/system/file_data_pipe_producer.h"
#include "net/base/completion_once_callback.h"
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
...@@ -70,11 +71,10 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { ...@@ -70,11 +71,10 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob {
} }
// Overridden from URLRequestSimpleJob: // Overridden from URLRequestSimpleJob:
int GetRefCountedData( int GetRefCountedData(std::string* mime_type,
std::string* mime_type, std::string* charset,
std::string* charset, scoped_refptr<base::RefCountedMemory>* data,
scoped_refptr<base::RefCountedMemory>* data, net::CompletionOnceCallback callback) const override {
const net::CompletionCallback& callback) const override {
const ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); const ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
*data = rb.LoadDataResourceBytes(resource_id_); *data = rb.LoadDataResourceBytes(resource_id_);
...@@ -86,11 +86,11 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { ...@@ -86,11 +86,11 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob {
std::string* read_mime_type = new std::string; std::string* read_mime_type = new std::string;
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock()}, FROM_HERE, {base::MayBlock()},
base::Bind(&net::GetMimeTypeFromFile, filename_, base::BindOnce(&net::GetMimeTypeFromFile, filename_,
base::Unretained(read_mime_type)), base::Unretained(read_mime_type)),
base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead, base::BindOnce(&URLRequestResourceBundleJob::OnMimeTypeRead,
weak_factory_.GetWeakPtr(), mime_type, charset, *data, weak_factory_.GetWeakPtr(), mime_type, charset, *data,
base::Owned(read_mime_type), callback)); base::Owned(read_mime_type), std::move(callback)));
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
} }
...@@ -106,7 +106,7 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { ...@@ -106,7 +106,7 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob {
std::string* charset, std::string* charset,
scoped_refptr<base::RefCountedMemory> data, scoped_refptr<base::RefCountedMemory> data,
std::string* read_mime_type, std::string* read_mime_type,
const net::CompletionCallback& callback, net::CompletionOnceCallback callback,
bool read_result) { bool read_result) {
response_info_.headers->AddHeader( response_info_.headers->AddHeader(
base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentType, base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentType,
...@@ -114,7 +114,7 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { ...@@ -114,7 +114,7 @@ class URLRequestResourceBundleJob : public net::URLRequestSimpleJob {
*out_mime_type = *read_mime_type; *out_mime_type = *read_mime_type;
DetermineCharset(*read_mime_type, data.get(), charset); DetermineCharset(*read_mime_type, data.get(), charset);
int result = read_result ? net::OK : net::ERR_INVALID_URL; int result = read_result ? net::OK : net::ERR_INVALID_URL;
callback.Run(result); std::move(callback).Run(result);
} }
// We need the filename of the resource to determine the mime type. // We need the filename of the resource to determine the mime type.
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "content/test/test_navigation_url_loader_delegate.h" #include "content/test/test_navigation_url_loader_delegate.h"
#include "mojo/public/cpp/system/data_pipe_utils.h" #include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/chunked_upload_data_stream.h" #include "net/base/chunked_upload_data_stream.h"
#include "net/base/completion_once_callback.h"
#include "net/base/elements_upload_data_stream.h" #include "net/base/elements_upload_data_stream.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -312,7 +313,7 @@ class URLRequestBigJob : public net::URLRequestSimpleJob { ...@@ -312,7 +313,7 @@ class URLRequestBigJob : public net::URLRequestSimpleJob {
int GetData(std::string* mime_type, int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const net::CompletionCallback& callback) const override { net::CompletionOnceCallback callback) const override {
*mime_type = "text/plain"; *mime_type = "text/plain";
*charset = "UTF-8"; *charset = "UTF-8";
......
...@@ -123,7 +123,7 @@ class GeneratedBackgroundPageJob : public net::URLRequestSimpleJob { ...@@ -123,7 +123,7 @@ class GeneratedBackgroundPageJob : public net::URLRequestSimpleJob {
int GetData(std::string* mime_type, int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const net::CompletionCallback& callback) const override { net::CompletionOnceCallback callback) const override {
GenerateBackgroundPageContents(extension_.get(), mime_type, charset, data); GenerateBackgroundPageContents(extension_.get(), mime_type, charset, data);
return net::OK; return net::OK;
} }
......
...@@ -51,7 +51,7 @@ URLRequestDataJob::URLRequestDataJob( ...@@ -51,7 +51,7 @@ URLRequestDataJob::URLRequestDataJob(
int URLRequestDataJob::GetData(std::string* mime_type, int URLRequestDataJob::GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const CompletionCallback& callback) const { CompletionOnceCallback callback) const {
// Check if data URL is valid. If not, don't bother to try to extract data. // Check if data URL is valid. If not, don't bother to try to extract data.
// Otherwise, parse the data from the data URL. // Otherwise, parse the data from the data URL.
const GURL& url = request_->url(); const GURL& url = request_->url();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_simple_job.h" #include "net/url_request/url_request_simple_job.h"
...@@ -35,7 +36,7 @@ class NET_EXPORT URLRequestDataJob : public URLRequestSimpleJob { ...@@ -35,7 +36,7 @@ class NET_EXPORT URLRequestDataJob : public URLRequestSimpleJob {
int GetData(std::string* mime_type, int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const CompletionCallback& callback) const override; CompletionOnceCallback callback) const override;
private: private:
~URLRequestDataJob() override; ~URLRequestDataJob() override;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "net/url_request/url_request_simple_job.h" #include "net/url_request/url_request_simple_job.h"
#include <utility>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
...@@ -85,7 +86,7 @@ int URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size) { ...@@ -85,7 +86,7 @@ int URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size) {
int URLRequestSimpleJob::GetData(std::string* mime_type, int URLRequestSimpleJob::GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const CompletionCallback& callback) const { CompletionOnceCallback callback) const {
NOTREACHED(); NOTREACHED();
return ERR_UNEXPECTED; return ERR_UNEXPECTED;
} }
...@@ -94,9 +95,10 @@ int URLRequestSimpleJob::GetRefCountedData( ...@@ -94,9 +95,10 @@ int URLRequestSimpleJob::GetRefCountedData(
std::string* mime_type, std::string* mime_type,
std::string* charset, std::string* charset,
scoped_refptr<base::RefCountedMemory>* data, scoped_refptr<base::RefCountedMemory>* data,
const CompletionCallback& callback) const { CompletionOnceCallback callback) const {
scoped_refptr<base::RefCountedString> str_data(new base::RefCountedString()); scoped_refptr<base::RefCountedString> str_data(new base::RefCountedString());
int result = GetData(mime_type, charset, &str_data->data(), callback); int result =
GetData(mime_type, charset, &str_data->data(), std::move(callback));
*data = str_data; *data = str_data;
return result; return result;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/url_request/url_range_request_job.h" #include "net/url_request/url_range_request_job.h"
...@@ -51,14 +52,14 @@ class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob { ...@@ -51,14 +52,14 @@ class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
virtual int GetData(std::string* mime_type, virtual int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const CompletionCallback& callback) const; CompletionOnceCallback callback) const;
// Similar to GetData(), except |*data| can share ownership of the bytes // Similar to GetData(), except |*data| can share ownership of the bytes
// instead of copying them into a std::string. // instead of copying them into a std::string.
virtual int GetRefCountedData(std::string* mime_type, virtual int GetRefCountedData(std::string* mime_type,
std::string* charset, std::string* charset,
scoped_refptr<base::RefCountedMemory>* data, scoped_refptr<base::RefCountedMemory>* data,
const CompletionCallback& callback) const; CompletionOnceCallback callback) const;
void StartAsync(); void StartAsync();
......
...@@ -53,7 +53,7 @@ class MockSimpleJob : public URLRequestSimpleJob { ...@@ -53,7 +53,7 @@ class MockSimpleJob : public URLRequestSimpleJob {
int GetData(std::string* mime_type, int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const CompletionCallback& callback) const override { CompletionOnceCallback callback) const override {
mime_type->assign("text/plain"); mime_type->assign("text/plain");
charset->assign("US-ASCII"); charset->assign("US-ASCII");
data->assign(data_); data->assign(data_);
......
...@@ -180,11 +180,10 @@ void ViewBlobInternalsJob::Kill() { ...@@ -180,11 +180,10 @@ void ViewBlobInternalsJob::Kill() {
weak_factory_.InvalidateWeakPtrs(); weak_factory_.InvalidateWeakPtrs();
} }
int ViewBlobInternalsJob::GetData( int ViewBlobInternalsJob::GetData(std::string* mime_type,
std::string* mime_type, std::string* charset,
std::string* charset, std::string* data,
std::string* data, net::CompletionOnceCallback callback) const {
const net::CompletionCallback& callback) const {
mime_type->assign("text/html"); mime_type->assign("text/html");
charset->assign("UTF-8"); charset->assign("UTF-8");
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "net/base/completion_once_callback.h"
#include "net/url_request/url_request_simple_job.h" #include "net/url_request/url_request_simple_job.h"
#include "storage/browser/storage_browser_export.h" #include "storage/browser/storage_browser_export.h"
...@@ -34,7 +35,7 @@ class STORAGE_EXPORT ViewBlobInternalsJob ...@@ -34,7 +35,7 @@ class STORAGE_EXPORT ViewBlobInternalsJob
int GetData(std::string* mime_type, int GetData(std::string* mime_type,
std::string* charset, std::string* charset,
std::string* data, std::string* data,
const net::CompletionCallback& callback) const override; net::CompletionOnceCallback callback) const override;
bool IsRedirectResponse(GURL* location, bool IsRedirectResponse(GURL* location,
int* http_status_code, int* http_status_code,
bool* insecure_scheme_was_upgraded) override; bool* insecure_scheme_was_upgraded) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment