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 | 4 |
5 #include "chrome/browser/net/url_request_slow_download_job.h" | 5 #include "chrome/browser/net/url_request_slow_download_job.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 URLRequestFilter* filter = URLRequestFilter::GetInstance(); | 35 URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
36 filter->AddUrlHandler(GURL(kUnknownSizeUrl), | 36 filter->AddUrlHandler(GURL(kUnknownSizeUrl), |
37 &URLRequestSlowDownloadJob::Factory); | 37 &URLRequestSlowDownloadJob::Factory); |
38 filter->AddUrlHandler(GURL(kKnownSizeUrl), | 38 filter->AddUrlHandler(GURL(kKnownSizeUrl), |
39 &URLRequestSlowDownloadJob::Factory); | 39 &URLRequestSlowDownloadJob::Factory); |
40 filter->AddUrlHandler(GURL(kFinishDownloadUrl), | 40 filter->AddUrlHandler(GURL(kFinishDownloadUrl), |
41 &URLRequestSlowDownloadJob::Factory); | 41 &URLRequestSlowDownloadJob::Factory); |
42 } | 42 } |
43 | 43 |
44 /*static */ | 44 /*static */ |
45 URLRequestJob* URLRequestSlowDownloadJob::Factory(URLRequest* request, | 45 URLRequestJob* URLRequestSlowDownloadJob::Factory(net::URLRequest* request, |
46 const std::string& scheme) { | 46 const std::string& scheme) { |
47 URLRequestSlowDownloadJob* job = new URLRequestSlowDownloadJob(request); | 47 URLRequestSlowDownloadJob* job = new URLRequestSlowDownloadJob(request); |
48 if (request->url().spec() != kFinishDownloadUrl) | 48 if (request->url().spec() != kFinishDownloadUrl) |
49 URLRequestSlowDownloadJob::kPendingRequests.push_back(job); | 49 URLRequestSlowDownloadJob::kPendingRequests.push_back(job); |
50 return job; | 50 return job; |
51 } | 51 } |
52 | 52 |
53 /* static */ | 53 /* static */ |
54 void URLRequestSlowDownloadJob::FinishPendingRequests() { | 54 void URLRequestSlowDownloadJob::FinishPendingRequests() { |
55 typedef std::vector<URLRequestSlowDownloadJob*> JobList; | 55 typedef std::vector<URLRequestSlowDownloadJob*> JobList; |
56 for (JobList::iterator it = kPendingRequests.begin(); it != | 56 for (JobList::iterator it = kPendingRequests.begin(); it != |
57 kPendingRequests.end(); ++it) { | 57 kPendingRequests.end(); ++it) { |
58 (*it)->set_should_finish_download(); | 58 (*it)->set_should_finish_download(); |
59 } | 59 } |
60 kPendingRequests.clear(); | 60 kPendingRequests.clear(); |
61 } | 61 } |
62 | 62 |
63 URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(URLRequest* request) | 63 URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(net::URLRequest* request) |
64 : URLRequestJob(request), | 64 : URLRequestJob(request), |
65 first_download_size_remaining_(kFirstDownloadSize), | 65 first_download_size_remaining_(kFirstDownloadSize), |
66 should_finish_download_(false), | 66 should_finish_download_(false), |
67 should_send_second_chunk_(false) { | 67 should_send_second_chunk_(false) { |
68 } | 68 } |
69 | 69 |
70 void URLRequestSlowDownloadJob::StartAsync() { | 70 void URLRequestSlowDownloadJob::StartAsync() { |
71 if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str())) | 71 if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str())) |
72 URLRequestSlowDownloadJob::FinishPendingRequests(); | 72 URLRequestSlowDownloadJob::FinishPendingRequests(); |
73 | 73 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // ParseRawHeaders expects \0 to end each header line. | 163 // ParseRawHeaders expects \0 to end each header line. |
164 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 164 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
165 info->headers = new net::HttpResponseHeaders(raw_headers); | 165 info->headers = new net::HttpResponseHeaders(raw_headers); |
166 } | 166 } |
167 | 167 |
168 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { | 168 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { |
169 net::HttpResponseInfo info; | 169 net::HttpResponseInfo info; |
170 GetResponseInfoConst(&info); | 170 GetResponseInfoConst(&info); |
171 return info.headers && info.headers->GetMimeType(mime_type); | 171 return info.headers && info.headers->GetMimeType(mime_type); |
172 } | 172 } |
OLD | NEW |