Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/resource_request_body.h" | 5 #include "content/common/resource_request_body.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "content/common/page_state_serialization.h" | |
| 9 | |
| 10 using blink::WebHTTPBody; | |
| 11 using blink::WebString; | |
| 12 | |
| 7 namespace content { | 13 namespace content { |
| 8 | 14 |
| 9 ResourceRequestBody::ResourceRequestBody() | 15 ResourceRequestBody::ResourceRequestBody() |
| 10 : identifier_(0) { | 16 : identifier_(0) { |
| 11 } | 17 } |
| 12 | 18 |
| 19 void ResourceRequestBody::AppendExplodedHTTPBodyElement( | |
| 20 const ExplodedHttpBodyElement& element) { | |
| 21 switch (element.type) { | |
| 22 case WebHTTPBody::Element::TypeData: | |
| 23 if (!element.data.empty()) { | |
| 24 // Blink sometimes gives empty data to append. These aren't | |
| 25 // necessary so they are just optimized out here. | |
| 26 AppendBytes(element.data.data(), static_cast<int>(element.data.size())); | |
|
Łukasz Anforowicz
2016/05/12 02:53:59
It is not immediately clear why size_t -> int cast
clamy
2016/05/12 08:53:13
This whole method is a copy of what we do to conve
Łukasz Anforowicz
2016/05/12 19:44:12
It is pretty sad that we have to repeat almost the
Charlie Reis
2016/05/16 21:16:42
Please add a comment above this method indicating
clamy
2016/05/19 13:11:57
Done.
| |
| 27 } | |
| 28 break; | |
| 29 case WebHTTPBody::Element::TypeFile: | |
| 30 if (element.file_length == -1) { | |
| 31 AppendFileRange( | |
| 32 base::FilePath::FromUTF16Unsafe(element.file_path.string()), 0, | |
| 33 std::numeric_limits<uint64_t>::max(), base::Time()); | |
|
Łukasz Anforowicz
2016/05/12 02:53:59
I see that UploadFileElementReader::OnGetFileInfoC
clamy
2016/05/12 08:53:13
Possibly? As explained above, I'm just copy pastin
Łukasz Anforowicz
2016/05/12 19:44:12
Acknowledged.
| |
| 34 } else { | |
| 35 AppendFileRange( | |
| 36 base::FilePath::FromUTF16Unsafe(element.file_path.string()), | |
| 37 static_cast<uint64_t>(element.file_start), | |
| 38 static_cast<uint64_t>(element.file_length), | |
| 39 base::Time::FromDoubleT(element.file_modification_time)); | |
|
Łukasz Anforowicz
2016/05/12 02:53:59
Just wanted to double-check - is it okay to use ba
clamy
2016/05/12 08:53:13
Again I imagine it's ok since we've been doing it.
Łukasz Anforowicz
2016/05/12 19:44:12
Acknowledged.
Charlie Reis
2016/05/16 21:16:41
In general, copy/pasting code isn't an excuse for
Łukasz Anforowicz
2016/05/18 00:22:27
I wonder if we could avoid copy&pasted conversion
clamy
2016/05/19 13:11:57
So I did a bit of code archeology, and the time pa
Charlie Reis
2016/05/19 17:43:48
Agreed. Since we aren't certain there's a bug her
| |
| 40 } | |
| 41 break; | |
| 42 case WebHTTPBody::Element::TypeFileSystemURL: { | |
| 43 GURL file_system_url = element.filesystem_url; | |
| 44 DCHECK(file_system_url.SchemeIsFileSystem()); | |
|
Łukasz Anforowicz
2016/05/12 02:53:59
I guess a DCHECK is sufficient, because UploadFile
clamy
2016/05/12 08:53:13
I imagine. I don't know if we want to crash the re
Łukasz Anforowicz
2016/05/12 19:44:12
Acknowledged.
| |
| 45 AppendFileSystemFileRange( | |
| 46 file_system_url, static_cast<uint64_t>(element.file_start), | |
| 47 static_cast<uint64_t>(element.file_length), | |
| 48 base::Time::FromDoubleT(element.file_modification_time)); | |
| 49 break; | |
| 50 } | |
| 51 case WebHTTPBody::Element::TypeBlob: | |
| 52 AppendBlob(element.blob_uuid); | |
| 53 break; | |
| 54 default: | |
| 55 NOTREACHED(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 13 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { | 59 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
| 14 if (bytes_len > 0) { | 60 if (bytes_len > 0) { |
| 15 elements_.push_back(Element()); | 61 elements_.push_back(Element()); |
| 16 elements_.back().SetToBytes(bytes, bytes_len); | 62 elements_.back().SetToBytes(bytes, bytes_len); |
| 17 } | 63 } |
| 18 } | 64 } |
| 19 | 65 |
| 20 void ResourceRequestBody::AppendFileRange( | 66 void ResourceRequestBody::AppendFileRange( |
| 21 const base::FilePath& file_path, | 67 const base::FilePath& file_path, |
| 22 uint64_t offset, | 68 uint64_t offset, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 35 void ResourceRequestBody::AppendFileSystemFileRange( | 81 void ResourceRequestBody::AppendFileSystemFileRange( |
| 36 const GURL& url, | 82 const GURL& url, |
| 37 uint64_t offset, | 83 uint64_t offset, |
| 38 uint64_t length, | 84 uint64_t length, |
| 39 const base::Time& expected_modification_time) { | 85 const base::Time& expected_modification_time) { |
| 40 elements_.push_back(Element()); | 86 elements_.push_back(Element()); |
| 41 elements_.back().SetToFileSystemUrlRange(url, offset, length, | 87 elements_.back().SetToFileSystemUrlRange(url, offset, length, |
| 42 expected_modification_time); | 88 expected_modification_time); |
| 43 } | 89 } |
| 44 | 90 |
| 91 scoped_refptr<ResourceRequestBody> ResourceRequestBody::MakeCopy() { | |
| 92 scoped_refptr<ResourceRequestBody> copy = new ResourceRequestBody(); | |
| 93 copy->set_identifier(identifier_); | |
| 94 for (auto element : elements_) | |
| 95 copy->elements_mutable()->push_back(element); | |
| 96 return copy; | |
| 97 } | |
| 98 | |
| 45 ResourceRequestBody::~ResourceRequestBody() { | 99 ResourceRequestBody::~ResourceRequestBody() { |
| 46 } | 100 } |
| 47 | 101 |
| 48 } // namespace content | 102 } // namespace content |
| OLD | NEW |