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

Side by Side Diff: content/child/url_response_body_consumer.cc

Issue 2591383003: Implement SetDefersLoading on content::URLLoaderClientImpl (Closed)
Patch Set: fix Created 3 years, 12 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
« no previous file with comments | « content/child/url_response_body_consumer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/child/url_response_body_consumer.h" 5 #include "content/child/url_response_body_consumer.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 has_received_completion_ = true; 69 has_received_completion_ = true;
70 completion_status_ = status; 70 completion_status_ = status;
71 NotifyCompletionIfAppropriate(); 71 NotifyCompletionIfAppropriate();
72 } 72 }
73 73
74 void URLResponseBodyConsumer::Cancel() { 74 void URLResponseBodyConsumer::Cancel() {
75 has_been_cancelled_ = true; 75 has_been_cancelled_ = true;
76 handle_watcher_.Cancel(); 76 handle_watcher_.Cancel();
77 } 77 }
78 78
79 void URLResponseBodyConsumer::SetDefersLoading() {
80 is_deferred_ = true;
81 }
82
83 void URLResponseBodyConsumer::UnsetDefersLoading() {
84 is_deferred_ = false;
85 OnReadable(MOJO_RESULT_OK);
86 }
87
79 void URLResponseBodyConsumer::Reclaim(uint32_t size) { 88 void URLResponseBodyConsumer::Reclaim(uint32_t size) {
80 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size); 89 MojoResult result = mojo::EndReadDataRaw(handle_.get(), size);
81 DCHECK_EQ(MOJO_RESULT_OK, result); 90 DCHECK_EQ(MOJO_RESULT_OK, result);
82 91
83 if (is_in_on_readable_) 92 if (is_in_on_readable_)
84 return; 93 return;
85 94
86 task_runner_->PostTask( 95 task_runner_->PostTask(
87 FROM_HERE, base::Bind(&URLResponseBodyConsumer::OnReadable, AsWeakPtr(), 96 FROM_HERE, base::Bind(&URLResponseBodyConsumer::OnReadable, AsWeakPtr(),
88 MOJO_RESULT_OK)); 97 MOJO_RESULT_OK));
89 } 98 }
90 99
91 void URLResponseBodyConsumer::OnReadable(MojoResult unused) { 100 void URLResponseBodyConsumer::OnReadable(MojoResult unused) {
101 if (has_been_cancelled_ || has_seen_end_of_data_ || is_deferred_)
102 return;
103
92 DCHECK(!is_in_on_readable_); 104 DCHECK(!is_in_on_readable_);
93 105
94 if (has_been_cancelled_ || has_seen_end_of_data_)
95 return;
96
97 // Protect |this| as RequestPeer::OnReceivedData may call deref. 106 // Protect |this| as RequestPeer::OnReceivedData may call deref.
98 scoped_refptr<URLResponseBodyConsumer> protect(this); 107 scoped_refptr<URLResponseBodyConsumer> protect(this);
99 base::AutoReset<bool> is_in_on_readable(&is_in_on_readable_, true); 108 base::AutoReset<bool> is_in_on_readable(&is_in_on_readable_, true);
100 109
101 // TODO(yhirano): Suppress notification when deferred. 110 while (!has_been_cancelled_ && !is_deferred_) {
102 while (!has_been_cancelled_) {
103 const void* buffer = nullptr; 111 const void* buffer = nullptr;
104 uint32_t available = 0; 112 uint32_t available = 0;
105 MojoResult result = mojo::BeginReadDataRaw( 113 MojoResult result = mojo::BeginReadDataRaw(
106 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE); 114 handle_.get(), &buffer, &available, MOJO_READ_DATA_FLAG_NONE);
107 if (result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_BUSY) 115 if (result == MOJO_RESULT_SHOULD_WAIT || result == MOJO_RESULT_BUSY)
108 return; 116 return;
109 if (result == MOJO_RESULT_FAILED_PRECONDITION) { 117 if (result == MOJO_RESULT_FAILED_PRECONDITION) {
110 has_seen_end_of_data_ = true; 118 has_seen_end_of_data_ = true;
111 NotifyCompletionIfAppropriate(); 119 NotifyCompletionIfAppropriate();
112 return; 120 return;
(...skipping 14 matching lines...) Expand all
127 } 135 }
128 136
129 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() { 137 void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() {
130 if (has_been_cancelled_) 138 if (has_been_cancelled_)
131 return; 139 return;
132 if (!has_received_completion_ || !has_seen_end_of_data_) 140 if (!has_received_completion_ || !has_seen_end_of_data_)
133 return; 141 return;
134 // Cancel this instance in order not to notify twice. 142 // Cancel this instance in order not to notify twice.
135 Cancel(); 143 Cancel();
136 144
137 resource_dispatcher_->OnMessageReceived( 145 resource_dispatcher_->DispatchMessage(
138 ResourceMsg_RequestComplete(request_id_, completion_status_)); 146 ResourceMsg_RequestComplete(request_id_, completion_status_));
139 // |this| may be deleted. 147 // |this| may be deleted.
140 } 148 }
141 149
142 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/child/url_response_body_consumer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698