Chromium Code Reviews| 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_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/lazy_instance.h" | |
| 16 #include "base/task.h" | 17 #include "base/task.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "net/url_request/url_request_job.h" | 19 #include "net/url_request/url_request_job.h" |
| 19 | 20 |
| 20 class URLRequestSlowDownloadJob : public net::URLRequestJob { | 21 class URLRequestSlowDownloadJob : public net::URLRequestJob { |
| 21 public: | 22 public: |
| 22 // Test URLs. | 23 // Test URLs. |
| 23 CONTENT_EXPORT static const char kUnknownSizeUrl[]; | 24 CONTENT_EXPORT static const char kUnknownSizeUrl[]; |
| 24 CONTENT_EXPORT static const char kKnownSizeUrl[]; | 25 CONTENT_EXPORT static const char kKnownSizeUrl[]; |
| 25 CONTENT_EXPORT static const char kFinishDownloadUrl[]; | 26 CONTENT_EXPORT static const char kFinishDownloadUrl[]; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 explicit URLRequestSlowDownloadJob(net::URLRequest* request); | 53 explicit URLRequestSlowDownloadJob(net::URLRequest* request); |
| 53 virtual ~URLRequestSlowDownloadJob(); | 54 virtual ~URLRequestSlowDownloadJob(); |
| 54 | 55 |
| 55 void GetResponseInfoConst(net::HttpResponseInfo* info) const; | 56 void GetResponseInfoConst(net::HttpResponseInfo* info) const; |
| 56 | 57 |
| 57 // Mark all pending requests to be finished. We keep track of pending | 58 // Mark all pending requests to be finished. We keep track of pending |
| 58 // requests in |pending_requests_|. | 59 // requests in |pending_requests_|. |
| 59 static void FinishPendingRequests(); | 60 static void FinishPendingRequests(); |
| 60 static std::set<URLRequestSlowDownloadJob*> pending_requests_; | 61 typedef std::set<URLRequestSlowDownloadJob*> SlowJobsSet; |
| 62 static base::LazyInstance<SlowJobsSet, | |
|
Mark Mentovai
2011/11/07 22:34:15
private + static again.
Nico
2011/11/07 23:29:21
Since the comment for FinishPendingRequests() refe
| |
| 63 base::LeakyLazyInstanceTraits<SlowJobsSet> > | |
| 64 pending_requests_; | |
| 61 | 65 |
| 62 void StartAsync(); | 66 void StartAsync(); |
| 63 | 67 |
| 64 void set_should_finish_download() { should_finish_download_ = true; } | 68 void set_should_finish_download() { should_finish_download_ = true; } |
| 65 | 69 |
| 66 int first_download_size_remaining_; | 70 int first_download_size_remaining_; |
| 67 bool should_finish_download_; | 71 bool should_finish_download_; |
| 68 scoped_refptr<net::IOBuffer> buffer_; | 72 scoped_refptr<net::IOBuffer> buffer_; |
| 69 int buffer_size_; | 73 int buffer_size_; |
| 70 | 74 |
| 71 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; | 75 ScopedRunnableMethodFactory<URLRequestSlowDownloadJob> method_factory_; |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ | 78 #endif // CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ |
| OLD | NEW |