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

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

Issue 2843573002: Use TaskScheduler instead of blocking pool in prerender_test_utils.cc. (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
« no previous file with comments | « no previous file | 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 (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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/task_scheduler/post_task.h"
18 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
19 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" 20 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h"
20 #include "chrome/browser/prerender/prerender_manager.h" 21 #include "chrome/browser/prerender/prerender_manager.h"
21 #include "chrome/browser/prerender/prerender_manager_factory.h" 22 #include "chrome/browser/prerender/prerender_manager_factory.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/safe_browsing/local_database_manager.h" 24 #include "chrome/browser/safe_browsing/local_database_manager.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
(...skipping 25 matching lines...) Expand all
53 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks. 54 // Wrapper over URLRequestMockHTTPJob that exposes extra callbacks.
54 class MockHTTPJob : public net::URLRequestMockHTTPJob { 55 class MockHTTPJob : public net::URLRequestMockHTTPJob {
55 public: 56 public:
56 MockHTTPJob(net::URLRequest* request, 57 MockHTTPJob(net::URLRequest* request,
57 net::NetworkDelegate* delegate, 58 net::NetworkDelegate* delegate,
58 const base::FilePath& file) 59 const base::FilePath& file)
59 : net::URLRequestMockHTTPJob( 60 : net::URLRequestMockHTTPJob(
60 request, 61 request,
61 delegate, 62 delegate,
62 file, 63 file,
63 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 64 base::CreateTaskRunnerWithTraits(
64 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {} 65 base::TaskTraits()
66 .MayBlock()
67 .WithPriority(base::TaskPriority::BACKGROUND)
68 .WithShutdownBehavior(
69 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN))) {}
65 70
66 void set_start_callback(const base::Closure& start_callback) { 71 void set_start_callback(const base::Closure& start_callback) {
67 start_callback_ = start_callback; 72 start_callback_ = start_callback;
68 } 73 }
69 74
70 void Start() override { 75 void Start() override {
71 if (!start_callback_.is_null()) 76 if (!start_callback_.is_null())
72 start_callback_.Run(); 77 start_callback_.Run();
73 net::URLRequestMockHTTPJob::Start(); 78 net::URLRequestMockHTTPJob::Start();
74 } 79 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 net::URLRequestJob* MaybeInterceptRequest( 191 net::URLRequestJob* MaybeInterceptRequest(
187 net::URLRequest* request, 192 net::URLRequest* request,
188 net::NetworkDelegate* network_delegate) const override { 193 net::NetworkDelegate* network_delegate) const override {
189 if (first_run_) { 194 if (first_run_) {
190 first_run_ = false; 195 first_run_ = false;
191 if (!callback_.is_null()) 196 if (!callback_.is_null())
192 callback_.Run(request); 197 callback_.Run(request);
193 return new HangingURLRequestJob(request, network_delegate); 198 return new HangingURLRequestJob(request, network_delegate);
194 } 199 }
195 return new net::URLRequestMockHTTPJob( 200 return new net::URLRequestMockHTTPJob(
196 request, 201 request, network_delegate, file_,
197 network_delegate, 202 base::CreateTaskRunnerWithTraits(
198 file_, 203 base::TaskTraits()
199 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 204 .MayBlock()
200 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 205 .WithPriority(base::TaskPriority::BACKGROUND)
206 .WithShutdownBehavior(
207 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN)));
201 } 208 }
202 209
203 private: 210 private:
204 base::FilePath file_; 211 base::FilePath file_;
205 base::Callback<void(net::URLRequest*)> callback_; 212 base::Callback<void(net::URLRequest*)> callback_;
206 mutable bool first_run_; 213 mutable bool first_run_;
207 }; 214 };
208 215
209 // An ExternalProtocolHandler that blocks everything and asserts it never is 216 // An ExternalProtocolHandler that blocks everything and asserts it never is
210 // called. 217 // called.
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
828 content::BrowserThread::PostTask( 835 content::BrowserThread::PostTask(
829 content::BrowserThread::IO, FROM_HERE, 836 content::BrowserThread::IO, FROM_HERE,
830 base::BindOnce(&CreateHangingFirstRequestInterceptorOnIO, url, file, 837 base::BindOnce(&CreateHangingFirstRequestInterceptorOnIO, url, file,
831 callback_io)); 838 callback_io));
832 } 839 }
833 840
834 } // namespace test_utils 841 } // namespace test_utils
835 842
836 } // namespace prerender 843 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698