Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 230 |
| 231 // Don't notify observers and clients of completion if this ImageResource is | 231 // Don't notify observers and clients of completion if this ImageResource is |
| 232 // about to be reloaded. | 232 // about to be reloaded. |
| 233 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) | 233 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) |
| 234 return; | 234 return; |
| 235 | 235 |
| 236 Resource::didAddClient(client); | 236 Resource::didAddClient(client); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void ImageResource::destroyDecodedDataForFailedRevalidation() { | 239 void ImageResource::destroyDecodedDataForFailedRevalidation() { |
| 240 getContent()->clearImage(); | 240 // Clears the image, as we must create a new image for the failed |
| 241 // revalidation response. | |
| 242 getContent()->updateImage(nullptr, ImageResourceContent::ClearAndUpdateImage, | |
|
yhirano
2016/12/19 11:50:26
Isn't this ClearImageOnly?
hiroshige
2016/12/19 22:51:50
No.
Here, we want to clear the image without notif
yhirano
2016/12/20 12:09:16
Then I think the enum naming is confusing - ClearI
| |
| 243 false); | |
| 241 setDecodedSize(0); | 244 setDecodedSize(0); |
| 242 } | 245 } |
| 243 | 246 |
| 244 void ImageResource::destroyDecodedDataIfPossible() { | 247 void ImageResource::destroyDecodedDataIfPossible() { |
| 245 getContent()->destroyDecodedData(); | 248 getContent()->destroyDecodedData(); |
| 246 if (getContent()->hasImage() && !isPreloaded() && | 249 if (getContent()->hasImage() && !isPreloaded() && |
| 247 getContent()->isRefetchableDataFromDiskCache()) { | 250 getContent()->isRefetchableDataFromDiskCache()) { |
| 248 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer.EstimatedDroppableEncodedSize", | 251 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer.EstimatedDroppableEncodedSize", |
| 249 encodedSize() / 1024); | 252 encodedSize() / 1024); |
| 250 } | 253 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 275 | 278 |
| 276 void ImageResource::appendData(const char* data, size_t length) { | 279 void ImageResource::appendData(const char* data, size_t length) { |
| 277 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); | 280 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); |
| 278 if (m_multipartParser) { | 281 if (m_multipartParser) { |
| 279 m_multipartParser->appendData(data, length); | 282 m_multipartParser->appendData(data, length); |
| 280 } else { | 283 } else { |
| 281 Resource::appendData(data, length); | 284 Resource::appendData(data, length); |
| 282 | 285 |
| 283 // Update the image immediately if needed. | 286 // Update the image immediately if needed. |
| 284 if (getContent()->shouldUpdateImageImmediately()) { | 287 if (getContent()->shouldUpdateImageImmediately()) { |
| 285 getContent()->updateImage(this->data(), | 288 getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage, |
| 286 ImageResourceContent::KeepExistingImage, false); | 289 false); |
| 287 return; | 290 return; |
| 288 } | 291 } |
| 289 | 292 |
| 290 // For other cases, only update at |kFlushDelaySeconds| intervals. This | 293 // For other cases, only update at |kFlushDelaySeconds| intervals. This |
| 291 // throttles how frequently we update |m_image| and how frequently we | 294 // throttles how frequently we update |m_image| and how frequently we |
| 292 // inform the clients which causes an invalidation of this image. In other | 295 // inform the clients which causes an invalidation of this image. In other |
| 293 // words, we only invalidate this image every |kFlushDelaySeconds| seconds | 296 // words, we only invalidate this image every |kFlushDelaySeconds| seconds |
| 294 // while loading. | 297 // while loading. |
| 295 if (!m_flushTimer.isActive()) { | 298 if (!m_flushTimer.isActive()) { |
| 296 double now = WTF::monotonicallyIncreasingTime(); | 299 double now = WTF::monotonicallyIncreasingTime(); |
| 297 if (!m_lastFlushTime) | 300 if (!m_lastFlushTime) |
| 298 m_lastFlushTime = now; | 301 m_lastFlushTime = now; |
| 299 | 302 |
| 300 DCHECK_LE(m_lastFlushTime, now); | 303 DCHECK_LE(m_lastFlushTime, now); |
| 301 double flushDelay = m_lastFlushTime - now + kFlushDelaySeconds; | 304 double flushDelay = m_lastFlushTime - now + kFlushDelaySeconds; |
| 302 if (flushDelay < 0.) | 305 if (flushDelay < 0.) |
| 303 flushDelay = 0.; | 306 flushDelay = 0.; |
| 304 m_flushTimer.startOneShot(flushDelay, BLINK_FROM_HERE); | 307 m_flushTimer.startOneShot(flushDelay, BLINK_FROM_HERE); |
| 305 } | 308 } |
| 306 } | 309 } |
| 307 } | 310 } |
| 308 | 311 |
| 309 void ImageResource::flushImageIfNeeded(TimerBase*) { | 312 void ImageResource::flushImageIfNeeded(TimerBase*) { |
| 310 // We might have already loaded the image fully, in which case we don't need | 313 // We might have already loaded the image fully, in which case we don't need |
| 311 // to call |updateImage()|. | 314 // to call |updateImage()|. |
| 312 if (isLoading()) { | 315 if (isLoading()) { |
| 313 m_lastFlushTime = WTF::monotonicallyIncreasingTime(); | 316 m_lastFlushTime = WTF::monotonicallyIncreasingTime(); |
| 314 getContent()->updateImage(this->data(), | 317 getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage, |
| 315 ImageResourceContent::KeepExistingImage, false); | 318 false); |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 | 321 |
| 319 bool ImageResource::willPaintBrokenImage() const { | 322 bool ImageResource::willPaintBrokenImage() const { |
| 320 return errorOccurred(); | 323 return errorOccurred(); |
| 321 } | 324 } |
| 322 | 325 |
| 323 void ImageResource::decodeError(bool allDataReceived) { | 326 void ImageResource::decodeError(bool allDataReceived) { |
| 324 size_t size = encodedSize(); | 327 size_t size = encodedSize(); |
| 325 | 328 |
| 326 clearData(); | 329 clearData(); |
| 327 setEncodedSize(0); | 330 setEncodedSize(0); |
| 328 if (!errorOccurred()) | 331 if (!errorOccurred()) |
| 329 setStatus(DecodeError); | 332 setStatus(DecodeError); |
| 330 | 333 |
| 331 if (!allDataReceived && loader()) { | 334 if (!allDataReceived && loader()) { |
| 332 // TODO(hiroshige): Do not call didFinishLoading() directly. | 335 // TODO(hiroshige): Do not call didFinishLoading() directly. |
| 333 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size); | 336 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size); |
| 334 } | 337 } |
| 335 | 338 |
| 336 memoryCache()->remove(this); | 339 memoryCache()->remove(this); |
| 337 } | 340 } |
| 338 | 341 |
| 339 void ImageResource::updateImageAndClearBuffer() { | 342 void ImageResource::updateImageAndClearBuffer() { |
| 340 getContent()->updateImage(data(), ImageResourceContent::ClearExistingImage, | 343 getContent()->updateImage(data(), ImageResourceContent::ClearAndUpdateImage, |
| 341 true); | 344 true); |
| 342 clearData(); | 345 clearData(); |
| 343 } | 346 } |
| 344 | 347 |
| 345 void ImageResource::finish(double loadFinishTime) { | 348 void ImageResource::finish(double loadFinishTime) { |
| 346 if (m_multipartParser) { | 349 if (m_multipartParser) { |
| 347 m_multipartParser->finish(); | 350 m_multipartParser->finish(); |
| 348 if (data()) | 351 if (data()) |
| 349 updateImageAndClearBuffer(); | 352 updateImageAndClearBuffer(); |
| 350 } else { | 353 } else { |
| 351 getContent()->updateImage(data(), ImageResourceContent::KeepExistingImage, | 354 getContent()->updateImage(data(), ImageResourceContent::UpdateImage, true); |
| 352 true); | |
| 353 // As encoded image data can be created from m_image (see | 355 // As encoded image data can be created from m_image (see |
| 354 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's | 356 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's |
| 355 // clear this. As for the lifetimes of m_image and m_data, see this | 357 // clear this. As for the lifetimes of m_image and m_data, see this |
| 356 // document: | 358 // document: |
| 357 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1Vsqpxo L7aciY/edit?usp=sharing | 359 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1Vsqpxo L7aciY/edit?usp=sharing |
| 358 clearData(); | 360 clearData(); |
| 359 } | 361 } |
| 360 Resource::finish(loadFinishTime); | 362 Resource::finish(loadFinishTime); |
| 361 } | 363 } |
| 362 | 364 |
| 363 void ImageResource::error(const ResourceError& error) { | 365 void ImageResource::error(const ResourceError& error) { |
| 364 if (m_multipartParser) | 366 if (m_multipartParser) |
| 365 m_multipartParser->cancel(); | 367 m_multipartParser->cancel(); |
| 366 // TODO(hiroshige): Move setEncodedSize() call to Resource::error() if it | 368 // TODO(hiroshige): Move setEncodedSize() call to Resource::error() if it |
| 367 // is really needed, or remove it otherwise. | 369 // is really needed, or remove it otherwise. |
| 368 setEncodedSize(0); | 370 setEncodedSize(0); |
| 369 Resource::error(error); | 371 Resource::error(error); |
| 370 getContent()->clearImageAndNotifyObservers( | 372 getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly, |
| 371 ImageResourceContent::ShouldNotifyFinish); | 373 true); |
| 372 } | 374 } |
| 373 | 375 |
| 374 void ImageResource::responseReceived( | 376 void ImageResource::responseReceived( |
| 375 const ResourceResponse& response, | 377 const ResourceResponse& response, |
| 376 std::unique_ptr<WebDataConsumerHandle> handle) { | 378 std::unique_ptr<WebDataConsumerHandle> handle) { |
| 377 DCHECK(!handle); | 379 DCHECK(!handle); |
| 378 DCHECK(!m_multipartParser); | 380 DCHECK(!m_multipartParser); |
| 379 // If there's no boundary, just handle the request normally. | 381 // If there's no boundary, just handle the request normally. |
| 380 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { | 382 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { |
| 381 m_multipartParser = new MultipartImageResourceParser( | 383 m_multipartParser = new MultipartImageResourceParser( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 } | 432 } |
| 431 | 433 |
| 432 if (isLoading()) { | 434 if (isLoading()) { |
| 433 loader()->cancel(); | 435 loader()->cancel(); |
| 434 // Canceling the loader causes error() to be called, which in turn calls | 436 // Canceling the loader causes error() to be called, which in turn calls |
| 435 // clear() and notifyObservers(), so there's no need to call these again | 437 // clear() and notifyObservers(), so there's no need to call these again |
| 436 // here. | 438 // here. |
| 437 } else { | 439 } else { |
| 438 clearData(); | 440 clearData(); |
| 439 setEncodedSize(0); | 441 setEncodedSize(0); |
| 440 getContent()->clearImageAndNotifyObservers( | 442 getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly, |
| 441 ImageResourceContent::DoNotNotifyFinish); | 443 false); |
| 442 } | 444 } |
| 443 | 445 |
| 444 setStatus(NotStarted); | 446 setStatus(NotStarted); |
| 445 | 447 |
| 446 DCHECK(m_isSchedulingReload); | 448 DCHECK(m_isSchedulingReload); |
| 447 m_isSchedulingReload = false; | 449 m_isSchedulingReload = false; |
| 448 | 450 |
| 449 fetcher->startLoad(this); | 451 fetcher->startLoad(this); |
| 450 } | 452 } |
| 451 | 453 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 | 504 |
| 503 const ImageResourceContent* ImageResource::getContent() const { | 505 const ImageResourceContent* ImageResource::getContent() const { |
| 504 return m_content; | 506 return m_content; |
| 505 } | 507 } |
| 506 | 508 |
| 507 ResourcePriority ImageResource::priorityFromObservers() { | 509 ResourcePriority ImageResource::priorityFromObservers() { |
| 508 return getContent()->priorityFromObservers(); | 510 return getContent()->priorityFromObservers(); |
| 509 } | 511 } |
| 510 | 512 |
| 511 } // namespace blink | 513 } // namespace blink |
| OLD | NEW |