OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "content/browser/net/url_request_slow_http_job.h" | 5 #include "content/browser/net/url_request_slow_http_job.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "net/url_request/url_request_filter.h" | 9 #include "net/url_request/url_request_filter.h" |
10 | 10 |
11 static const char kMockHostname[] = "mock.slow.http"; | 11 static const char kMockHostname[] = "mock.slow.http"; |
12 | 12 |
13 FilePath URLRequestSlowHTTPJob::base_path_; | 13 // static |
| 14 FilePath& URLRequestSlowHTTPJob::BasePath() { |
| 15 CR_DEFINE_STATIC_LOCAL(FilePath, base_path, ()); |
| 16 return base_path; |
| 17 } |
14 | 18 |
15 // static | 19 // static |
16 const int URLRequestSlowHTTPJob::kDelayMs = 1000; | 20 const int URLRequestSlowHTTPJob::kDelayMs = 1000; |
17 | 21 |
18 using base::TimeDelta; | 22 using base::TimeDelta; |
19 | 23 |
20 /* static */ | 24 // static |
21 net::URLRequestJob* URLRequestSlowHTTPJob::Factory(net::URLRequest* request, | 25 net::URLRequestJob* URLRequestSlowHTTPJob::Factory(net::URLRequest* request, |
22 const std::string& scheme) { | 26 const std::string& scheme) { |
23 return new URLRequestSlowHTTPJob(request, | 27 return new URLRequestSlowHTTPJob(request, |
24 GetOnDiskPath(base_path_, request, scheme)); | 28 GetOnDiskPath(BasePath(), request, scheme)); |
25 } | 29 } |
26 | 30 |
27 /* static */ | 31 // static |
28 void URLRequestSlowHTTPJob::AddUrlHandler(const FilePath& base_path) { | 32 void URLRequestSlowHTTPJob::AddUrlHandler(const FilePath& base_path) { |
29 base_path_ = base_path; | 33 BasePath() = base_path; |
30 | 34 |
31 // Add kMockHostname to net::URLRequestFilter. | 35 // Add kMockHostname to net::URLRequestFilter. |
32 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 36 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
33 filter->AddHostnameHandler("http", kMockHostname, | 37 filter->AddHostnameHandler("http", kMockHostname, |
34 URLRequestSlowHTTPJob::Factory); | 38 URLRequestSlowHTTPJob::Factory); |
35 } | 39 } |
36 | 40 |
37 /* static */ | 41 /* static */ |
38 GURL URLRequestSlowHTTPJob::GetMockUrl(const FilePath& path) { | 42 GURL URLRequestSlowHTTPJob::GetMockUrl(const FilePath& path) { |
39 std::string url = "http://"; | 43 std::string url = "http://"; |
(...skipping 13 matching lines...) Expand all Loading... |
53 delay_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kDelayMs), this, | 57 delay_timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kDelayMs), this, |
54 &URLRequestSlowHTTPJob::RealStart); | 58 &URLRequestSlowHTTPJob::RealStart); |
55 } | 59 } |
56 | 60 |
57 URLRequestSlowHTTPJob::~URLRequestSlowHTTPJob() { | 61 URLRequestSlowHTTPJob::~URLRequestSlowHTTPJob() { |
58 } | 62 } |
59 | 63 |
60 void URLRequestSlowHTTPJob::RealStart() { | 64 void URLRequestSlowHTTPJob::RealStart() { |
61 URLRequestMockHTTPJob::Start(); | 65 URLRequestMockHTTPJob::Start(); |
62 } | 66 } |
OLD | NEW |