2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org>
4 Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
25 #include "AtomicString.h"
26 #include "AtomicStringImpl.h"
27 #include "PlatformString.h"
28 #include "SubresourceLoaderClient.h"
30 #include <wtf/Deque.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/Noncopyable.h>
40 class Loader
: Noncopyable
{
45 void load(DocLoader
*, CachedResource
*, bool incremental
= true, bool skipCanLoadCheck
= false, bool sendResourceLoadCallbacks
= true);
47 void cancelRequests(DocLoader
*);
49 enum Priority
{ Low
, Medium
, High
};
50 void servePendingRequests(Priority minimumPriority
= Low
);
52 bool isSuspendingPendingRequests() { return m_isSuspendingPendingRequests
; }
53 void suspendPendingRequests();
54 void resumePendingRequests();
57 Priority
determinePriority(const CachedResource
*) const;
58 void scheduleServePendingRequests();
60 void requestTimerFired(Timer
<Loader
>*);
62 class Host
: private SubresourceLoaderClient
{
64 Host(const AtomicString
& name
, unsigned maxRequestsInFlight
);
67 const AtomicString
& name() const { return m_name
; }
68 void addRequest(Request
*, Priority
);
69 void servePendingRequests(Priority minimumPriority
= Low
);
70 void cancelRequests(DocLoader
*);
71 bool hasRequests() const;
73 bool processingResource() const { return m_numResourcesProcessing
!= 0; }
76 class ProcessingResource
{
78 ProcessingResource(Host
* host
)
81 m_host
->m_numResourcesProcessing
++;
86 m_host
->m_numResourcesProcessing
--;
93 virtual void didReceiveResponse(SubresourceLoader
*, const ResourceResponse
&);
94 virtual void didReceiveData(SubresourceLoader
*, const char*, int);
95 virtual void didFinishLoading(SubresourceLoader
*);
96 virtual void didFail(SubresourceLoader
*, const ResourceError
&);
98 typedef Deque
<Request
*> RequestQueue
;
99 void servePendingRequests(RequestQueue
& requestsPending
, bool& serveLowerPriority
);
100 void didFail(SubresourceLoader
*, bool cancelled
= false);
101 void cancelPendingRequests(RequestQueue
& requestsPending
, DocLoader
*);
103 RequestQueue m_requestsPending
[High
+ 1];
104 typedef HashMap
<RefPtr
<SubresourceLoader
>, Request
*> RequestMap
;
105 RequestMap m_requestsLoading
;
106 const AtomicString m_name
;
107 const int m_maxRequestsInFlight
;
108 int m_numResourcesProcessing
;
110 typedef HashMap
<AtomicStringImpl
*, Host
*> HostMap
;
112 Host m_nonHTTPProtocolHost
;
114 Timer
<Loader
> m_requestTimer
;
116 bool m_isSuspendingPendingRequests
;