OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/net/url_request_mock_util.h" | 5 #include "chrome/browser/net/url_request_mock_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/thread_restrictions.h" |
10 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
11 #include "chrome/browser/net/url_request_failed_dns_job.h" | 12 #include "chrome/browser/net/url_request_failed_dns_job.h" |
12 #include "chrome/browser/net/url_request_mock_http_job.h" | 13 #include "chrome/browser/net/url_request_mock_http_job.h" |
13 #include "chrome/browser/net/url_request_mock_link_doctor_job.h" | 14 #include "chrome/browser/net/url_request_mock_link_doctor_job.h" |
14 #include "chrome/browser/net/url_request_slow_download_job.h" | 15 #include "chrome/browser/net/url_request_slow_download_job.h" |
15 #include "chrome/browser/net/url_request_slow_http_job.h" | 16 #include "chrome/browser/net/url_request_slow_http_job.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "net/url_request/url_request_filter.h" | 18 #include "net/url_request/url_request_filter.h" |
18 | 19 |
19 namespace chrome_browser_net { | 20 namespace chrome_browser_net { |
20 | 21 |
21 void SetUrlRequestMocksEnabled(bool enabled) { | 22 void SetUrlRequestMocksEnabled(bool enabled) { |
22 // Since this involves changing the URLRequest ProtocolFactory, we need to | 23 // Since this involves changing the URLRequest ProtocolFactory, we need to |
23 // run on the IO thread. | 24 // run on the IO thread. |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
25 | 26 |
26 if (enabled) { | 27 if (enabled) { |
| 28 // We have to look around for our helper files, but we only use |
| 29 // this from tests, so allow these IO operations to happen |
| 30 // anywhere. |
| 31 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 32 |
27 URLRequestFilter::GetInstance()->ClearHandlers(); | 33 URLRequestFilter::GetInstance()->ClearHandlers(); |
28 | 34 |
29 URLRequestFailedDnsJob::AddUrlHandler(); | 35 URLRequestFailedDnsJob::AddUrlHandler(); |
30 URLRequestMockLinkDoctorJob::AddUrlHandler(); | 36 URLRequestMockLinkDoctorJob::AddUrlHandler(); |
31 URLRequestSlowDownloadJob::AddUrlHandler(); | 37 URLRequestSlowDownloadJob::AddUrlHandler(); |
32 | 38 |
33 FilePath root_http; | 39 FilePath root_http; |
34 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 40 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
35 URLRequestMockHTTPJob::AddUrlHandler(root_http); | 41 URLRequestMockHTTPJob::AddUrlHandler(root_http); |
36 URLRequestSlowHTTPJob::AddUrlHandler(root_http); | 42 URLRequestSlowHTTPJob::AddUrlHandler(root_http); |
37 } else { | 43 } else { |
38 // Revert to the default handlers. | 44 // Revert to the default handlers. |
39 URLRequestFilter::GetInstance()->ClearHandlers(); | 45 URLRequestFilter::GetInstance()->ClearHandlers(); |
40 } | 46 } |
41 } | 47 } |
42 | 48 |
43 } // namespace chrome_browser_net | 49 } // namespace chrome_browser_net |
OLD | NEW |