OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 |
7 | 7 |
8 #ifndef CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 8 #ifndef CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
9 #define CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 9 #define CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "net/url_request/url_request_job.h" | 15 #include "net/url_request/url_request_job.h" |
16 | 16 |
17 class URLRequestSlowDownloadJob : public URLRequestJob { | 17 class URLRequestSlowDownloadJob : public URLRequestJob { |
18 public: | 18 public: |
19 explicit URLRequestSlowDownloadJob(URLRequest* request); | 19 explicit URLRequestSlowDownloadJob(net::URLRequest* request); |
20 | 20 |
21 // Timer callback, used to check to see if we should finish our download and | 21 // Timer callback, used to check to see if we should finish our download and |
22 // send the second chunk. | 22 // send the second chunk. |
23 void CheckDoneStatus(); | 23 void CheckDoneStatus(); |
24 | 24 |
25 // URLRequestJob methods | 25 // URLRequestJob methods |
26 virtual void Start(); | 26 virtual void Start(); |
27 virtual bool GetMimeType(std::string* mime_type) const; | 27 virtual bool GetMimeType(std::string* mime_type) const; |
28 virtual void GetResponseInfo(net::HttpResponseInfo* info); | 28 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
29 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 29 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
30 | 30 |
31 static URLRequestJob* Factory(URLRequest* request, | 31 static net::URLRequestJob* Factory(net::URLRequest* request, |
32 const std::string& scheme); | 32 const std::string& scheme); |
33 | 33 |
34 // Test URLs. | 34 // Test URLs. |
35 static const char kUnknownSizeUrl[]; | 35 static const char kUnknownSizeUrl[]; |
36 static const char kKnownSizeUrl[]; | 36 static const char kKnownSizeUrl[]; |
37 static const char kFinishDownloadUrl[]; | 37 static const char kFinishDownloadUrl[]; |
38 | 38 |
39 // Adds the testing URLs to the URLRequestFilter. | 39 // Adds the testing URLs to the URLRequestFilter. |
40 static void AddUrlHandler(); | 40 static void AddUrlHandler(); |
41 | 41 |
42 private: | 42 private: |
43 virtual ~URLRequestSlowDownloadJob() { } | 43 virtual ~URLRequestSlowDownloadJob() { } |
44 | 44 |
45 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 45 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
46 | 46 |
47 // Mark all pending requests to be finished. We keep track of pending | 47 // Mark all pending requests to be finished. We keep track of pending |
48 // requests in |kPendingRequests|. | 48 // requests in |kPendingRequests|. |
49 static void FinishPendingRequests(); | 49 static void FinishPendingRequests(); |
50 static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; | 50 static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; |
51 | 51 |
52 void StartAsync(); | 52 void StartAsync(); |
53 | 53 |
54 void set_should_finish_download() { should_finish_download_ = true; } | 54 void set_should_finish_download() { should_finish_download_ = true; } |
55 | 55 |
56 int first_download_size_remaining_; | 56 int first_download_size_remaining_; |
57 bool should_finish_download_; | 57 bool should_finish_download_; |
58 bool should_send_second_chunk_; | 58 bool should_send_second_chunk_; |
59 }; | 59 }; |
60 | 60 |
61 #endif // CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 61 #endif // CHROME_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
OLD | NEW |