OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 , m_isContentEvicted(false) | 73 , m_isContentEvicted(false) |
74 , m_type(InspectorPageAgent::OtherResource) | 74 , m_type(InspectorPageAgent::OtherResource) |
75 , m_cachedResource(0) | 75 , m_cachedResource(0) |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
79 void NetworkResourcesData::ResourceData::setContent(const String& content, bool
base64Encoded) | 79 void NetworkResourcesData::ResourceData::setContent(const String& content, bool
base64Encoded) |
80 { | 80 { |
81 ASSERT(!hasData()); | 81 ASSERT(!hasData()); |
82 ASSERT(!hasContent()); | 82 ASSERT(!hasContent()); |
| 83 ASSERT(!hasBlob()); |
83 m_content = content; | 84 m_content = content; |
84 m_base64Encoded = base64Encoded; | 85 m_base64Encoded = base64Encoded; |
85 } | 86 } |
86 | 87 |
| 88 void NetworkResourcesData::ResourceData::setBlob(PassRefPtr<Blob> blob, const St
ring& textEncodingName) |
| 89 { |
| 90 ASSERT(!hasData()); |
| 91 ASSERT(!hasContent()); |
| 92 ASSERT(!hasBlob()); |
| 93 m_blob = blob; |
| 94 m_blobTextEncodingName = textEncodingName; |
| 95 } |
| 96 |
87 static size_t contentSizeInBytes(const String& content) | 97 static size_t contentSizeInBytes(const String& content) |
88 { | 98 { |
89 return content.isNull() ? 0 : content.impl()->sizeInBytes(); | 99 return content.isNull() ? 0 : content.impl()->sizeInBytes(); |
90 } | 100 } |
91 | 101 |
92 unsigned NetworkResourcesData::ResourceData::removeContent() | 102 unsigned NetworkResourcesData::ResourceData::removeContent() |
93 { | 103 { |
94 unsigned result = 0; | 104 unsigned result = 0; |
95 if (hasData()) { | 105 if (hasData()) { |
96 ASSERT(!hasContent()); | 106 ASSERT(!hasContent() && !hasBlob()); |
97 result = m_dataBuffer->size(); | 107 result = m_dataBuffer->size(); |
98 m_dataBuffer = nullptr; | 108 m_dataBuffer = nullptr; |
99 } | 109 } |
100 | 110 |
101 if (hasContent()) { | 111 if (hasContent()) { |
102 ASSERT(!hasData()); | 112 ASSERT(!hasData() && !hasBlob()); |
103 result = contentSizeInBytes(m_content); | 113 result = contentSizeInBytes(m_content); |
104 m_content = String(); | 114 m_content = String(); |
105 } | 115 } |
| 116 |
| 117 if (hasBlob()) { |
| 118 ASSERT(!hasData() && !hasContent()); |
| 119 result = m_blob->size(); |
| 120 m_blob = nullptr; |
| 121 m_blobTextEncodingName = String(); |
| 122 } |
106 return result; | 123 return result; |
107 } | 124 } |
108 | 125 |
109 unsigned NetworkResourcesData::ResourceData::evictContent() | 126 unsigned NetworkResourcesData::ResourceData::evictContent() |
110 { | 127 { |
111 m_isContentEvicted = true; | 128 m_isContentEvicted = true; |
112 return removeContent(); | 129 return removeContent(); |
113 } | 130 } |
114 | 131 |
115 size_t NetworkResourcesData::ResourceData::dataLength() const | 132 size_t NetworkResourcesData::ResourceData::dataLength() const |
116 { | 133 { |
117 return m_dataBuffer ? m_dataBuffer->size() : 0; | 134 return m_dataBuffer ? m_dataBuffer->size() : 0; |
118 } | 135 } |
119 | 136 |
120 void NetworkResourcesData::ResourceData::appendData(const char* data, size_t dat
aLength) | 137 void NetworkResourcesData::ResourceData::appendData(const char* data, size_t dat
aLength) |
121 { | 138 { |
122 ASSERT(!hasContent()); | 139 ASSERT(!hasContent() && !hasBlob()); |
123 if (!m_dataBuffer) | 140 if (!m_dataBuffer) |
124 m_dataBuffer = SharedBuffer::create(data, dataLength); | 141 m_dataBuffer = SharedBuffer::create(data, dataLength); |
125 else | 142 else |
126 m_dataBuffer->append(data, dataLength); | 143 m_dataBuffer->append(data, dataLength); |
127 } | 144 } |
128 | 145 |
129 size_t NetworkResourcesData::ResourceData::decodeDataToContent() | 146 size_t NetworkResourcesData::ResourceData::decodeDataToContent() |
130 { | 147 { |
131 ASSERT(!hasContent()); | 148 ASSERT(!hasContent() && !hasBlob()); |
132 size_t dataLength = m_dataBuffer->size(); | 149 size_t dataLength = m_dataBuffer->size(); |
133 m_content = m_decoder->decode(m_dataBuffer->data(), m_dataBuffer->size()); | 150 m_content = m_decoder->decode(m_dataBuffer->data(), m_dataBuffer->size()); |
134 m_content.append(m_decoder->flush()); | 151 m_content.append(m_decoder->flush()); |
135 m_dataBuffer = nullptr; | 152 m_dataBuffer = nullptr; |
136 return contentSizeInBytes(m_content) - dataLength; | 153 return contentSizeInBytes(m_content) - dataLength; |
137 } | 154 } |
138 | 155 |
139 // NetworkResourcesData | 156 // NetworkResourcesData |
140 NetworkResourcesData::NetworkResourcesData() | 157 NetworkResourcesData::NetworkResourcesData() |
141 : m_contentSize(0) | 158 : m_contentSize(0) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ResourceData* resourceData = resourceDataForRequestId(requestId); | 219 ResourceData* resourceData = resourceDataForRequestId(requestId); |
203 if (!resourceData) | 220 if (!resourceData) |
204 return; | 221 return; |
205 size_t dataLength = contentSizeInBytes(content); | 222 size_t dataLength = contentSizeInBytes(content); |
206 if (dataLength > m_maximumSingleResourceContentSize) | 223 if (dataLength > m_maximumSingleResourceContentSize) |
207 return; | 224 return; |
208 if (resourceData->isContentEvicted()) | 225 if (resourceData->isContentEvicted()) |
209 return; | 226 return; |
210 if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) { | 227 if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) { |
211 // We can not be sure that we didn't try to save this request data while
it was loading, so remove it, if any. | 228 // We can not be sure that we didn't try to save this request data while
it was loading, so remove it, if any. |
212 if (resourceData->hasContent()) | 229 if (resourceData->hasContent() || resourceData->hasBlob()) |
213 m_contentSize -= resourceData->removeContent(); | 230 m_contentSize -= resourceData->removeContent(); |
214 m_requestIdsDeque.append(requestId); | 231 m_requestIdsDeque.append(requestId); |
215 resourceData->setContent(content, base64Encoded); | 232 resourceData->setContent(content, base64Encoded); |
216 m_contentSize += dataLength; | 233 m_contentSize += dataLength; |
217 } | 234 } |
218 } | 235 } |
219 | 236 |
| 237 void NetworkResourcesData::setResourceBlob(const String& requestId, PassRefPtr<B
lob> prpBlob, const String& textEncodingName) |
| 238 { |
| 239 RefPtr<Blob> blob = prpBlob; |
| 240 ResourceData* resourceData = resourceDataForRequestId(requestId); |
| 241 if (!resourceData) |
| 242 return; |
| 243 size_t dataLength = blob->size(); |
| 244 if (dataLength > m_maximumSingleResourceContentSize) |
| 245 return; |
| 246 if (resourceData->isContentEvicted()) |
| 247 return; |
| 248 if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) { |
| 249 // We can not be sure that we didn't try to save this request data while
it was loading, so remove it, if any. |
| 250 if (resourceData->hasContent() || resourceData->hasBlob()) |
| 251 m_contentSize -= resourceData->removeContent(); |
| 252 m_requestIdsDeque.append(requestId); |
| 253 resourceData->setBlob(blob, textEncodingName); |
| 254 m_contentSize += dataLength; |
| 255 } |
| 256 } |
| 257 |
220 void NetworkResourcesData::maybeAddResourceData(const String& requestId, const c
har* data, size_t dataLength) | 258 void NetworkResourcesData::maybeAddResourceData(const String& requestId, const c
har* data, size_t dataLength) |
221 { | 259 { |
222 ResourceData* resourceData = resourceDataForRequestId(requestId); | 260 ResourceData* resourceData = resourceDataForRequestId(requestId); |
223 if (!resourceData) | 261 if (!resourceData) |
224 return; | 262 return; |
225 if (!resourceData->decoder()) | 263 if (!resourceData->decoder()) |
226 return; | 264 return; |
227 if (resourceData->dataLength() + dataLength > m_maximumSingleResourceContent
Size) | 265 if (resourceData->dataLength() + dataLength > m_maximumSingleResourceContent
Size) |
228 m_contentSize -= resourceData->evictContent(); | 266 m_contentSize -= resourceData->evictContent(); |
229 if (resourceData->isContentEvicted()) | 267 if (resourceData->isContentEvicted()) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (requestId.isNull()) | 397 if (requestId.isNull()) |
360 return 0; | 398 return 0; |
361 return m_requestIdToResourceDataMap.get(requestId); | 399 return m_requestIdToResourceDataMap.get(requestId); |
362 } | 400 } |
363 | 401 |
364 void NetworkResourcesData::ensureNoDataForRequestId(const String& requestId) | 402 void NetworkResourcesData::ensureNoDataForRequestId(const String& requestId) |
365 { | 403 { |
366 ResourceData* resourceData = resourceDataForRequestId(requestId); | 404 ResourceData* resourceData = resourceDataForRequestId(requestId); |
367 if (!resourceData) | 405 if (!resourceData) |
368 return; | 406 return; |
369 if (resourceData->hasContent() || resourceData->hasData()) | 407 if (resourceData->hasContent() || resourceData->hasData() || resourceData->h
asBlob()) |
370 m_contentSize -= resourceData->evictContent(); | 408 m_contentSize -= resourceData->evictContent(); |
371 delete resourceData; | 409 delete resourceData; |
372 m_requestIdToResourceDataMap.remove(requestId); | 410 m_requestIdToResourceDataMap.remove(requestId); |
373 } | 411 } |
374 | 412 |
375 bool NetworkResourcesData::ensureFreeSpace(size_t size) | 413 bool NetworkResourcesData::ensureFreeSpace(size_t size) |
376 { | 414 { |
377 if (size > m_maximumResourcesContentSize) | 415 if (size > m_maximumResourcesContentSize) |
378 return false; | 416 return false; |
379 | 417 |
380 while (size > m_maximumResourcesContentSize - m_contentSize) { | 418 while (size > m_maximumResourcesContentSize - m_contentSize) { |
381 String requestId = m_requestIdsDeque.takeFirst(); | 419 String requestId = m_requestIdsDeque.takeFirst(); |
382 ResourceData* resourceData = resourceDataForRequestId(requestId); | 420 ResourceData* resourceData = resourceDataForRequestId(requestId); |
383 if (resourceData) | 421 if (resourceData) |
384 m_contentSize -= resourceData->evictContent(); | 422 m_contentSize -= resourceData->evictContent(); |
385 } | 423 } |
386 return true; | 424 return true; |
387 } | 425 } |
388 | 426 |
389 } // namespace WebCore | 427 } // namespace WebCore |
390 | 428 |
OLD | NEW |