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

Unified Diff: net/url_request/url_request_simple_job.h

Issue 725443003: Avoid a string copy in URLRequestResourceBundleJob::GetData(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Tidy up Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/chrome_url_request_util.cc ('k') | net/url_request/url_request_simple_job.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_simple_job.h
diff --git a/net/url_request/url_request_simple_job.h b/net/url_request/url_request_simple_job.h
index 85d8f7e39edfa29edbdf26e7be96cccb11e157cc..99b6cb6f5c594cf48ccd53f5ceea2f29439dbfaf 100644
--- a/net/url_request/url_request_simple_job.h
+++ b/net/url_request/url_request_simple_job.h
@@ -7,11 +7,17 @@
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "base/strings/string_piece.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
#include "net/url_request/url_range_request_job.h"
+namespace base {
+class RefCountedMemory;
+}
+
namespace net {
class URLRequest;
@@ -28,7 +34,8 @@ class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
protected:
~URLRequestSimpleJob() override;
- // Subclasses must override the way response data is determined.
+ // Subclasses must override either GetData or GetRefCountedData to define the
+ // way response data is determined.
// The return value should be:
// - OK if data is obtained;
// - ERR_IO_PENDING if async processing is needed to finish obtaining data.
@@ -41,9 +48,15 @@ class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
virtual int GetData(std::string* mime_type,
std::string* charset,
std::string* data,
- const CompletionCallback& callback) const = 0;
+ const CompletionCallback& callback) const;
+
+ // Similar to GetData(), except |*data| can share ownership of the bytes
+ // instead of copying them into a std::string.
+ virtual int GetRefCountedData(std::string* mime_type,
+ std::string* charset,
+ scoped_refptr<base::RefCountedMemory>* data,
+ const CompletionCallback& callback) const;
- protected:
void StartAsync();
private:
@@ -52,7 +65,7 @@ class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
HttpByteRange byte_range_;
std::string mime_type_;
std::string charset_;
- std::string data_;
+ scoped_refptr<base::RefCountedMemory> data_;
int data_offset_;
base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_;
};
« no previous file with comments | « chrome/browser/extensions/chrome_url_request_util.cc ('k') | net/url_request/url_request_simple_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698