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

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: Wrap by 80 cols and Rebase. Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void Resource::setLoader(ResourceLoader* loader) 335 void Resource::setLoader(ResourceLoader* loader)
336 { 336 {
337 RELEASE_ASSERT(!m_loader); 337 RELEASE_ASSERT(!m_loader);
338 ASSERT(stillNeedsLoad()); 338 ASSERT(stillNeedsLoad());
339 m_loader = loader; 339 m_loader = loader;
340 m_status = Pending; 340 m_status = Pending;
341 } 341 }
342 342
343 void Resource::checkNotify() 343 void Resource::checkNotify()
344 { 344 {
345 notifyClientsInternal(MarkFinishedOption::ShouldMarkFinished);
346 }
347
348 void Resource::notifyClientsInternal(MarkFinishedOption markFinishedOption)
349 {
345 if (isLoading()) 350 if (isLoading())
346 return; 351 return;
347 352
348 ResourceClientWalker<ResourceClient> w(m_clients); 353 ResourceClientWalker<ResourceClient> w(m_clients);
349 while (ResourceClient* c = w.next()) 354 while (ResourceClient* c = w.next()) {
355 if (markFinishedOption == MarkFinishedOption::ShouldMarkFinished)
356 markClientFinished(c);
350 c->notifyFinished(this); 357 c->notifyFinished(this);
358 }
359 }
360
361 void Resource::markClientFinished(ResourceClient* client)
362 {
363 if (m_clients.contains(client)) {
364 m_finishedClients.add(client);
365 m_clients.remove(client);
366 }
351 } 367 }
352 368
353 void Resource::appendData(const char* data, size_t length) 369 void Resource::appendData(const char* data, size_t length)
354 { 370 {
355 TRACE_EVENT0("blink", "Resource::appendData"); 371 TRACE_EVENT0("blink", "Resource::appendData");
356 DCHECK(!m_isRevalidating); 372 DCHECK(!m_isRevalidating);
357 ASSERT(!errorOccurred()); 373 ASSERT(!errorOccurred());
358 if (m_options.dataBufferingPolicy == DoNotBufferData) 374 if (m_options.dataBufferingPolicy == DoNotBufferData)
359 return; 375 return;
360 if (m_data) 376 if (m_data)
(...skipping 12 matching lines...) Expand all
373 setEncodedSize(m_data->size()); 389 setEncodedSize(m_data->size());
374 } 390 }
375 391
376 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy) 392 void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy)
377 { 393 {
378 m_options.dataBufferingPolicy = dataBufferingPolicy; 394 m_options.dataBufferingPolicy = dataBufferingPolicy;
379 m_data.clear(); 395 m_data.clear();
380 setEncodedSize(0); 396 setEncodedSize(0);
381 } 397 }
382 398
383 void Resource::markClientsAndObserversFinished()
384 {
385 HashCountedSet<ResourceClient*> clients;
386 m_clients.swap(clients);
387 for (const auto& it : clients)
388 m_finishedClients.add(it.key, it.value);
389 }
390
391 void Resource::error(const ResourceError& error) 399 void Resource::error(const ResourceError& error)
392 { 400 {
393 ASSERT(!error.isNull()); 401 ASSERT(!error.isNull());
394 m_error = error; 402 m_error = error;
395 m_isRevalidating = false; 403 m_isRevalidating = false;
396 404
397 if (m_error.isCancellation() || !isPreloaded()) 405 if (m_error.isCancellation() || !isPreloaded())
398 memoryCache()->remove(this); 406 memoryCache()->remove(this);
399 407
400 if (!errorOccurred()) 408 if (!errorOccurred())
401 setStatus(LoadError); 409 setStatus(LoadError);
402 ASSERT(errorOccurred()); 410 ASSERT(errorOccurred());
403 m_data.clear(); 411 m_data.clear();
404 m_loader = nullptr; 412 m_loader = nullptr;
405 checkNotify(); 413 checkNotify();
406 markClientsAndObserversFinished();
407 } 414 }
408 415
409 void Resource::finish(double loadFinishTime) 416 void Resource::finish(double loadFinishTime)
410 { 417 {
411 DCHECK(!m_isRevalidating); 418 DCHECK(!m_isRevalidating);
412 m_loadFinishTime = loadFinishTime; 419 m_loadFinishTime = loadFinishTime;
413 if (!errorOccurred()) 420 if (!errorOccurred())
414 m_status = Cached; 421 m_status = Cached;
415 m_loader = nullptr; 422 m_loader = nullptr;
416 checkNotify(); 423 checkNotify();
417 markClientsAndObserversFinished();
418 } 424 }
419 425
420 AtomicString Resource::httpContentType() const 426 AtomicString Resource::httpContentType() const
421 { 427 {
422 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower()); 428 return extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPNames::Co ntent_Type).lower());
423 } 429 }
424 430
425 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const 431 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const
426 { 432 {
427 String ignoredErrorDescription; 433 String ignoredErrorDescription;
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 case Resource::TextTrack: 1114 case Resource::TextTrack:
1109 case Resource::Media: 1115 case Resource::Media:
1110 case Resource::Manifest: 1116 case Resource::Manifest:
1111 return false; 1117 return false;
1112 } 1118 }
1113 ASSERT_NOT_REACHED(); 1119 ASSERT_NOT_REACHED();
1114 return false; 1120 return false;
1115 } 1121 }
1116 1122
1117 } // namespace blink 1123 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698