| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 N bytes, to be completed by sending a | 6 // downloads that pause after the first N bytes, to be completed by sending a |
| 7 // request to |kFinishDownloadUrl|. | 7 // request to |kFinishDownloadUrl|. |
| 8 | 8 |
| 9 #ifndef CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 9 #ifndef CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| 10 #define CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 10 #define CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // net::URLRequestJob methods | 34 // net::URLRequestJob methods |
| 35 virtual void Start() OVERRIDE; | 35 virtual void Start() OVERRIDE; |
| 36 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 36 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 37 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; | 37 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE; |
| 38 virtual bool ReadRawData(net::IOBuffer* buf, | 38 virtual bool ReadRawData(net::IOBuffer* buf, |
| 39 int buf_size, | 39 int buf_size, |
| 40 int *bytes_read) OVERRIDE; | 40 int *bytes_read) OVERRIDE; |
| 41 | 41 |
| 42 static net::URLRequestJob* Factory(net::URLRequest* request, | 42 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 43 net::NetworkDelegate* network_delegate, |
| 43 const std::string& scheme); | 44 const std::string& scheme); |
| 44 | 45 |
| 45 // Returns the current number of URLRequestSlowDownloadJobs that have | 46 // Returns the current number of URLRequestSlowDownloadJobs that have |
| 46 // not yet completed. | 47 // not yet completed. |
| 47 static size_t NumberOutstandingRequests(); | 48 static size_t NumberOutstandingRequests(); |
| 48 | 49 |
| 49 // Adds the testing URLs to the net::URLRequestFilter. | 50 // Adds the testing URLs to the net::URLRequestFilter. |
| 50 static void AddUrlHandler(); | 51 static void AddUrlHandler(); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 explicit URLRequestSlowDownloadJob(net::URLRequest* request); | 54 URLRequestSlowDownloadJob(net::URLRequest* request, |
| 55 net::NetworkDelegate* network_delegate); |
| 54 virtual ~URLRequestSlowDownloadJob(); | 56 virtual ~URLRequestSlowDownloadJob(); |
| 55 | 57 |
| 56 // Enum indicating where we are in the read after a call to | 58 // Enum indicating where we are in the read after a call to |
| 57 // FillBufferHelper. | 59 // FillBufferHelper. |
| 58 enum ReadStatus { | 60 enum ReadStatus { |
| 59 // The buffer was filled with data and may be returned. | 61 // The buffer was filled with data and may be returned. |
| 60 BUFFER_FILLED, | 62 BUFFER_FILLED, |
| 61 | 63 |
| 62 // No data was added to the buffer because kFinishDownloadUrl has | 64 // No data was added to the buffer because kFinishDownloadUrl has |
| 63 // not yet been seen and we've already returned the first chunk. | 65 // not yet been seen and we've already returned the first chunk. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 | 88 |
| 87 int bytes_already_sent_; | 89 int bytes_already_sent_; |
| 88 bool should_finish_download_; | 90 bool should_finish_download_; |
| 89 scoped_refptr<net::IOBuffer> buffer_; | 91 scoped_refptr<net::IOBuffer> buffer_; |
| 90 int buffer_size_; | 92 int buffer_size_; |
| 91 | 93 |
| 92 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; | 94 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 #endif // CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 97 #endif // CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| OLD | NEW |