1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_
10 #include "base/memory/ref_counted.h"
11 #include "content/browser/loader/resource_handler.h"
12 #include "content/browser/loader/resource_message_delegate.h"
21 class ResourceContext
;
22 class ResourceDispatcherHostImpl
;
23 class ResourceMessageFilter
;
26 // Used to complete an asynchronous resource request in response to resource
27 // load events from the resource dispatcher host.
28 class AsyncResourceHandler
: public ResourceHandler
,
29 public ResourceMessageDelegate
{
31 AsyncResourceHandler(ResourceMessageFilter
* filter
,
32 ResourceContext
* resource_context
,
33 net::URLRequest
* request
,
34 ResourceDispatcherHostImpl
* rdh
);
35 virtual ~AsyncResourceHandler();
37 virtual bool OnMessageReceived(const IPC::Message
& message
,
38 bool* message_was_ok
) OVERRIDE
;
40 // ResourceHandler implementation:
41 virtual bool OnUploadProgress(int request_id
,
43 uint64 size
) OVERRIDE
;
44 virtual bool OnRequestRedirected(int request_id
,
46 ResourceResponse
* response
,
47 bool* defer
) OVERRIDE
;
48 virtual bool OnResponseStarted(int request_id
,
49 ResourceResponse
* response
,
50 bool* defer
) OVERRIDE
;
51 virtual bool OnWillStart(int request_id
,
53 bool* defer
) OVERRIDE
;
54 virtual bool OnWillRead(int request_id
,
57 int min_size
) OVERRIDE
;
58 virtual bool OnReadCompleted(int request_id
,
60 bool* defer
) OVERRIDE
;
61 virtual bool OnResponseCompleted(int request_id
,
62 const net::URLRequestStatus
& status
,
63 const std::string
& security_info
) OVERRIDE
;
64 virtual void OnDataDownloaded(int request_id
,
65 int bytes_downloaded
) OVERRIDE
;
68 // IPC message handlers:
69 void OnFollowRedirect(int request_id
,
70 bool has_new_first_party_for_cookies
,
71 const GURL
& new_first_party_for_cookies
);
72 void OnDataReceivedACK(int request_id
);
74 bool EnsureResourceBufferIsInitialized();
75 void ResumeIfDeferred();
77 scoped_refptr
<ResourceBuffer
> buffer_
;
78 scoped_refptr
<ResourceMessageFilter
> filter_
;
79 ResourceContext
* resource_context_
;
80 net::URLRequest
* request_
;
81 ResourceDispatcherHostImpl
* rdh_
;
83 // Number of messages we've sent to the renderer that we haven't gotten an
84 // ACK for. This allows us to avoid having too many messages in flight.
85 int pending_data_count_
;
91 bool has_checked_for_sufficient_resources_
;
92 bool sent_received_response_msg_
;
93 bool sent_first_data_msg_
;
95 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler
);
98 } // namespace content
100 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_