Index: net/test/url_request/url_request_mock_http_job.cc |
diff --git a/content/test/net/url_request_mock_http_job.cc b/net/test/url_request/url_request_mock_http_job.cc |
similarity index 79% |
rename from content/test/net/url_request_mock_http_job.cc |
rename to net/test/url_request/url_request_mock_http_job.cc |
index 0572473643ef729b676599a3630da02dda320ea3..a7651bfb662311fd2480525c8ebbb7dcb6b7068f 100644 |
--- a/content/test/net/url_request_mock_http_job.cc |
+++ b/net/test/url_request/url_request_mock_http_job.cc |
@@ -2,16 +2,15 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/test/net/url_request_mock_http_job.h" |
+#include "net/test/url_request/url_request_mock_http_job.h" |
#include "base/file_util.h" |
+#include "base/macros.h" |
mmenke
2014/09/04 19:02:38
This should be in the header file (After adding DI
xunjieli
2014/09/04 19:24:16
Done. Should have read your comment more carefully
|
#include "base/message_loop/message_loop.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "base/threading/thread_restrictions.h" |
-#include "content/public/browser/browser_thread.h" |
-#include "content/public/common/url_constants.h" |
#include "net/base/filename_util.h" |
#include "net/http/http_response_headers.h" |
#include "net/url_request/url_request_filter.h" |
@@ -21,7 +20,7 @@ const char kMockHostname[] = "mock.http"; |
const base::FilePath::CharType kMockHeaderFileSuffix[] = |
FILE_PATH_LITERAL(".mock-http-headers"); |
-namespace content { |
+namespace net { |
namespace { |
@@ -31,10 +30,13 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
// contents of the file at |base_path|. When |map_all_requests_to_base_path| |
// is false, |base_path| is the file path leading to the root of the directory |
// to use as the root of the HTTP server. |
- MockJobInterceptor(const base::FilePath& base_path, |
- bool map_all_requests_to_base_path) |
+ MockJobInterceptor( |
+ const base::FilePath& base_path, |
+ bool map_all_requests_to_base_path, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) |
: base_path_(base_path), |
- map_all_requests_to_base_path_(map_all_requests_to_base_path) {} |
+ map_all_requests_to_base_path_(map_all_requests_to_base_path), |
+ worker_pool_(worker_pool) {} |
virtual ~MockJobInterceptor() {} |
// net::URLRequestJobFactory::ProtocolHandler implementation |
@@ -42,7 +44,8 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
net::URLRequest* request, |
net::NetworkDelegate* network_delegate) const OVERRIDE { |
return new URLRequestMockHTTPJob(request, network_delegate, |
- map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request)); |
+ map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request), |
+ worker_pool_); |
} |
private: |
@@ -60,6 +63,7 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
const base::FilePath base_path_; |
const bool map_all_requests_to_base_path_; |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool_; |
mmenke
2014/09/04 19:02:38
IMPORTANT: Remove the &. Otherwise, we'll have a
xunjieli
2014/09/04 19:24:16
Done.
|
DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); |
}; |
@@ -67,20 +71,24 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
} // namespace |
// static |
-void URLRequestMockHTTPJob::AddUrlHandler(const base::FilePath& base_path) { |
+void URLRequestMockHTTPJob::AddUrlHandler( |
+ const base::FilePath& base_path, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) { |
// Add kMockHostname to net::URLRequestFilter. |
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
filter->AddHostnameInterceptor( |
- "http", kMockHostname, CreateInterceptor(base_path)); |
+ "http", kMockHostname, CreateInterceptor(base_path, worker_pool)); |
} |
// static |
void URLRequestMockHTTPJob::AddHostnameToFileHandler( |
const std::string& hostname, |
- const base::FilePath& file) { |
+ const base::FilePath& file, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) { |
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
filter->AddHostnameInterceptor( |
- "http", hostname, CreateInterceptorForSingleFile(file)); |
+ "http", hostname, |
+ CreateInterceptorForSingleFile(file, worker_pool)); |
} |
// static |
@@ -95,36 +103,31 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const base::FilePath& path) { |
} |
// static |
-GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const base::FilePath& path) { |
- std::string url = kViewSourceScheme; |
- url.append(":"); |
- url.append(GetMockUrl(path).spec()); |
- return GURL(url); |
-} |
- |
-// static |
scoped_ptr<net::URLRequestInterceptor> |
-URLRequestMockHTTPJob::CreateInterceptor(const base::FilePath& base_path) { |
+URLRequestMockHTTPJob::CreateInterceptor( |
+ const base::FilePath& base_path, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) { |
return scoped_ptr<net::URLRequestInterceptor>( |
- new MockJobInterceptor(base_path, false)); |
+ new MockJobInterceptor(base_path, false, worker_pool)); |
} |
// static |
scoped_ptr<net::URLRequestInterceptor> |
URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
- const base::FilePath& file) { |
+ const base::FilePath& file, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) { |
return scoped_ptr<net::URLRequestInterceptor>( |
- new MockJobInterceptor(file, true)); |
+ new MockJobInterceptor(file, true, worker_pool)); |
} |
URLRequestMockHTTPJob::URLRequestMockHTTPJob( |
net::URLRequest* request, net::NetworkDelegate* network_delegate, |
- const base::FilePath& file_path) |
+ const base::FilePath& file_path, |
+ const scoped_refptr<base::SequencedWorkerPool>& worker_pool) |
: net::URLRequestFileJob( |
request, network_delegate, file_path, |
- content::BrowserThread::GetBlockingPool()-> |
- GetTaskRunnerWithShutdownBehavior( |
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {} |
+ worker_pool->GetTaskRunnerWithShutdownBehavior( |
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)) {} |
URLRequestMockHTTPJob::~URLRequestMockHTTPJob() { } |
@@ -146,7 +149,7 @@ void URLRequestMockHTTPJob::GetResponseInfoConst( |
net::HttpResponseInfo* info) const { |
// We have to load our headers from disk, but we only use this class |
// from tests, so allow these IO operations to happen on any thread. |
- base::ThreadRestrictions::ScopedAllowIO allow_io; |
+ base::ThreadRestrictions::SetIOAllowed(true); |
base::FilePath header_file = |
base::FilePath(file_path_.value() + kMockHeaderFileSuffix); |
@@ -187,4 +190,4 @@ bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
return info.headers.get() && info.headers->GetCharset(charset); |
} |
-} // namespace content |
+} // namespace net |