Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / loader / async_resource_handler.h
blob464be2fa06934ed78f030db5405c1a77bcb846a0
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_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/timer/timer.h"
12 #include "content/browser/loader/resource_handler.h"
13 #include "content/browser/loader/resource_message_delegate.h"
14 #include "url/gurl.h"
16 namespace net {
17 class URLRequest;
20 namespace content {
21 class ResourceBuffer;
22 class ResourceContext;
23 class ResourceDispatcherHostImpl;
24 class ResourceMessageFilter;
25 class SharedIOBuffer;
27 // Used to complete an asynchronous resource request in response to resource
28 // load events from the resource dispatcher host.
29 class AsyncResourceHandler : public ResourceHandler,
30 public ResourceMessageDelegate {
31 public:
32 AsyncResourceHandler(net::URLRequest* request,
33 ResourceDispatcherHostImpl* rdh);
34 ~AsyncResourceHandler() override;
36 bool OnMessageReceived(const IPC::Message& message) override;
38 // ResourceHandler implementation:
39 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
40 ResourceResponse* response,
41 bool* defer) override;
42 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
43 bool OnWillStart(const GURL& url, bool* defer) override;
44 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override;
45 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
46 int* buf_size,
47 int min_size) override;
48 bool OnReadCompleted(int bytes_read, bool* defer) override;
49 void OnResponseCompleted(const net::URLRequestStatus& status,
50 const std::string& security_info,
51 bool* defer) override;
52 void OnDataDownloaded(int bytes_downloaded) override;
54 private:
55 // IPC message handlers:
56 void OnFollowRedirect(int request_id);
57 void OnDataReceivedACK(int request_id);
58 void OnUploadProgressACK(int request_id);
60 void ReportUploadProgress();
62 bool EnsureResourceBufferIsInitialized();
63 void ResumeIfDeferred();
64 void OnDefer();
66 scoped_refptr<ResourceBuffer> buffer_;
67 ResourceDispatcherHostImpl* rdh_;
69 // Number of messages we've sent to the renderer that we haven't gotten an
70 // ACK for. This allows us to avoid having too many messages in flight.
71 int pending_data_count_;
73 int allocation_size_;
75 bool did_defer_;
77 bool has_checked_for_sufficient_resources_;
78 bool sent_received_response_msg_;
79 bool sent_first_data_msg_;
81 uint64 last_upload_position_;
82 bool waiting_for_upload_progress_ack_;
83 base::TimeTicks last_upload_ticks_;
84 base::RepeatingTimer<AsyncResourceHandler> progress_timer_;
86 int64_t reported_transfer_size_;
88 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler);
91 } // namespace content
93 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_