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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 if (first_download_size_remaining_ > 0) { | 95 if (first_download_size_remaining_ > 0) { |
96 int send_size = std::min(first_download_size_remaining_, buf_size); | 96 int send_size = std::min(first_download_size_remaining_, buf_size); |
97 for (int i = 0; i < send_size; ++i) { | 97 for (int i = 0; i < send_size; ++i) { |
98 buf->data()[i] = '*'; | 98 buf->data()[i] = '*'; |
99 } | 99 } |
100 *bytes_read = send_size; | 100 *bytes_read = send_size; |
101 first_download_size_remaining_ -= send_size; | 101 first_download_size_remaining_ -= send_size; |
102 | 102 |
103 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
104 DCHECK(!is_done()); | 103 DCHECK(!is_done()); |
105 return true; | 104 return true; |
106 } | 105 } |
107 | 106 |
108 if (should_finish_download_) { | 107 if (should_finish_download_) { |
109 *bytes_read = 0; | 108 *bytes_read = 0; |
110 return true; | 109 return true; |
111 } | 110 } |
112 | 111 |
113 // If we make it here, the first chunk has been sent and we need to wait | 112 // If we make it here, the first chunk has been sent and we need to wait |
114 // until a request is made for kFinishDownloadUrl. | 113 // until a request is made for kFinishDownloadUrl. |
| 114 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
115 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 115 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
116 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); | 116 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); |
117 AddRef(); | 117 AddRef(); |
118 | 118 |
119 // Return false to signal there is pending data. | 119 // Return false to signal there is pending data. |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 void URLRequestSlowDownloadJob::CheckDoneStatus() { | 123 void URLRequestSlowDownloadJob::CheckDoneStatus() { |
124 if (should_finish_download_) { | 124 if (should_finish_download_) { |
(...skipping 38 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 |