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

Side by Side Diff: content/common/page_state_serialization.cc

Issue 2002413002: Revert of Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/page_state_serialization.h" 5 #include "content/common/page_state_serialization.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/strings/nullable_string16.h"
14 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 #include "content/common/resource_request_body.h" 17 #include "content/common/resource_request_body.h"
19 #include "ui/display/display.h" 18 #include "ui/display/display.h"
20 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
21 20
22 namespace content { 21 namespace content {
23 namespace { 22 namespace {
24 23
25 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
26 float g_device_scale_factor_for_testing = 0.0; 25 float g_device_scale_factor_for_testing = 0.0;
27 #endif 26 #endif
28 27
29 //----------------------------------------------------------------------------- 28 //-----------------------------------------------------------------------------
30 29
31 void AppendDataToHttpBody(ExplodedHttpBody* http_body, const char* data, 30 void AppendDataToHttpBody(ExplodedHttpBody* http_body, const char* data,
32 int data_length) { 31 int data_length) {
33 ExplodedHttpBodyElement element; 32 ExplodedHttpBodyElement element;
34 element.SetToBytes(data, data_length); 33 element.type = blink::WebHTTPBody::Element::TypeData;
34 element.data.assign(data, data_length);
35 http_body->elements.push_back(element); 35 http_body->elements.push_back(element);
36 } 36 }
37 37
38 void AppendFileRangeToHttpBody(ExplodedHttpBody* http_body, 38 void AppendFileRangeToHttpBody(ExplodedHttpBody* http_body,
39 const base::NullableString16& file_path, 39 const base::NullableString16& file_path,
40 int file_start, 40 int file_start,
41 int file_length, 41 int file_length,
42 double file_modification_time) { 42 double file_modification_time) {
43 ExplodedHttpBodyElement element; 43 ExplodedHttpBodyElement element;
44 element.SetToFilePathRange( 44 element.type = blink::WebHTTPBody::Element::TypeFile;
45 base::FilePath::FromUTF16Unsafe(file_path.string()), 45 element.file_path = file_path;
46 static_cast<uint64_t>(file_start), static_cast<uint64_t>(file_length), 46 element.file_start = file_start;
47 base::Time::FromDoubleT(file_modification_time)); 47 element.file_length = file_length;
48 element.file_modification_time = file_modification_time;
48 http_body->elements.push_back(element); 49 http_body->elements.push_back(element);
49 } 50 }
50 51
51 void AppendURLRangeToHttpBody(ExplodedHttpBody* http_body, 52 void AppendURLRangeToHttpBody(ExplodedHttpBody* http_body,
52 const GURL& url, 53 const GURL& url,
53 int file_start, 54 int file_start,
54 int file_length, 55 int file_length,
55 double file_modification_time) { 56 double file_modification_time) {
56 ExplodedHttpBodyElement element; 57 ExplodedHttpBodyElement element;
57 element.SetToFileSystemUrlRange( 58 element.type = blink::WebHTTPBody::Element::TypeFileSystemURL;
58 url, static_cast<uint64_t>(file_start), 59 element.filesystem_url = url;
59 static_cast<uint64_t>(file_length), 60 element.file_start = file_start;
60 base::Time::FromDoubleT(file_modification_time)); 61 element.file_length = file_length;
62 element.file_modification_time = file_modification_time;
61 http_body->elements.push_back(element); 63 http_body->elements.push_back(element);
62 } 64 }
63 65
64 void AppendBlobToHttpBody(ExplodedHttpBody* http_body, 66 void AppendBlobToHttpBody(ExplodedHttpBody* http_body,
65 const std::string& uuid) { 67 const std::string& uuid) {
66 ExplodedHttpBodyElement element; 68 ExplodedHttpBodyElement element;
67 element.SetToBlob(uuid); 69 element.type = blink::WebHTTPBody::Element::TypeBlob;
70 element.blob_uuid = uuid;
68 http_body->elements.push_back(element); 71 http_body->elements.push_back(element);
69 } 72 }
70 73
71 //---------------------------------------------------------------------------- 74 //----------------------------------------------------------------------------
72 75
73 void AppendReferencedFilesFromHttpBody( 76 void AppendReferencedFilesFromHttpBody(
74 const std::vector<ExplodedHttpBodyElement>& elements, 77 const std::vector<ExplodedHttpBodyElement>& elements,
75 std::vector<base::NullableString16>* referenced_files) { 78 std::vector<base::NullableString16>* referenced_files) {
76 for (size_t i = 0; i < elements.size(); ++i) { 79 for (size_t i = 0; i < elements.size(); ++i) {
77 if (elements[i].type() == ExplodedHttpBodyElement::TYPE_FILE) 80 if (elements[i].type == blink::WebHTTPBody::Element::TypeFile)
78 referenced_files->push_back( 81 referenced_files->push_back(elements[i].file_path);
79 base::NullableString16(elements[i].path().AsUTF16Unsafe(), false));
80 } 82 }
81 } 83 }
82 84
83 bool AppendReferencedFilesFromDocumentState( 85 bool AppendReferencedFilesFromDocumentState(
84 const std::vector<base::NullableString16>& document_state, 86 const std::vector<base::NullableString16>& document_state,
85 std::vector<base::NullableString16>* referenced_files) { 87 std::vector<base::NullableString16>* referenced_files) {
86 if (document_state.empty()) 88 if (document_state.empty())
87 return true; 89 return true;
88 90
89 // This algorithm is adapted from Blink's core/html/FormController.cpp code. 91 // This algorithm is adapted from Blink's core/html/FormController.cpp code.
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // Writes an ExplodedHttpBody object into a SerializeObject for serialization. 400 // Writes an ExplodedHttpBody object into a SerializeObject for serialization.
399 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) { 401 void WriteHttpBody(const ExplodedHttpBody& http_body, SerializeObject* obj) {
400 WriteBoolean(!http_body.is_null, obj); 402 WriteBoolean(!http_body.is_null, obj);
401 403
402 if (http_body.is_null) 404 if (http_body.is_null)
403 return; 405 return;
404 406
405 WriteAndValidateVectorSize(http_body.elements, obj); 407 WriteAndValidateVectorSize(http_body.elements, obj);
406 for (size_t i = 0; i < http_body.elements.size(); ++i) { 408 for (size_t i = 0; i < http_body.elements.size(); ++i) {
407 const ExplodedHttpBodyElement& element = http_body.elements[i]; 409 const ExplodedHttpBodyElement& element = http_body.elements[i];
408 switch (element.type()) { 410 WriteInteger(element.type, obj);
409 case ExplodedHttpBodyElement::TYPE_BYTES: 411 if (element.type == blink::WebHTTPBody::Element::TypeData) {
410 WriteInteger(blink::WebHTTPBody::Element::TypeData, obj); 412 WriteData(element.data.data(), static_cast<int>(element.data.size()),
411 WriteData(element.bytes(), static_cast<int>(element.length()), obj); 413 obj);
412 break; 414 } else if (element.type == blink::WebHTTPBody::Element::TypeFile) {
413 case ExplodedHttpBodyElement::TYPE_FILE: 415 WriteString(element.file_path, obj);
414 WriteInteger(blink::WebHTTPBody::Element::TypeFile, obj); 416 WriteInteger64(element.file_start, obj);
415 WriteString( 417 WriteInteger64(element.file_length, obj);
416 base::NullableString16(element.path().AsUTF16Unsafe(), false), obj); 418 WriteReal(element.file_modification_time, obj);
417 WriteInteger64(static_cast<int64_t>(element.offset()), obj); 419 } else if (element.type ==
418 WriteInteger64(static_cast<int64_t>(element.length()), obj); 420 blink::WebHTTPBody::Element::TypeFileSystemURL) {
419 WriteReal(element.expected_modification_time().ToDoubleT(), obj); 421 WriteGURL(element.filesystem_url, obj);
420 break; 422 WriteInteger64(element.file_start, obj);
421 case ExplodedHttpBodyElement::TYPE_FILE_FILESYSTEM: 423 WriteInteger64(element.file_length, obj);
422 WriteInteger(blink::WebHTTPBody::Element::TypeFileSystemURL, obj); 424 WriteReal(element.file_modification_time, obj);
423 WriteGURL(element.filesystem_url(), obj); 425 } else {
424 WriteInteger64(static_cast<int64_t>(element.offset()), obj); 426 DCHECK(element.type == blink::WebHTTPBody::Element::TypeBlob);
425 WriteInteger64(static_cast<int64_t>(element.length()), obj); 427 WriteStdString(element.blob_uuid, obj);
426 WriteReal(element.expected_modification_time().ToDoubleT(), obj);
427 break;
428 case ExplodedHttpBodyElement::TYPE_BLOB:
429 WriteInteger(blink::WebHTTPBody::Element::TypeBlob, obj);
430 WriteStdString(element.blob_uuid(), obj);
431 break;
432 case ExplodedHttpBodyElement::TYPE_BYTES_DESCRIPTION:
433 case ExplodedHttpBodyElement::TYPE_DISK_CACHE_ENTRY:
434 default:
435 NOTREACHED();
436 continue;
437 } 428 }
438 } 429 }
439 WriteInteger64(http_body.identifier, obj); 430 WriteInteger64(http_body.identifier, obj);
440 WriteBoolean(http_body.contains_passwords, obj); 431 WriteBoolean(http_body.contains_passwords, obj);
441 } 432 }
442 433
443 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) { 434 void ReadHttpBody(SerializeObject* obj, ExplodedHttpBody* http_body) {
444 // An initial boolean indicates if we have an HTTP body. 435 // An initial boolean indicates if we have an HTTP body.
445 if (!ReadBoolean(obj)) 436 if (!ReadBoolean(obj))
446 return; 437 return;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 660
670 // De-dupe 661 // De-dupe
671 state->referenced_files.erase( 662 state->referenced_files.erase(
672 std::unique(state->referenced_files.begin(), 663 std::unique(state->referenced_files.begin(),
673 state->referenced_files.end()), 664 state->referenced_files.end()),
674 state->referenced_files.end()); 665 state->referenced_files.end());
675 } 666 }
676 667
677 } // namespace 668 } // namespace
678 669
670 ExplodedHttpBodyElement::ExplodedHttpBodyElement()
671 : type(blink::WebHTTPBody::Element::TypeData),
672 file_start(0),
673 file_length(-1),
674 file_modification_time(std::numeric_limits<double>::quiet_NaN()) {
675 }
676
677 ExplodedHttpBodyElement::ExplodedHttpBodyElement(
678 const ExplodedHttpBodyElement& other) = default;
679
680 ExplodedHttpBodyElement::~ExplodedHttpBodyElement() {
681 }
682
679 ExplodedHttpBody::ExplodedHttpBody() 683 ExplodedHttpBody::ExplodedHttpBody()
680 : identifier(0), 684 : identifier(0),
681 contains_passwords(false), 685 contains_passwords(false),
682 is_null(true) { 686 is_null(true) {
683 } 687 }
684 688
685 ExplodedHttpBody::~ExplodedHttpBody() { 689 ExplodedHttpBody::~ExplodedHttpBody() {
686 } 690 }
687 691
688 ExplodedFrameState::ExplodedFrameState() 692 ExplodedFrameState::ExplodedFrameState()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 return true; 751 return true;
748 } 752 }
749 753
750 bool GeneratePostData(const ExplodedHttpBody& exploded, 754 bool GeneratePostData(const ExplodedHttpBody& exploded,
751 ResourceRequestBody* http_body) { 755 ResourceRequestBody* http_body) {
752 if (exploded.is_null) 756 if (exploded.is_null)
753 return false; 757 return false;
754 758
755 http_body->set_identifier(exploded.identifier); 759 http_body->set_identifier(exploded.identifier);
756 for (auto element : exploded.elements) 760 for (auto element : exploded.elements)
757 http_body->elements_mutable()->push_back(element); 761 http_body->AppendExplodedHTTPBodyElement(element);
758 762
759 return true; 763 return true;
760 } 764 }
761 765
762 #if defined(OS_ANDROID) 766 #if defined(OS_ANDROID)
763 bool DecodePageStateWithDeviceScaleFactorForTesting( 767 bool DecodePageStateWithDeviceScaleFactorForTesting(
764 const std::string& encoded, 768 const std::string& encoded,
765 float device_scale_factor, 769 float device_scale_factor,
766 ExplodedPageState* exploded) { 770 ExplodedPageState* exploded) {
767 g_device_scale_factor_for_testing = device_scale_factor; 771 g_device_scale_factor_for_testing = device_scale_factor;
768 bool rv = DecodePageState(encoded, exploded); 772 bool rv = DecodePageState(encoded, exploded);
769 g_device_scale_factor_for_testing = 0.0; 773 g_device_scale_factor_for_testing = 0.0;
770 return rv; 774 return rv;
771 } 775 }
772 #endif 776 #endif
773 777
774 } // namespace content 778 } // namespace content
OLDNEW
« no previous file with comments | « content/common/page_state_serialization.h ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698