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