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

Side by Side Diff: net/url_request/url_request_data_job_fuzzer.cc

Issue 2313013002: Revert of Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: Created 4 years, 3 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
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 read_loop_ = nullptr; 92 read_loop_ = nullptr;
93 return 0; 93 return 0;
94 } 94 }
95 95
96 void QuitLoop() { 96 void QuitLoop() {
97 DCHECK(read_loop_); 97 DCHECK(read_loop_);
98 task_runner_->PostTask(FROM_HERE, read_loop_->QuitClosure()); 98 task_runner_->PostTask(FROM_HERE, read_loop_->QuitClosure());
99 } 99 }
100 100
101 void ReadFromRequest(net::URLRequest* request) { 101 void ReadFromRequest(net::URLRequest* request) {
102 int bytes_read = 0; 102 bool sync = false;
103 do { 103 do {
104 // If possible, pop the next read size. If none exists, then this should 104 // If possible, pop the next read size. If none exists, then this should
105 // be the last call to Read. 105 // be the last call to Read.
106 bool using_populated_read = read_lengths_.size() > 0; 106 bool using_populated_read = read_lengths_.size() > 0;
107 size_t read_size = 1; 107 size_t read_size = 1;
108 if (using_populated_read) { 108 if (using_populated_read) {
109 read_size = read_lengths_.back(); 109 read_size = read_lengths_.back();
110 read_lengths_.pop_back(); 110 read_lengths_.pop_back();
111 } 111 }
112 112
113 bytes_read = request->Read(buf_.get(), read_size); 113 int bytes_read = 0;
114 } while (bytes_read > 0); 114 sync = request->Read(buf_.get(), read_size, &bytes_read);
115 } while (sync);
115 116
116 if (bytes_read != net::ERR_IO_PENDING) 117 if (!request->status().is_io_pending())
117 QuitLoop(); 118 QuitLoop();
118 } 119 }
119 120
120 // net::URLRequest::Delegate: 121 // net::URLRequest::Delegate:
121 void OnReceivedRedirect(net::URLRequest* request, 122 void OnReceivedRedirect(net::URLRequest* request,
122 const net::RedirectInfo& redirect_info, 123 const net::RedirectInfo& redirect_info,
123 bool* defer_redirect) override {} 124 bool* defer_redirect) override {}
124 void OnAuthRequired(net::URLRequest* request, 125 void OnAuthRequired(net::URLRequest* request,
125 net::AuthChallengeInfo* auth_info) override {} 126 net::AuthChallengeInfo* auth_info) override {}
126 void OnCertificateRequested( 127 void OnCertificateRequested(
127 net::URLRequest* request, 128 net::URLRequest* request,
128 net::SSLCertRequestInfo* cert_request_info) override {} 129 net::SSLCertRequestInfo* cert_request_info) override {}
129 void OnSSLCertificateError(net::URLRequest* request, 130 void OnSSLCertificateError(net::URLRequest* request,
130 const net::SSLInfo& ssl_info, 131 const net::SSLInfo& ssl_info,
131 bool fatal) override {} 132 bool fatal) override {}
132 void OnResponseStarted(net::URLRequest* request, int net_error) override { 133 void OnResponseStarted(net::URLRequest* request) override {
134 DCHECK(!request->status().is_io_pending());
133 DCHECK(buf_.get()); 135 DCHECK(buf_.get());
134 DCHECK(read_loop_); 136 DCHECK(read_loop_);
135 DCHECK_NE(net::ERR_IO_PENDING, net_error); 137 if (request->status().is_success()) {
136
137 if (net_error == net::OK) {
138 ReadFromRequest(request); 138 ReadFromRequest(request);
139 } else { 139 } else {
140 QuitLoop(); 140 QuitLoop();
141 } 141 }
142 } 142 }
143 void OnReadCompleted(net::URLRequest* request, int bytes_read) override { 143 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {
144 DCHECK_NE(net::ERR_IO_PENDING, bytes_read); 144 DCHECK(!request->status().is_io_pending());
145 DCHECK(buf_.get()); 145 DCHECK(buf_.get());
146 DCHECK(read_loop_); 146 DCHECK(read_loop_);
147 147 if (request->status().is_success() && bytes_read > 0) {
148 if (bytes_read > 0) {
149 ReadFromRequest(request); 148 ReadFromRequest(request);
150 } else { 149 } else {
151 QuitLoop(); 150 QuitLoop();
152 } 151 }
153 } 152 }
154 153
155 private: 154 private:
156 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>; 155 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>;
157 156
158 net::TestURLRequestContext context_; 157 net::TestURLRequestContext context_;
159 net::URLRequestJobFactoryImpl job_factory_; 158 net::URLRequestJobFactoryImpl job_factory_;
160 std::vector<size_t> read_lengths_; 159 std::vector<size_t> read_lengths_;
161 scoped_refptr<net::IOBuffer> buf_; 160 scoped_refptr<net::IOBuffer> buf_;
162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 161 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
163 base::RunLoop* read_loop_; 162 base::RunLoop* read_loop_;
164 163
165 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); 164 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness);
166 }; 165 };
167 166
168 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 167 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
169 // Using a static singleton test harness lets the test run ~3-4x faster. 168 // Using a static singleton test harness lets the test run ~3-4x faster.
170 return URLRequestDataJobFuzzerHarness::GetInstance() 169 return URLRequestDataJobFuzzerHarness::GetInstance()
171 ->CreateAndReadFromDataURLRequest(data, size); 170 ->CreateAndReadFromDataURLRequest(data, size);
172 } 171 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_context_builder.cc ('k') | net/url_request/url_request_file_dir_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698