Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: webkit/fileapi/file_writer_delegate.cc

Issue 9007055: Check response code before writing blob to file. (Closed) Base URL: git://localhost/chromium.git@master
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4
5 #include "webkit/fileapi/file_writer_delegate.h" 5 #include "webkit/fileapi/file_writer_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 bool is_hsts_host) { 162 bool is_hsts_host) {
163 NOTREACHED(); 163 NOTREACHED();
164 OnError(base::PLATFORM_FILE_ERROR_SECURITY); 164 OnError(base::PLATFORM_FILE_ERROR_SECURITY);
165 } 165 }
166 166
167 void FileWriterDelegate::OnResponseStarted(net::URLRequest* request) { 167 void FileWriterDelegate::OnResponseStarted(net::URLRequest* request) {
168 DCHECK_EQ(request_, request); 168 DCHECK_EQ(request_, request);
169 // file_stream_->Seek() blocks the IO thread. 169 // file_stream_->Seek() blocks the IO thread.
170 // See http://crbug.com/75548. 170 // See http://crbug.com/75548.
171 base::ThreadRestrictions::ScopedAllowIO allow_io; 171 base::ThreadRestrictions::ScopedAllowIO allow_io;
172 if (!request->status().is_success()) { 172 if (!request->status().is_success() || request->GetResponseCode() != 200) {
ericu 2012/01/05 05:47:20 Why is is_success true here, if the blob wasn't va
tzik 2012/01/05 06:59:45 Looking at other use of URLRequestStatus, !is_succ
173 OnError(base::PLATFORM_FILE_ERROR_FAILED); 173 OnError(base::PLATFORM_FILE_ERROR_FAILED);
174 return; 174 return;
175 } 175 }
176 int64 error = file_stream_->Seek(net::FROM_BEGIN, offset_); 176 int64 error = file_stream_->Seek(net::FROM_BEGIN, offset_);
177 if (error != offset_) { 177 if (error != offset_) {
178 OnError(base::PLATFORM_FILE_ERROR_FAILED); 178 OnError(base::PLATFORM_FILE_ERROR_FAILED);
179 return; 179 return;
180 } 180 }
181 Read(); 181 Read();
182 } 182 }
183 183
184 void FileWriterDelegate::OnReadCompleted(net::URLRequest* request, 184 void FileWriterDelegate::OnReadCompleted(net::URLRequest* request,
185 int bytes_read) { 185 int bytes_read) {
186 DCHECK_EQ(request_, request); 186 DCHECK_EQ(request_, request);
187 if (!request->status().is_success()) { 187 if (!request->status().is_success()) {
ericu 2012/01/05 05:47:20 Is it possible to get is_success == true, but requ
tzik 2012/01/05 06:59:45 The response code is invariant after header of the
188 OnError(base::PLATFORM_FILE_ERROR_FAILED); 188 OnError(base::PLATFORM_FILE_ERROR_FAILED);
189 return; 189 return;
190 } 190 }
191 OnDataReceived(bytes_read); 191 OnDataReceived(bytes_read);
192 } 192 }
193 193
194 void FileWriterDelegate::Read() { 194 void FileWriterDelegate::Read() {
195 bytes_written_ = 0; 195 bytes_written_ = 0;
196 bytes_read_ = 0; 196 bytes_read_ = 0;
197 if (request_->Read(io_buffer_.get(), io_buffer_->size(), &bytes_read_)) { 197 if (request_->Read(io_buffer_.get(), io_buffer_->size(), &bytes_read_)) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 FileSystemQuotaUtil* FileWriterDelegate::quota_util() const { 319 FileSystemQuotaUtil* FileWriterDelegate::quota_util() const {
320 DCHECK(file_system_operation_); 320 DCHECK(file_system_operation_);
321 DCHECK(file_system_operation_->file_system_context()); 321 DCHECK(file_system_operation_->file_system_context());
322 DCHECK(file_system_operation_->file_system_operation_context()); 322 DCHECK(file_system_operation_->file_system_operation_context());
323 return file_system_operation_->file_system_context()->GetQuotaUtil( 323 return file_system_operation_->file_system_context()->GetQuotaUtil(
324 file_system_operation_context()->src_type()); 324 file_system_operation_context()->src_type());
325 } 325 }
326 326
327 } // namespace fileapi 327 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation_write_unittest.cc ('k') | webkit/fileapi/file_writer_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698