| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_frame/urlmon_upload_data_stream.h" | 5 #include "chrome_frame/urlmon_upload_data_stream.h" |
| 6 | 6 |
| 7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 #include "net/base/net_errors.h" |
| 8 | 9 |
| 9 void UrlmonUploadDataStream::Initialize(net::UploadData* upload_data) { | 10 void UrlmonUploadDataStream::Initialize(net::UploadData* upload_data) { |
| 10 upload_data_ = upload_data; | 11 upload_data_ = upload_data; |
| 11 request_body_stream_.reset(new net::UploadDataStream(upload_data)); | 12 request_body_stream_.reset(net::UploadDataStream::Create(upload_data, NULL)); |
| 13 DCHECK(request_body_stream_.get()); |
| 12 } | 14 } |
| 13 | 15 |
| 14 STDMETHODIMP UrlmonUploadDataStream::Read(void* pv, ULONG cb, ULONG* read) { | 16 STDMETHODIMP UrlmonUploadDataStream::Read(void* pv, ULONG cb, ULONG* read) { |
| 15 if (pv == NULL) { | 17 if (pv == NULL) { |
| 16 NOTREACHED(); | 18 NOTREACHED(); |
| 17 return E_POINTER; | 19 return E_POINTER; |
| 18 } | 20 } |
| 19 | 21 |
| 20 // Have we already read past the end of the stream? | 22 // Have we already read past the end of the stream? |
| 21 if (request_body_stream_->position() >= request_body_stream_->size()) { | 23 if (request_body_stream_->position() >= request_body_stream_->size()) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 64 |
| 63 return S_OK; | 65 return S_OK; |
| 64 } | 66 } |
| 65 | 67 |
| 66 STDMETHODIMP UrlmonUploadDataStream::Seek(LARGE_INTEGER move, DWORD origin, | 68 STDMETHODIMP UrlmonUploadDataStream::Seek(LARGE_INTEGER move, DWORD origin, |
| 67 ULARGE_INTEGER* new_pos) { | 69 ULARGE_INTEGER* new_pos) { |
| 68 // UploadDataStream is really not very seek-able, so for now allow | 70 // UploadDataStream is really not very seek-able, so for now allow |
| 69 // STREAM_SEEK_SETs to work with a 0 offset, but fail on everything else. | 71 // STREAM_SEEK_SETs to work with a 0 offset, but fail on everything else. |
| 70 if (origin == STREAM_SEEK_SET && move.QuadPart == 0) { | 72 if (origin == STREAM_SEEK_SET && move.QuadPart == 0) { |
| 71 if (request_body_stream_->position() != 0) { | 73 if (request_body_stream_->position() != 0) { |
| 72 request_body_stream_.reset(new net::UploadDataStream(upload_data_)); | 74 request_body_stream_.reset( |
| 75 net::UploadDataStream::Create(upload_data_, NULL)); |
| 76 DCHECK(request_body_stream_.get()); |
| 73 } | 77 } |
| 74 if (new_pos) { | 78 if (new_pos) { |
| 75 new_pos->QuadPart = 0; | 79 new_pos->QuadPart = 0; |
| 76 } | 80 } |
| 77 return S_OK; | 81 return S_OK; |
| 78 } | 82 } |
| 79 | 83 |
| 80 DCHECK(false) << __FUNCTION__; | 84 DCHECK(false) << __FUNCTION__; |
| 81 return STG_E_INVALIDFUNCTION; | 85 return STG_E_INVALIDFUNCTION; |
| 82 } | 86 } |
| 83 | 87 |
| 84 STDMETHODIMP UrlmonUploadDataStream::Stat(STATSTG *stat_stg, | 88 STDMETHODIMP UrlmonUploadDataStream::Stat(STATSTG *stat_stg, |
| 85 DWORD grf_stat_flag) { | 89 DWORD grf_stat_flag) { |
| 86 if (stat_stg == NULL) | 90 if (stat_stg == NULL) |
| 87 return E_POINTER; | 91 return E_POINTER; |
| 88 | 92 |
| 89 memset(stat_stg, 0, sizeof(STATSTG)); | 93 memset(stat_stg, 0, sizeof(STATSTG)); |
| 90 if (0 == (grf_stat_flag & STATFLAG_NONAME)) { | 94 if (0 == (grf_stat_flag & STATFLAG_NONAME)) { |
| 91 const wchar_t kStreamBuffer[] = L"PostStream"; | 95 const wchar_t kStreamBuffer[] = L"PostStream"; |
| 92 stat_stg->pwcsName = | 96 stat_stg->pwcsName = |
| 93 static_cast<wchar_t*>(::CoTaskMemAlloc(sizeof(kStreamBuffer))); | 97 static_cast<wchar_t*>(::CoTaskMemAlloc(sizeof(kStreamBuffer))); |
| 94 lstrcpy(stat_stg->pwcsName, kStreamBuffer); | 98 lstrcpy(stat_stg->pwcsName, kStreamBuffer); |
| 95 } | 99 } |
| 96 stat_stg->type = STGTY_STREAM; | 100 stat_stg->type = STGTY_STREAM; |
| 97 stat_stg->cbSize.QuadPart = upload_data_->GetContentLength(); | 101 stat_stg->cbSize.QuadPart = upload_data_->GetContentLength(); |
| 98 return S_OK; | 102 return S_OK; |
| 99 } | 103 } |
| OLD | NEW |