| 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 // This class simulates a slow download. This used in a UI test to test the | 4 // This class simulates a slow download. This used in a UI test to test the |
| 5 // download manager. Requests to |kUnknownSizeUrl| and |kKnownSizeUrl| start | 5 // download manager. Requests to |kUnknownSizeUrl| and |kKnownSizeUrl| start |
| 6 // downloads that pause after the first | 6 // downloads that pause after the first chunk of data is delivered. |
| 7 // A later request to |kFinishDownloadUrl| will finish these downloads. |
| 8 // A later request to |kErrorFinishDownloadUrl| will cause these |
| 9 // downloads to error with |net::ERR_FAILED|. |
| 10 // TODO(rdsmith): Update to allow control of returned error. |
| 7 | 11 |
| 8 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 12 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| 9 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 13 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| 10 #pragma once | 14 #pragma once |
| 11 | 15 |
| 12 #include <string> | 16 #include <string> |
| 13 #include <vector> | 17 #include <vector> |
| 14 | 18 |
| 15 #include "base/task.h" | 19 #include "base/task.h" |
| 16 #include "net/url_request/url_request_job.h" | 20 #include "net/url_request/url_request_job.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 29 virtual void GetResponseInfo(net::HttpResponseInfo* info); | 33 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
| 30 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 34 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
| 31 | 35 |
| 32 static net::URLRequestJob* Factory(net::URLRequest* request, | 36 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 33 const std::string& scheme); | 37 const std::string& scheme); |
| 34 | 38 |
| 35 // Test URLs. | 39 // Test URLs. |
| 36 static const char kUnknownSizeUrl[]; | 40 static const char kUnknownSizeUrl[]; |
| 37 static const char kKnownSizeUrl[]; | 41 static const char kKnownSizeUrl[]; |
| 38 static const char kFinishDownloadUrl[]; | 42 static const char kFinishDownloadUrl[]; |
| 43 static const char kErrorFinishDownloadUrl[]; |
| 39 | 44 |
| 40 // Adds the testing URLs to the net::URLRequestFilter. | 45 // Adds the testing URLs to the net::URLRequestFilter. |
| 41 static void AddUrlHandler(); | 46 static void AddUrlHandler(); |
| 42 | 47 |
| 43 private: | 48 private: |
| 44 virtual ~URLRequestSlowDownloadJob(); | 49 virtual ~URLRequestSlowDownloadJob(); |
| 45 | 50 |
| 46 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 51 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
| 47 | 52 |
| 48 // Mark all pending requests to be finished. We keep track of pending | 53 // Mark all pending requests to be finished. We keep track of pending |
| 49 // requests in |kPendingRequests|. | 54 // requests in |kPendingRequests|. |
| 50 static void FinishPendingRequests(); | 55 static void FinishPendingRequests(bool error); |
| 51 static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; | 56 static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; |
| 52 | 57 |
| 53 void StartAsync(); | 58 void StartAsync(); |
| 54 | 59 |
| 55 void set_should_finish_download() { should_finish_download_ = true; } | 60 void set_should_finish_download() { should_finish_download_ = true; } |
| 61 void set_should_error_download() { should_error_download_ = true; } |
| 56 | 62 |
| 57 int first_download_size_remaining_; | 63 int first_download_size_remaining_; |
| 58 bool should_finish_download_; | 64 bool should_finish_download_; |
| 59 bool should_send_second_chunk_; | 65 bool should_send_second_chunk_; |
| 66 bool should_error_download_; |
| 60 | 67 |
| 61 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; | 68 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; |
| 62 }; | 69 }; |
| 63 | 70 |
| 64 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 71 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| OLD | NEW |