Chromium Code Reviews

Side by Side Diff: third_party/WebKit/Source/core/fetch/Resource.cpp

Issue 2210473002: Mark ResourceClient/ImageResourceObserver finished just before notifying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reflect comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 325 matching lines...)
336 void Resource::setLoader(ResourceLoader* loader) 336 void Resource::setLoader(ResourceLoader* loader)
337 { 337 {
338 RELEASE_ASSERT(!m_loader); 338 RELEASE_ASSERT(!m_loader);
339 ASSERT(stillNeedsLoad()); 339 ASSERT(stillNeedsLoad());
340 m_loader = loader; 340 m_loader = loader;
341 m_status = Pending; 341 m_status = Pending;
342 } 342 }
343 343
344 void Resource::checkNotify() 344 void Resource::checkNotify()
345 { 345 {
346 notifyClientsInternal(MarkFinishedOption::ShouldMarkFinished);
347 }
348
349 void Resource::notifyClientsInternal(MarkFinishedOption markFinishedOption)
350 {
346 if (isLoading()) 351 if (isLoading())
347 return; 352 return;
348 353
349 ResourceClientWalker<ResourceClient> w(m_clients); 354 ResourceClientWalker<ResourceClient> w(m_clients);
350 while (ResourceClient* c = w.next()) 355 while (ResourceClient* c = w.next()) {
356 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished)
357 markClientFinished(c);
351 c->notifyFinished(this); 358 c->notifyFinished(this);
359 }
360 }
361
362 void Resource::markClientFinished(ResourceClient* client)
363 {
364 if (m_clients.contains(client)) {
365 m_finishedClients.add(client);
366 m_clients.remove(client);
367 }
352 } 368 }
353 369
354 void Resource::appendData(const char* data, size_t length) 370 void Resource::appendData(const char* data, size_t length)
355 { 371 {
356 TRACE_EVENT0("blink", "Resource::appendData"); 372 TRACE_EVENT0("blink", "Resource::appendData");
357 DCHECK(!m_isRevalidating); 373 DCHECK(!m_isRevalidating);
358 ASSERT(!errorOccurred()); 374 ASSERT(!errorOccurred());
359 if (m_options.dataBufferingPolicy == DoNotBufferData) 375 if (m_options.dataBufferingPolicy == DoNotBufferData)
360 return; 376 return;
361 if (m_data) 377 if (m_data)
(...skipping 12 matching lines...)
374 setEncodedSize(m_data->size()); 390 setEncodedSize(m_data->size());
375 } 391 }
376 392
377 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy) 393 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy)
378 { 394 {
379 m_options.dataBufferingPolicy = dataBufferingPolicy; 395 m_options.dataBufferingPolicy = dataBufferingPolicy;
380 m_data.clear(); 396 m_data.clear();
381 setEncodedSize(0); 397 setEncodedSize(0);
382 } 398 }
383 399
384 void Resource::markClientsAndObserversFinished()
385 {
386 HashCountedSet<ResourceClient*> clients;
387 m_clients.swap(clients);
388 for (const auto& it : clients)
389 m_finishedClients.add(it.key, it.value);
390 }
391
392 void Resource::error(const ResourceError& error) 400 void Resource::error(const ResourceError& error)
393 { 401 {
394 ASSERT(!error.isNull()); 402 ASSERT(!error.isNull());
395 m_error = error; 403 m_error = error;
396 m_isRevalidating = false; 404 m_isRevalidating = false;
397 405
398 if (m_error.isCancellation() || !isPreloaded()) 406 if (m_error.isCancellation() || !isPreloaded())
399 memoryCache()->remove(this); 407 memoryCache()->remove(this);
400 408
401 if (!errorOccurred()) 409 if (!errorOccurred())
402 setStatus(LoadError); 410 setStatus(LoadError);
403 ASSERT(errorOccurred()); 411 ASSERT(errorOccurred());
404 m_data.clear(); 412 m_data.clear();
405 m_loader = nullptr; 413 m_loader = nullptr;
406 checkNotify(); 414 checkNotify();
407 markClientsAndObserversFinished();
408 } 415 }
409 416
410 void Resource::finish(double loadFinishTime) 417 void Resource::finish(double loadFinishTime)
411 { 418 {
412 DCHECK(!m_isRevalidating); 419 DCHECK(!m_isRevalidating);
413 m_loadFinishTime = loadFinishTime; 420 m_loadFinishTime = loadFinishTime;
414 if (!errorOccurred()) 421 if (!errorOccurred())
415 m_status = Cached; 422 m_status = Cached;
416 m_loader = nullptr; 423 m_loader = nullptr;
417 checkNotify(); 424 checkNotify();
418 markClientsAndObserversFinished();
419 } 425 }
420 426
421 AtomicString Resource::httpContentType() const 427 AtomicString Resource::httpContentType() const
422 { 428 {
423 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower()); 429 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower());
424 } 430 }
425 431
426 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const 432 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const
427 { 433 {
428 String ignoredErrorDescription; 434 String ignoredErrorDescription;
(...skipping 683 matching lines...)
1112 case Resource::TextTrack: 1118 case Resource::TextTrack:
1113 case Resource::Media: 1119 case Resource::Media:
1114 case Resource::Manifest: 1120 case Resource::Manifest:
1115 return false; 1121 return false;
1116 } 1122 }
1117 ASSERT_NOT_REACHED(); 1123 ASSERT_NOT_REACHED();
1118 return false; 1124 return false;
1119 } 1125 }
1120 1126
1121 } // namespace blink 1127 } // namespace blink
OLDNEW

Powered by Google App Engine