OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 9 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
10 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 10 #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // not yet completed. | 48 // not yet completed. |
49 CONTENT_EXPORT static size_t NumberOutstandingRequests(); | 49 CONTENT_EXPORT static size_t NumberOutstandingRequests(); |
50 | 50 |
51 // Adds the testing URLs to the net::URLRequestFilter. | 51 // Adds the testing URLs to the net::URLRequestFilter. |
52 CONTENT_EXPORT static void AddUrlHandler(); | 52 CONTENT_EXPORT static void AddUrlHandler(); |
53 | 53 |
54 private: | 54 private: |
55 explicit URLRequestSlowDownloadJob(net::URLRequest* request); | 55 explicit URLRequestSlowDownloadJob(net::URLRequest* request); |
56 virtual ~URLRequestSlowDownloadJob(); | 56 virtual ~URLRequestSlowDownloadJob(); |
57 | 57 |
| 58 // Enum indicating where we are in the read after a call to |
| 59 // FillBufferHelper. |
| 60 enum ReadStatus { |
| 61 // The buffer was filled with data and may be returned. |
| 62 BUFFER_FILLED, |
| 63 |
| 64 // No data was added to the buffer because kFinishDownloadUrl has |
| 65 // not yet been seen and we've already returned the first chunk. |
| 66 REQUEST_BLOCKED, |
| 67 |
| 68 // No data was added to the buffer because we've already returned |
| 69 // all the data. |
| 70 REQUEST_COMPLETE |
| 71 }; |
| 72 ReadStatus FillBufferHelper( |
| 73 net::IOBuffer* buf, |
| 74 int buf_size, |
| 75 int* bytes_written); |
| 76 |
58 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 77 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
59 | 78 |
60 // Mark all pending requests to be finished. We keep track of pending | 79 // Mark all pending requests to be finished. We keep track of pending |
61 // requests in |pending_requests_|. | 80 // requests in |pending_requests_|. |
62 static void FinishPendingRequests(); | 81 static void FinishPendingRequests(); |
63 typedef std::set<URLRequestSlowDownloadJob*> SlowJobsSet; | 82 typedef std::set<URLRequestSlowDownloadJob*> SlowJobsSet; |
64 static base::LazyInstance<SlowJobsSet, | 83 static base::LazyInstance<SlowJobsSet, |
65 base::LeakyLazyInstanceTraits<SlowJobsSet> > | 84 base::LeakyLazyInstanceTraits<SlowJobsSet> > |
66 pending_requests_; | 85 pending_requests_; |
67 | 86 |
68 void StartAsync(); | 87 void StartAsync(); |
69 | 88 |
70 void set_should_finish_download() { should_finish_download_ = true; } | 89 void set_should_finish_download() { should_finish_download_ = true; } |
71 | 90 |
72 int first_download_size_remaining_; | 91 int bytes_already_sent_; |
73 bool should_finish_download_; | 92 bool should_finish_download_; |
74 scoped_refptr<net::IOBuffer> buffer_; | 93 scoped_refptr<net::IOBuffer> buffer_; |
75 int buffer_size_; | 94 int buffer_size_; |
76 | 95 |
77 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; | 96 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; |
78 }; | 97 }; |
79 | 98 |
80 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 99 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
OLD | NEW |