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

Side by Side Diff: chrome/browser/prerender/prerender_test_utils.cc

Issue 2833553002: Revert of [Prerender] Restore request priorities when swapped in (Closed)
Patch Set: Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/prerender/prerender_test_utils.h" 5 #include "chrome/browser/prerender/prerender_test_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 171
172 void Start() override {} 172 void Start() override {}
173 173
174 private: 174 private:
175 ~HangingURLRequestJob() override {} 175 ~HangingURLRequestJob() override {}
176 }; 176 };
177 177
178 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor { 178 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor {
179 public: 179 public:
180 HangingFirstRequestInterceptor( 180 HangingFirstRequestInterceptor(const base::FilePath& file,
181 const base::FilePath& file, 181 base::Closure callback)
182 base::Callback<void(net::URLRequest*)> callback) 182 : file_(file),
183 : file_(file), callback_(callback), first_run_(true) {} 183 callback_(callback),
184 first_run_(true) {
185 }
184 ~HangingFirstRequestInterceptor() override {} 186 ~HangingFirstRequestInterceptor() override {}
185 187
186 net::URLRequestJob* MaybeInterceptRequest( 188 net::URLRequestJob* MaybeInterceptRequest(
187 net::URLRequest* request, 189 net::URLRequest* request,
188 net::NetworkDelegate* network_delegate) const override { 190 net::NetworkDelegate* network_delegate) const override {
189 if (first_run_) { 191 if (first_run_) {
190 first_run_ = false; 192 first_run_ = false;
191 if (!callback_.is_null()) 193 if (!callback_.is_null()) {
192 callback_.Run(request); 194 BrowserThread::PostTask(
195 BrowserThread::UI, FROM_HERE, callback_);
196 }
193 return new HangingURLRequestJob(request, network_delegate); 197 return new HangingURLRequestJob(request, network_delegate);
194 } 198 }
195 return new net::URLRequestMockHTTPJob( 199 return new net::URLRequestMockHTTPJob(
196 request, 200 request,
197 network_delegate, 201 network_delegate,
198 file_, 202 file_,
199 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 203 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
200 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 204 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
201 } 205 }
202 206
203 private: 207 private:
204 base::FilePath file_; 208 base::FilePath file_;
205 base::Callback<void(net::URLRequest*)> callback_; 209 base::Closure callback_;
206 mutable bool first_run_; 210 mutable bool first_run_;
207 }; 211 };
208 212
209 // An ExternalProtocolHandler that blocks everything and asserts it never is 213 // An ExternalProtocolHandler that blocks everything and asserts it never is
210 // called. 214 // called.
211 class NeverRunsExternalProtocolHandlerDelegate 215 class NeverRunsExternalProtocolHandlerDelegate
212 : public ExternalProtocolHandler::Delegate { 216 : public ExternalProtocolHandler::Delegate {
213 public: 217 public:
214 scoped_refptr<shell_integration::DefaultProtocolClientWorker> 218 scoped_refptr<shell_integration::DefaultProtocolClientWorker>
215 CreateShellWorker( 219 CreateShellWorker(
(...skipping 24 matching lines...) Expand all
240 244
241 void LaunchUrlWithoutSecurityCheck( 245 void LaunchUrlWithoutSecurityCheck(
242 const GURL& url, 246 const GURL& url,
243 content::WebContents* web_contents) override { 247 content::WebContents* web_contents) override {
244 NOTREACHED(); 248 NOTREACHED();
245 } 249 }
246 250
247 void FinishedProcessingCheck() override { NOTREACHED(); } 251 void FinishedProcessingCheck() override { NOTREACHED(); }
248 }; 252 };
249 253
250 void CreateHangingFirstRequestInterceptorOnIO(
251 const GURL& url,
252 const base::FilePath& file,
253 base::Callback<void(net::URLRequest*)> callback_io) {
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
255 std::unique_ptr<net::URLRequestInterceptor> interceptor(
256 new HangingFirstRequestInterceptor(file, callback_io));
257 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
258 url, std::move(interceptor));
259 }
260
261 } // namespace 254 } // namespace
262 255
263 RequestCounter::RequestCounter() : count_(0), expected_count_(-1) {} 256 RequestCounter::RequestCounter() : count_(0), expected_count_(-1) {}
264 257
265 RequestCounter::~RequestCounter() {} 258 RequestCounter::~RequestCounter() {}
266 259
267 void RequestCounter::RequestStarted() { 260 void RequestCounter::RequestStarted() {
268 count_++; 261 count_++;
269 if (loop_ && count_ == expected_count_) 262 if (loop_ && count_ == expected_count_)
270 loop_->Quit(); 263 loop_->Quit();
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 CountingInterceptorWithCallback::Initialize(url, counter, callback_io); 794 CountingInterceptorWithCallback::Initialize(url, counter, callback_io);
802 } 795 }
803 796
804 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { 797 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
805 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 798 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
806 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 799 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
807 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( 800 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
808 file, content::BrowserThread::GetBlockingPool())); 801 file, content::BrowserThread::GetBlockingPool()));
809 } 802 }
810 803
811 void CreateHangingFirstRequestInterceptor( 804 void CreateHangingFirstRequestInterceptorOnIO(
812 const GURL& url, 805 const GURL& url, const base::FilePath& file, base::Closure callback) {
813 const base::FilePath& file, 806 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
814 base::Callback<void(net::URLRequest*)> callback_io) { 807 std::unique_ptr<net::URLRequestInterceptor> interceptor(
815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 808 new HangingFirstRequestInterceptor(file, callback));
816 content::BrowserThread::PostTask( 809 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
817 content::BrowserThread::IO, FROM_HERE, 810 url, std::move(interceptor));
818 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, url, file,
819 callback_io));
820 } 811 }
821 812
822 } // namespace test_utils 813 } // namespace test_utils
823 814
824 } // namespace prerender 815 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698