OLD | NEW |
1 // Copyright (c) 2006-2008 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 | 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 if (should_finish_download_) { | 111 if (should_finish_download_) { |
112 *bytes_read = 0; | 112 *bytes_read = 0; |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 // If we make it here, the first chunk has been sent and we need to wait | 116 // If we make it here, the first chunk has been sent and we need to wait |
117 // until a request is made for kFinishDownloadUrl. | 117 // until a request is made for kFinishDownloadUrl. |
118 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 118 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
119 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 119 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
120 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); | 120 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); |
121 AddRef(); | 121 AddRef(); |
122 | 122 |
123 // Return false to signal there is pending data. | 123 // Return false to signal there is pending data. |
124 return false; | 124 return false; |
125 } | 125 } |
126 | 126 |
127 void URLRequestSlowDownloadJob::CheckDoneStatus() { | 127 void URLRequestSlowDownloadJob::CheckDoneStatus() { |
128 if (should_finish_download_) { | 128 if (should_finish_download_) { |
129 should_send_second_chunk_ = true; | 129 should_send_second_chunk_ = true; |
130 SetStatus(URLRequestStatus()); | 130 SetStatus(net::URLRequestStatus()); |
131 NotifyReadComplete(kSecondDownloadSize); | 131 NotifyReadComplete(kSecondDownloadSize); |
132 Release(); | 132 Release(); |
133 } else { | 133 } else { |
134 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 134 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
135 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); | 135 this, &URLRequestSlowDownloadJob::CheckDoneStatus), 100); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 // Public virtual version. | 139 // Public virtual version. |
140 void URLRequestSlowDownloadJob::GetResponseInfo(net::HttpResponseInfo* info) { | 140 void URLRequestSlowDownloadJob::GetResponseInfo(net::HttpResponseInfo* info) { |
(...skipping 28 matching lines...) Expand all Loading... |
169 // ParseRawHeaders expects \0 to end each header line. | 169 // ParseRawHeaders expects \0 to end each header line. |
170 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 170 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
171 info->headers = new net::HttpResponseHeaders(raw_headers); | 171 info->headers = new net::HttpResponseHeaders(raw_headers); |
172 } | 172 } |
173 | 173 |
174 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { | 174 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { |
175 net::HttpResponseInfo info; | 175 net::HttpResponseInfo info; |
176 GetResponseInfoConst(&info); | 176 GetResponseInfoConst(&info); |
177 return info.headers && info.headers->GetMimeType(mime_type); | 177 return info.headers && info.headers->GetMimeType(mime_type); |
178 } | 178 } |
OLD | NEW |