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 81% |
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..7ac0b41eea76b4cd19ecf4b03a738bfe5981d178 100644 |
--- a/content/test/net/url_request_mock_http_job.cc |
+++ b/net/test/url_request/url_request_mock_http_job.cc |
@@ -2,7 +2,7 @@ |
// 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/message_loop/message_loop.h" |
@@ -10,8 +10,6 @@ |
#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 +19,7 @@ const char kMockHostname[] = "mock.http"; |
const base::FilePath::CharType kMockHeaderFileSuffix[] = |
FILE_PATH_LITERAL(".mock-http-headers"); |
-namespace content { |
+namespace net { |
namespace { |
@@ -32,9 +30,11 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
// 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) |
+ bool map_all_requests_to_base_path, |
+ 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 +42,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 +61,7 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
const base::FilePath base_path_; |
const bool map_all_requests_to_base_path_; |
+ base::SequencedWorkerPool* worker_pool_; |
DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); |
}; |
@@ -67,20 +69,24 @@ class MockJobInterceptor : public net::URLRequestInterceptor { |
} // namespace |
// static |
-void URLRequestMockHTTPJob::AddUrlHandler(const base::FilePath& base_path) { |
+void URLRequestMockHTTPJob::AddUrlHandler( |
+ const base::FilePath& base_path, |
+ 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, |
+ base::SequencedWorkerPool* worker_pool) { |
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
filter->AddHostnameInterceptor( |
- "http", hostname, CreateInterceptorForSingleFile(file)); |
+ "http", hostname, |
+ CreateInterceptorForSingleFile(file, worker_pool)); |
} |
// static |
@@ -96,7 +102,7 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const base::FilePath& path) { |
// static |
GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const base::FilePath& path) { |
- std::string url = kViewSourceScheme; |
+ std::string url = "view-source"; |
mmenke
2014/09/04 18:05:12
This is a layering violation. net shouldn't know
xunjieli
2014/09/04 18:44:25
Done. Thanks! That was a bad thing to do. I was pl
|
url.append(":"); |
url.append(GetMockUrl(path).spec()); |
return GURL(url); |
@@ -104,27 +110,30 @@ GURL URLRequestMockHTTPJob::GetMockViewSourceUrl(const base::FilePath& path) { |
// static |
scoped_ptr<net::URLRequestInterceptor> |
-URLRequestMockHTTPJob::CreateInterceptor(const base::FilePath& base_path) { |
+URLRequestMockHTTPJob::CreateInterceptor( |
+ const base::FilePath& base_path, |
+ 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, |
+ 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, |
+ 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 +155,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 +196,4 @@ bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
return info.headers.get() && info.headers->GetCharset(charset); |
} |
-} // namespace content |
+} // namespace net |