OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 } | 46 } |
47 | 47 |
48 void WebHTTPBody::Assign(const WebHTTPBody& other) { | 48 void WebHTTPBody::Assign(const WebHTTPBody& other) { |
49 WebHTTPBodyPrivate* p = const_cast<WebHTTPBodyPrivate*>(other.private_); | 49 WebHTTPBodyPrivate* p = const_cast<WebHTTPBodyPrivate*>(other.private_); |
50 if (p) | 50 if (p) |
51 p->Ref(); | 51 p->Ref(); |
52 Assign(p); | 52 Assign(p); |
53 } | 53 } |
54 | 54 |
55 size_t WebHTTPBody::ElementCount() const { | 55 size_t WebHTTPBody::ElementCount() const { |
56 ASSERT(!IsNull()); | 56 DCHECK(!IsNull()); |
57 return private_->Elements().size(); | 57 return private_->Elements().size(); |
58 } | 58 } |
59 | 59 |
60 bool WebHTTPBody::ElementAt(size_t index, Element& result) const { | 60 bool WebHTTPBody::ElementAt(size_t index, Element& result) const { |
61 ASSERT(!IsNull()); | 61 DCHECK(!IsNull()); |
62 | 62 |
63 if (index >= private_->Elements().size()) | 63 if (index >= private_->Elements().size()) |
64 return false; | 64 return false; |
65 | 65 |
66 const FormDataElement& element = private_->Elements()[index]; | 66 const FormDataElement& element = private_->Elements()[index]; |
67 | 67 |
68 result.data.Reset(); | 68 result.data.Reset(); |
69 result.file_path.Reset(); | 69 result.file_path.Reset(); |
70 result.file_start = 0; | 70 result.file_start = 0; |
71 result.file_length = 0; | 71 result.file_length = 0; |
(...skipping 17 matching lines...) Expand all Loading... | |
89 result.blob_uuid = element.blob_uuid_; | 89 result.blob_uuid = element.blob_uuid_; |
90 break; | 90 break; |
91 case FormDataElement::kEncodedFileSystemURL: | 91 case FormDataElement::kEncodedFileSystemURL: |
92 result.type = Element::kTypeFileSystemURL; | 92 result.type = Element::kTypeFileSystemURL; |
93 result.file_system_url = element.file_system_url_; | 93 result.file_system_url = element.file_system_url_; |
94 result.file_start = element.file_start_; | 94 result.file_start = element.file_start_; |
95 result.file_length = element.file_length_; | 95 result.file_length = element.file_length_; |
96 result.modification_time = element.expected_file_modification_time_; | 96 result.modification_time = element.expected_file_modification_time_; |
97 break; | 97 break; |
98 default: | 98 default: |
99 ASSERT_NOT_REACHED(); | 99 NOTREACHED(); |
100 return false; | 100 return false; |
101 } | 101 } |
102 | 102 |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 void WebHTTPBody::AppendData(const WebData& data) { | 106 void WebHTTPBody::AppendData(const WebData& data) { |
107 EnsureMutable(); | 107 EnsureMutable(); |
108 // FIXME: FormDataElement::m_data should be a SharedBuffer<char>. Then we | 108 // FIXME: FormDataElement::m_data should be a SharedBuffer<char>. Then we |
109 // could avoid this buffer copy. | 109 // could avoid this buffer copy. |
(...skipping 12 matching lines...) Expand all Loading... | |
122 EnsureMutable(); | 122 EnsureMutable(); |
123 private_->AppendFileRange(file_path, file_start, file_length, | 123 private_->AppendFileRange(file_path, file_start, file_length, |
124 modification_time); | 124 modification_time); |
125 } | 125 } |
126 | 126 |
127 void WebHTTPBody::AppendFileSystemURLRange(const WebURL& url, | 127 void WebHTTPBody::AppendFileSystemURLRange(const WebURL& url, |
128 long long start, | 128 long long start, |
129 long long length, | 129 long long length, |
130 double modification_time) { | 130 double modification_time) { |
131 // Currently we only support filesystem URL. | 131 // Currently we only support filesystem URL. |
132 ASSERT(KURL(url).ProtocolIs("filesystem")); | 132 DCHECK(KURL(url).ProtocolIs("filesystem")); |
133 EnsureMutable(); | 133 EnsureMutable(); |
134 private_->AppendFileSystemURLRange(url, start, length, modification_time); | 134 private_->AppendFileSystemURLRange(url, start, length, modification_time); |
135 } | 135 } |
136 | 136 |
137 void WebHTTPBody::AppendBlob(const WebString& uuid) { | 137 void WebHTTPBody::AppendBlob(const WebString& uuid) { |
138 EnsureMutable(); | 138 EnsureMutable(); |
139 private_->AppendBlob(uuid, nullptr); | 139 private_->AppendBlob(uuid, nullptr); |
140 } | 140 } |
141 | 141 |
142 long long WebHTTPBody::Identifier() const { | 142 long long WebHTTPBody::Identifier() const { |
143 ASSERT(!IsNull()); | 143 DCHECK(!IsNull()); |
144 return private_->Identifier(); | 144 return private_->Identifier(); |
145 } | 145 } |
146 | 146 |
147 void WebHTTPBody::SetIdentifier(long long identifier) { | 147 void WebHTTPBody::SetIdentifier(long long identifier) { |
148 EnsureMutable(); | 148 EnsureMutable(); |
149 return private_->SetIdentifier(identifier); | 149 return private_->SetIdentifier(identifier); |
150 } | 150 } |
151 | 151 |
152 bool WebHTTPBody::ContainsPasswordData() const { | 152 bool WebHTTPBody::ContainsPasswordData() const { |
153 return private_->ContainsPasswordData(); | 153 return private_->ContainsPasswordData(); |
154 } | 154 } |
155 | 155 |
156 void WebHTTPBody::SetContainsPasswordData(bool contains_password_data) { | 156 void WebHTTPBody::SetContainsPasswordData(bool contains_password_data) { |
157 private_->SetContainsPasswordData(contains_password_data); | 157 private_->SetContainsPasswordData(contains_password_data); |
158 } | 158 } |
159 | 159 |
160 WebHTTPBody::WebHTTPBody(PassRefPtr<EncodedFormData> data) | 160 WebHTTPBody::WebHTTPBody(PassRefPtr<EncodedFormData> data) |
161 : private_(static_cast<WebHTTPBodyPrivate*>(data.LeakRef())) {} | 161 : private_(static_cast<WebHTTPBodyPrivate*>(data.LeakRef())) {} |
162 | 162 |
163 WebHTTPBody& WebHTTPBody::operator=(PassRefPtr<EncodedFormData> data) { | 163 WebHTTPBody& WebHTTPBody::operator=(PassRefPtr<EncodedFormData> data) { |
164 Assign(static_cast<WebHTTPBodyPrivate*>(data.LeakRef())); | 164 DCHECK(static_cast<WebHTTPBodyPrivate*>(data.LeakRef())); |
dcheng1
2017/07/11 03:15:06
Just a friendly reminder to be careful with refact
| |
165 return *this; | 165 return *this; |
166 } | 166 } |
167 | 167 |
168 WebHTTPBody::operator PassRefPtr<EncodedFormData>() const { | 168 WebHTTPBody::operator PassRefPtr<EncodedFormData>() const { |
169 return private_; | 169 return private_; |
170 } | 170 } |
171 | 171 |
172 void WebHTTPBody::Assign(WebHTTPBodyPrivate* p) { | 172 void WebHTTPBody::Assign(WebHTTPBodyPrivate* p) { |
173 // p is already ref'd for us by the caller | 173 // p is already ref'd for us by the caller |
174 if (private_) | 174 if (private_) |
175 private_->Deref(); | 175 private_->Deref(); |
176 private_ = p; | 176 private_ = p; |
177 } | 177 } |
178 | 178 |
179 void WebHTTPBody::EnsureMutable() { | 179 void WebHTTPBody::EnsureMutable() { |
180 ASSERT(!IsNull()); | 180 DCHECK(!IsNull()); |
181 if (!private_->HasOneRef()) | 181 if (!private_->HasOneRef()) |
182 Assign(static_cast<WebHTTPBodyPrivate*>(private_->Copy().LeakRef())); | 182 Assign(static_cast<WebHTTPBodyPrivate*>(private_->Copy().LeakRef())); |
183 } | 183 } |
184 | 184 |
185 } // namespace blink | 185 } // namespace blink |
OLD | NEW |