| 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_ |
| 11 | 11 |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "net/url_request/url_request_job.h" | 17 #include "net/url_request/url_request_job.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class URLRequestSlowDownloadJob : public net::URLRequestJob { | 21 class URLRequestSlowDownloadJob : public net::URLRequestJob { |
| 22 public: | 22 public: |
| 23 // Test URLs. | 23 // Test URLs. |
| 24 static const char kUnknownSizeUrl[]; | 24 static const char kUnknownSizeUrl[]; |
| 25 static const char kKnownSizeUrl[]; | 25 static const char kKnownSizeUrl[]; |
| 26 static const char kFinishDownloadUrl[]; | 26 static const char kFinishDownloadUrl[]; |
| 27 static const char kErrorDownloadUrl[]; |
| 27 | 28 |
| 28 // Download sizes. | 29 // Download sizes. |
| 29 static const int kFirstDownloadSize; | 30 static const int kFirstDownloadSize; |
| 30 static const int kSecondDownloadSize; | 31 static const int kSecondDownloadSize; |
| 31 | 32 |
| 32 // Timer callback, used to check to see if we should finish our download and | 33 // Timer callback, used to check to see if we should finish our download and |
| 33 // send the second chunk. | 34 // send the second chunk. |
| 34 void CheckDoneStatus(); | 35 void CheckDoneStatus(); |
| 35 | 36 |
| 36 // net::URLRequestJob methods | 37 // net::URLRequestJob methods |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 ReadStatus FillBufferHelper( | 75 ReadStatus FillBufferHelper( |
| 75 net::IOBuffer* buf, | 76 net::IOBuffer* buf, |
| 76 int buf_size, | 77 int buf_size, |
| 77 int* bytes_written); | 78 int* bytes_written); |
| 78 | 79 |
| 79 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 80 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
| 80 | 81 |
| 81 // Mark all pending requests to be finished. We keep track of pending | 82 // Mark all pending requests to be finished. We keep track of pending |
| 82 // requests in |pending_requests_|. | 83 // requests in |pending_requests_|. |
| 83 static void FinishPendingRequests(); | 84 static void FinishPendingRequests(); |
| 85 static void ErrorPendingRequests(); |
| 84 typedef std::set<URLRequestSlowDownloadJob*> SlowJobsSet; | 86 typedef std::set<URLRequestSlowDownloadJob*> SlowJobsSet; |
| 85 static base::LazyInstance<SlowJobsSet>::Leaky pending_requests_; | 87 static base::LazyInstance<SlowJobsSet>::Leaky pending_requests_; |
| 86 | 88 |
| 87 void StartAsync(); | 89 void StartAsync(); |
| 88 | 90 |
| 89 void set_should_finish_download() { should_finish_download_ = true; } | 91 void set_should_finish_download() { should_finish_download_ = true; } |
| 92 void set_should_error_download() { should_error_download_ = true; } |
| 90 | 93 |
| 91 int bytes_already_sent_; | 94 int bytes_already_sent_; |
| 95 bool should_error_download_; |
| 92 bool should_finish_download_; | 96 bool should_finish_download_; |
| 93 scoped_refptr<net::IOBuffer> buffer_; | 97 scoped_refptr<net::IOBuffer> buffer_; |
| 94 int buffer_size_; | 98 int buffer_size_; |
| 95 | 99 |
| 96 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; | 100 base::WeakPtrFactory<URLRequestSlowDownloadJob> weak_factory_; |
| 97 }; | 101 }; |
| 98 | 102 |
| 99 } // namespace content | 103 } // namespace content |
| 100 | 104 |
| 101 #endif // CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 105 #endif // CONTENT_TEST_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| OLD | NEW |