| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/automation/url_request_slow_http_job.h" |
| 6 |
| 7 #include "base/platform_thread.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/time.h" |
| 10 #include "net/url_request/url_request_filter.h" |
| 11 |
| 12 static const char kMockHostname[] = "mock.slow.http"; |
| 13 |
| 14 std::wstring URLRequestSlowHTTPJob::base_path_ = L""; |
| 15 |
| 16 // static |
| 17 const int URLRequestSlowHTTPJob::kDelayMs = 1000; |
| 18 |
| 19 using base::TimeDelta; |
| 20 |
| 21 /* static */ |
| 22 URLRequestJob* URLRequestSlowHTTPJob::Factory(URLRequest* request, |
| 23 const std::string& scheme) { |
| 24 return new URLRequestSlowHTTPJob(request, |
| 25 GetOnDiskPath(base_path_, request, scheme)); |
| 26 } |
| 27 |
| 28 /* static */ |
| 29 void URLRequestSlowHTTPJob::AddUITestUrls(const std::wstring& base_path) { |
| 30 base_path_ = base_path; |
| 31 |
| 32 // Add kMockHostname to URLRequestFilter. |
| 33 URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
| 34 filter->AddHostnameHandler("http", kMockHostname, |
| 35 URLRequestSlowHTTPJob::Factory); |
| 36 } |
| 37 |
| 38 /* static */ |
| 39 GURL URLRequestSlowHTTPJob::GetMockUrl(const std::wstring& path) { |
| 40 std::string url = "http://"; |
| 41 url.append(kMockHostname); |
| 42 url.append("/"); |
| 43 url.append(WideToUTF8(path)); |
| 44 return GURL(url); |
| 45 } |
| 46 |
| 47 URLRequestSlowHTTPJob::URLRequestSlowHTTPJob(URLRequest* request, |
| 48 const FilePath& file_path) |
| 49 : URLRequestMockHTTPJob(request, file_path) { } |
| 50 |
| 51 void URLRequestSlowHTTPJob::Start() { |
| 52 delay_timer_.Start(TimeDelta::FromMilliseconds(kDelayMs), this, |
| 53 &URLRequestSlowHTTPJob::RealStart); |
| 54 } |
| 55 |
| 56 void URLRequestSlowHTTPJob::RealStart() { |
| 57 URLRequestMockHTTPJob::Start(); |
| 58 } |
| OLD | NEW |