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

Unified Diff: net/url_request/url_fetcher_core.cc

Issue 15711003: net: Move write flush responsiblity from URLFetcherResponseWriter to URLFetcherCore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_response_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_fetcher_core.cc
diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc
index 24d4b46889f50c8db220bd7459b8ff1b76c17d13..d60f9b5045668e956fed5718aff4ff8813d753f9 100644
--- a/net/url_request/url_fetcher_core.cc
+++ b/net/url_request/url_fetcher_core.cc
@@ -431,9 +431,7 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request,
InformDelegateDownloadProgress();
InformDelegateDownloadDataIfNecessary(bytes_read);
- const int result = response_writer_->Write(
- buffer_, bytes_read,
- base::Bind(&URLFetcherCore::DidWriteBuffer, this));
+ const int result = WriteBuffer(new DrainableIOBuffer(buffer_, bytes_read));
if (result < 0) {
// Write failed or waiting for write completion.
if (result == ERR_IO_PENDING)
@@ -822,14 +820,35 @@ void URLFetcherCore::CompleteAddingUploadDataChunk(
is_last_chunk);
}
-void URLFetcherCore::DidWriteBuffer(int result) {
- if (result < 0) {
+int URLFetcherCore::WriteBuffer(scoped_refptr<DrainableIOBuffer> data) {
+ while (data->BytesRemaining() > 0) {
+ const int result = response_writer_->Write(
+ data, data->BytesRemaining(),
+ base::Bind(&URLFetcherCore::DidWriteBuffer, this, data));
+ if (result < 0)
+ return result;
+ data->DidConsume(result);
+ }
+ return OK;
+}
+
+void URLFetcherCore::DidWriteBuffer(scoped_refptr<DrainableIOBuffer> data,
+ int result) {
+ if (result >= 0) { // Continue writing.
+ data->DidConsume(result);
+ result = WriteBuffer(data);
+ if (result == ERR_IO_PENDING)
+ return;
+ }
+
+ if (result < 0) { // Handle errors.
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, this));
return;
}
// Finished writing buffer_. Read some more.
+ DCHECK_EQ(0, data->BytesRemaining());
ReadResponse();
}
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_response_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698