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

Side by Side Diff: chrome_frame/urlmon_upload_data_stream.cc

Issue 6357017: Add support for chunked encoding in ChromeFrame for POST requests. This fixes... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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 #include "net/base/net_errors.h"
9 9
10 void UrlmonUploadDataStream::Initialize(net::UploadData* upload_data) { 10 void UrlmonUploadDataStream::Initialize(net::UploadData* upload_data) {
11 upload_data_ = upload_data; 11 upload_data_ = upload_data;
12 request_body_stream_.reset(net::UploadDataStream::Create(upload_data, NULL)); 12 request_body_stream_.reset(net::UploadDataStream::Create(upload_data, NULL));
13 DCHECK(request_body_stream_.get()); 13 DCHECK(request_body_stream_.get());
14 } 14 }
15 15
16 STDMETHODIMP UrlmonUploadDataStream::Read(void* pv, ULONG cb, ULONG* read) { 16 STDMETHODIMP UrlmonUploadDataStream::Read(void* pv, ULONG cb, ULONG* read) {
17 if (pv == NULL) { 17 if (pv == NULL) {
18 NOTREACHED(); 18 NOTREACHED();
19 return E_POINTER; 19 return E_POINTER;
20 } 20 }
21 21
22 // Have we already read past the end of the stream? 22 // Have we already read past the end of the stream?
23 if (request_body_stream_->position() >= request_body_stream_->size()) { 23 if (request_body_stream_->eof()) {
24 if (read) { 24 if (read) {
25 *read = 0; 25 *read = 0;
26 } 26 }
27 return S_FALSE; 27 return S_FALSE;
28 } 28 }
29 29
30 uint64 total_bytes_to_copy = std::min(static_cast<uint64>(cb), 30 uint64 total_bytes_to_copy = std::min(static_cast<uint64>(cb),
31 request_body_stream_->size() - request_body_stream_->position()); 31 static_cast<uint64>(request_body_stream_->buf_len()));
amit 2011/01/26 21:42:24 if bug_len is ULONG you can remove both 'static_ca
ananta 2011/01/26 22:19:58 Leaving this as is as per our discussion.
32 uint64 initial_position = request_body_stream_->position();
33 32
34 uint64 bytes_copied = 0; 33 uint64 bytes_copied = 0;
35 34
36 char* write_pointer = reinterpret_cast<char*>(pv); 35 char* write_pointer = reinterpret_cast<char*>(pv);
37 while (bytes_copied < total_bytes_to_copy) { 36 while (bytes_copied < total_bytes_to_copy) {
38 net::IOBuffer* buf = request_body_stream_->buf(); 37 net::IOBuffer* buf = request_body_stream_->buf();
39 38
40 // Make sure our length doesn't run past the end of the available data. 39 // Make sure our length doesn't run past the end of the available data.
41 size_t bytes_to_copy_now = static_cast<size_t>( 40 size_t bytes_to_copy_now = static_cast<size_t>(
42 std::min(static_cast<uint64>(request_body_stream_->buf_len()), 41 std::min(static_cast<uint64>(request_body_stream_->buf_len()),
43 total_bytes_to_copy - bytes_copied)); 42 total_bytes_to_copy - bytes_copied));
44 43
45 memcpy(write_pointer, buf->data(), bytes_to_copy_now); 44 memcpy(write_pointer, buf->data(), bytes_to_copy_now);
46 45
47 // Advance our copy tally 46 // Advance our copy tally
48 bytes_copied += bytes_to_copy_now; 47 bytes_copied += bytes_to_copy_now;
49 48
50 // Advance our write pointer 49 // Advance our write pointer
51 write_pointer += bytes_to_copy_now; 50 write_pointer += bytes_to_copy_now;
52 51
53 // Advance the UploadDataStream read pointer: 52 // Advance the UploadDataStream read pointer:
54 request_body_stream_->MarkConsumedAndFillBuffer(bytes_to_copy_now); 53 request_body_stream_->MarkConsumedAndFillBuffer(bytes_to_copy_now);
55 } 54 }
56 55
57 DCHECK(bytes_copied == total_bytes_to_copy); 56 DCHECK(bytes_copied == total_bytes_to_copy);
58 DCHECK(request_body_stream_->position() ==
59 initial_position + total_bytes_to_copy);
60 57
61 if (read) { 58 if (read) {
62 *read = static_cast<ULONG>(total_bytes_to_copy); 59 *read = static_cast<ULONG>(total_bytes_to_copy);
63 } 60 }
64 61
65 return S_OK; 62 return S_OK;
66 } 63 }
67 64
68 STDMETHODIMP UrlmonUploadDataStream::Seek(LARGE_INTEGER move, DWORD origin, 65 STDMETHODIMP UrlmonUploadDataStream::Seek(LARGE_INTEGER move, DWORD origin,
69 ULARGE_INTEGER* new_pos) { 66 ULARGE_INTEGER* new_pos) {
(...skipping 24 matching lines...) Expand all
94 if (0 == (grf_stat_flag & STATFLAG_NONAME)) { 91 if (0 == (grf_stat_flag & STATFLAG_NONAME)) {
95 const wchar_t kStreamBuffer[] = L"PostStream"; 92 const wchar_t kStreamBuffer[] = L"PostStream";
96 stat_stg->pwcsName = 93 stat_stg->pwcsName =
97 static_cast<wchar_t*>(::CoTaskMemAlloc(sizeof(kStreamBuffer))); 94 static_cast<wchar_t*>(::CoTaskMemAlloc(sizeof(kStreamBuffer)));
98 lstrcpy(stat_stg->pwcsName, kStreamBuffer); 95 lstrcpy(stat_stg->pwcsName, kStreamBuffer);
99 } 96 }
100 stat_stg->type = STGTY_STREAM; 97 stat_stg->type = STGTY_STREAM;
101 stat_stg->cbSize.QuadPart = upload_data_->GetContentLength(); 98 stat_stg->cbSize.QuadPart = upload_data_->GetContentLength();
102 return S_OK; 99 return S_OK;
103 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698