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: net/base/upload_data.cc

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear 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
« no previous file with comments | « no previous file | net/base/upload_data_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/base/upload_data.h" 5 #include "net/base/upload_data.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/file_stream.h" 10 #include "net/base/file_stream.h"
(...skipping 10 matching lines...) Expand all
21 content_length_computed_(false), 21 content_length_computed_(false),
22 content_length_(-1), 22 content_length_(-1),
23 file_stream_(NULL) { 23 file_stream_(NULL) {
24 } 24 }
25 25
26 UploadData::Element::~Element() { 26 UploadData::Element::~Element() {
27 // In the common case |file__stream_| will be null. 27 // In the common case |file__stream_| will be null.
28 delete file_stream_; 28 delete file_stream_;
29 } 29 }
30 30
31 void UploadData::Element::SetToChunk(const char* bytes, int bytes_len) {
32 std::string chunk_length = StringPrintf("%X\r\n", bytes_len);
33 bytes_.clear();
34 bytes_.insert(bytes_.end(), chunk_length.data(),
35 chunk_length.data() + chunk_length.length());
36 bytes_.insert(bytes_.end(), bytes, bytes + bytes_len);
37 const char* crlf = "\r\n";
38 bytes_.insert(bytes_.end(), crlf, crlf + 2);
39 type_ = TYPE_CHUNK;
40 is_last_chunk_ = (bytes_len == 0);
41 }
42
31 uint64 UploadData::Element::GetContentLength() { 43 uint64 UploadData::Element::GetContentLength() {
32 if (override_content_length_ || content_length_computed_) 44 if (override_content_length_ || content_length_computed_)
33 return content_length_; 45 return content_length_;
34 46
35 if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK) 47 if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK)
36 return static_cast<uint64>(bytes_.size()); 48 return static_cast<uint64>(bytes_.size());
37 else if (type_ == TYPE_BLOB) 49 else if (type_ == TYPE_BLOB)
38 // The blob reference will be resolved later. 50 // The blob reference will be resolved later.
39 return 0; 51 return 0;
40 52
(...skipping 19 matching lines...) Expand all
60 return 0; 72 return 0;
61 73
62 if (file_range_offset_ >= static_cast<uint64>(length)) 74 if (file_range_offset_ >= static_cast<uint64>(length))
63 return 0; // range is beyond eof 75 return 0; // range is beyond eof
64 76
65 // compensate for the offset and clip file_range_length_ to eof 77 // compensate for the offset and clip file_range_length_ to eof
66 content_length_ = std::min(length - file_range_offset_, file_range_length_); 78 content_length_ = std::min(length - file_range_offset_, file_range_length_);
67 return content_length_; 79 return content_length_;
68 } 80 }
69 81
70 void UploadData::Element::SetToChunk(const char* bytes, int bytes_len) {
71 std::string chunk_length = StringPrintf("%X\r\n", bytes_len);
72 bytes_.clear();
73 bytes_.insert(bytes_.end(), chunk_length.data(),
74 chunk_length.data() + chunk_length.length());
75 bytes_.insert(bytes_.end(), bytes, bytes + bytes_len);
76 const char* crlf = "\r\n";
77 bytes_.insert(bytes_.end(), crlf, crlf + 2);
78 type_ = TYPE_CHUNK;
79 is_last_chunk_ = (bytes_len == 0);
80 }
81
82 FileStream* UploadData::Element::NewFileStreamForReading() { 82 FileStream* UploadData::Element::NewFileStreamForReading() {
83 // In common usage GetContentLength() will call this first and store the 83 // In common usage GetContentLength() will call this first and store the
84 // result into |file_| and a subsequent call (from UploadDataStream) will 84 // result into |file_| and a subsequent call (from UploadDataStream) will
85 // get the cached open FileStream. 85 // get the cached open FileStream.
86 if (file_stream_) { 86 if (file_stream_) {
87 FileStream* file = file_stream_; 87 FileStream* file = file_stream_;
88 file_stream_ = NULL; 88 file_stream_ = NULL;
89 return file; 89 return file;
90 } 90 }
91 91
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 void UploadData::SetElements(const std::vector<Element>& elements) { 170 void UploadData::SetElements(const std::vector<Element>& elements) {
171 elements_ = elements; 171 elements_ = elements;
172 } 172 }
173 173
174 UploadData::~UploadData() { 174 UploadData::~UploadData() {
175 } 175 }
176 176
177 } // namespace net 177 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/upload_data_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698