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

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

Issue 2390583002: [WIP] WebFonts cache-aware timeout adaption (Closed)
Patch Set: remove flag in finish() instead of responseReceived() Created 4 years, 2 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
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 m_preloadCount(0), 305 m_preloadCount(0),
306 m_preloadDiscoveryTime(0.0), 306 m_preloadDiscoveryTime(0.0),
307 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()), 307 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()),
308 m_preloadResult(PreloadNotReferenced), 308 m_preloadResult(PreloadNotReferenced),
309 m_type(type), 309 m_type(type),
310 m_status(NotStarted), 310 m_status(NotStarted),
311 m_needsSynchronousCacheHit(false), 311 m_needsSynchronousCacheHit(false),
312 m_linkPreload(false), 312 m_linkPreload(false),
313 m_isRevalidating(false), 313 m_isRevalidating(false),
314 m_isAlive(false), 314 m_isAlive(false),
315 m_isAddRemoveClientProhibited(false),
315 m_options(options), 316 m_options(options),
316 m_responseTimestamp(currentTime()), 317 m_responseTimestamp(currentTime()),
317 m_cancelTimer(this, &Resource::cancelTimerFired), 318 m_cancelTimer(this, &Resource::cancelTimerFired),
318 m_resourceRequest(request) { 319 m_resourceRequest(request) {
319 DCHECK_EQ( 320 DCHECK_EQ(
320 m_type, 321 m_type,
321 unsigned( 322 unsigned(
322 type)); // m_type is a bitfield, so this tests careless updates of th e enum. 323 type)); // m_type is a bitfield, so this tests careless updates of th e enum.
323 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 324 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
324 325
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 if (!errorOccurred()) 410 if (!errorOccurred())
410 setStatus(LoadError); 411 setStatus(LoadError);
411 DCHECK(errorOccurred()); 412 DCHECK(errorOccurred());
412 m_data.clear(); 413 m_data.clear();
413 m_loader = nullptr; 414 m_loader = nullptr;
414 checkNotify(); 415 checkNotify();
415 } 416 }
416 417
417 void Resource::finish(double loadFinishTime) { 418 void Resource::finish(double loadFinishTime) {
418 DCHECK(!m_isRevalidating); 419 DCHECK(!m_isRevalidating);
420 if (m_resourceRequest.isCacheAwareLoadingActivated())
hiroshige 2016/10/05 08:27:10 I'd like to prevent Resource from participating st
Shao-Chuan Lee 2016/10/07 08:10:06 Moved manipulation logic to ResourceFetcher. Still
421 m_resourceRequest.deactivateCacheAwareLoading();
419 m_loadFinishTime = loadFinishTime; 422 m_loadFinishTime = loadFinishTime;
420 if (!errorOccurred()) 423 if (!errorOccurred())
421 m_status = Cached; 424 m_status = Cached;
422 m_loader = nullptr; 425 m_loader = nullptr;
423 checkNotify(); 426 checkNotify();
424 } 427 }
425 428
426 AtomicString Resource::httpContentType() const { 429 AtomicString Resource::httpContentType() const {
427 return extractMIMETypeFromMediaType( 430 return extractMIMETypeFromMediaType(
428 m_response.httpHeaderField(HTTPNames::Content_Type).lower()); 431 m_response.httpHeaderField(HTTPNames::Content_Type).lower());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 DCHECK(!request.isNull()); 548 DCHECK(!request.isNull());
546 m_isRevalidating = true; 549 m_isRevalidating = true;
547 m_resourceRequest = request; 550 m_resourceRequest = request;
548 m_status = NotStarted; 551 m_status = NotStarted;
549 } 552 }
550 553
551 void Resource::willFollowRedirect(ResourceRequest& newRequest, 554 void Resource::willFollowRedirect(ResourceRequest& newRequest,
552 const ResourceResponse& redirectResponse) { 555 const ResourceResponse& redirectResponse) {
553 if (m_isRevalidating) 556 if (m_isRevalidating)
554 revalidationFailed(); 557 revalidationFailed();
558 if (m_resourceRequest.isCacheAwareLoadingActivated())
559 m_resourceRequest.deactivateCacheAwareLoading();
555 m_redirectChain.append(RedirectPair(newRequest, redirectResponse)); 560 m_redirectChain.append(RedirectPair(newRequest, redirectResponse));
556 } 561 }
557 562
558 void Resource::setResponse(const ResourceResponse& response) { 563 void Resource::setResponse(const ResourceResponse& response) {
559 m_response = response; 564 m_response = response;
560 if (m_response.wasFetchedViaServiceWorker()) 565 if (m_response.wasFetchedViaServiceWorker())
561 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create( 566 m_cacheHandler = ServiceWorkerResponseCachedMetadataHandler::create(
562 this, m_fetcherSecurityOrigin.get()); 567 this, m_fetcherSecurityOrigin.get());
563 } 568 }
564 569
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 } 684 }
680 } 685 }
681 if (!hasClientsOrObservers()) { 686 if (!hasClientsOrObservers()) {
682 m_isAlive = true; 687 m_isAlive = true;
683 memoryCache()->makeLive(this); 688 memoryCache()->makeLive(this);
684 } 689 }
685 } 690 }
686 691
687 void Resource::addClient(ResourceClient* client, 692 void Resource::addClient(ResourceClient* client,
688 PreloadReferencePolicy policy) { 693 PreloadReferencePolicy policy) {
694 DCHECK(!m_isAddRemoveClientProhibited);
695
689 willAddClientOrObserver(policy); 696 willAddClientOrObserver(policy);
690 697
691 if (m_isRevalidating) { 698 if (m_isRevalidating) {
692 m_clients.add(client); 699 m_clients.add(client);
693 return; 700 return;
694 } 701 }
695 702
696 // If we have existing data to send to the new client and the resource type su pprts it, send it asynchronously. 703 // If we have existing data to send to the new client and the resource type su pprts it, send it asynchronously.
697 if (!m_response.isNull() && 704 if (!m_response.isNull() &&
698 !shouldSendCachedDataSynchronouslyForType(getType()) && 705 !shouldSendCachedDataSynchronouslyForType(getType()) &&
699 !m_needsSynchronousCacheHit) { 706 !m_needsSynchronousCacheHit) {
700 m_clientsAwaitingCallback.add(client); 707 m_clientsAwaitingCallback.add(client);
701 ResourceCallback::callbackHandler().schedule(this); 708 ResourceCallback::callbackHandler().schedule(this);
702 return; 709 return;
703 } 710 }
704 711
705 m_clients.add(client); 712 m_clients.add(client);
706 didAddClient(client); 713 didAddClient(client);
707 return; 714 return;
708 } 715 }
709 716
710 void Resource::removeClient(ResourceClient* client) { 717 void Resource::removeClient(ResourceClient* client) {
718 DCHECK(!m_isAddRemoveClientProhibited);
719
711 // This code may be called in a pre-finalizer, where weak members in the 720 // This code may be called in a pre-finalizer, where weak members in the
712 // HashCountedSet are already swept out. 721 // HashCountedSet are already swept out.
713 722
714 if (m_finishedClients.contains(client)) 723 if (m_finishedClients.contains(client))
715 m_finishedClients.remove(client); 724 m_finishedClients.remove(client);
716 else if (m_clientsAwaitingCallback.contains(client)) 725 else if (m_clientsAwaitingCallback.contains(client))
717 m_clientsAwaitingCallback.remove(client); 726 m_clientsAwaitingCallback.remove(client);
718 else 727 else
719 m_clients.remove(client); 728 m_clients.remove(client);
720 729
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 case Resource::LinkPrefetch: 1076 case Resource::LinkPrefetch:
1068 case Resource::TextTrack: 1077 case Resource::TextTrack:
1069 case Resource::Media: 1078 case Resource::Media:
1070 case Resource::Manifest: 1079 case Resource::Manifest:
1071 return false; 1080 return false;
1072 } 1081 }
1073 NOTREACHED(); 1082 NOTREACHED();
1074 return false; 1083 return false;
1075 } 1084 }
1076 1085
1086 void Resource::willReloadAfterDiskCacheMiss() {
1087 m_resourceRequest.deactivateCacheAwareLoading();
1088
1089 DCHECK(!m_isAddRemoveClientProhibited);
1090 m_isAddRemoveClientProhibited = true;
1091 ResourceClientWalker<ResourceClient> w(m_clients);
1092 while (ResourceClient* c = w.next()) {
Takashi Toyoshima 2016/10/05 07:06:18 nit: we do not use {} for one-liner.
Shao-Chuan Lee 2016/10/05 10:16:10 Done.
1093 c->willReloadAfterDiskCacheMiss(this);
1094 }
1095 m_isAddRemoveClientProhibited = false;
1096 }
1097
1077 } // namespace blink 1098 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698