2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef ThreadableLoaderClientWrapper_h
32 #define ThreadableLoaderClientWrapper_h
34 #include "core/loader/ThreadableLoaderClient.h"
35 #include "wtf/Noncopyable.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/ThreadSafeRefCounted.h"
38 #include "wtf/Threading.h"
42 class ThreadableLoaderClientWrapper
: public ThreadSafeRefCounted
<ThreadableLoaderClientWrapper
> {
44 class ResourceTimingClient
{
46 virtual void didReceiveResourceTiming(const ResourceTimingInfo
&) = 0;
49 static PassRefPtr
<ThreadableLoaderClientWrapper
> create(ThreadableLoaderClient
* client
)
51 return adoptRef(new ThreadableLoaderClientWrapper(client
));
58 clearResourceTimingClient();
66 void setResourceTimingClient(ResourceTimingClient
* client
)
68 m_resourceTimingClient
= client
;
71 void clearResourceTimingClient()
73 m_resourceTimingClient
= nullptr;
76 void didSendData(unsigned long long bytesSent
, unsigned long long totalBytesToBeSent
)
79 m_client
->didSendData(bytesSent
, totalBytesToBeSent
);
82 void didReceiveResponse(unsigned long identifier
, const ResourceResponse
& response
, PassOwnPtr
<WebDataConsumerHandle
> handle
)
85 m_client
->didReceiveResponse(identifier
, response
, handle
);
88 void didReceiveData(const char* data
, unsigned dataLength
)
91 m_client
->didReceiveData(data
, dataLength
);
94 void didReceiveCachedMetadata(const char* data
, int dataLength
)
97 m_client
->didReceiveCachedMetadata(data
, dataLength
);
100 void didFinishLoading(unsigned long identifier
, double finishTime
)
104 m_client
->didFinishLoading(identifier
, finishTime
);
107 void didFail(const ResourceError
& error
)
111 m_client
->didFail(error
);
114 void didFailAccessControlCheck(const ResourceError
& error
)
118 m_client
->didFailAccessControlCheck(error
);
121 void didFailRedirectCheck()
125 m_client
->didFailRedirectCheck();
128 void didReceiveAuthenticationCancellation(unsigned long identifier
, const ResourceResponse
& response
)
131 m_client
->didReceiveResponse(identifier
, response
, nullptr);
134 void didDownloadData(int dataLength
)
137 m_client
->didDownloadData(dataLength
);
140 void didReceiveResourceTiming(const ResourceTimingInfo
& info
)
142 if (m_resourceTimingClient
)
143 m_resourceTimingClient
->didReceiveResourceTiming(info
);
147 explicit ThreadableLoaderClientWrapper(ThreadableLoaderClient
* client
)
149 , m_resourceTimingClient(nullptr)
154 ThreadableLoaderClient
* m_client
;
155 ResourceTimingClient
* m_resourceTimingClient
;
161 #endif // ThreadableLoaderClientWrapper_h