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

Side by Side Diff: content/browser/loader/async_resource_handler.h

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Response to comments Created 3 years, 10 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
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/async_resource_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "content/browser/loader/resource_handler.h" 15 #include "content/browser/loader/resource_handler.h"
16 #include "content/browser/loader/resource_message_delegate.h" 16 #include "content/browser/loader/resource_message_delegate.h"
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace net { 21 namespace net {
22 class URLRequest; 22 class URLRequest;
23 class UploadProgress; 23 class UploadProgress;
24 } 24 }
25 25
26 namespace content { 26 namespace content {
27 class ResourceBuffer; 27 class ResourceBuffer;
28 class ResourceController;
28 class ResourceDispatcherHostImpl; 29 class ResourceDispatcherHostImpl;
29 class UploadProgressTracker; 30 class UploadProgressTracker;
30 31
31 // Used to complete an asynchronous resource request in response to resource 32 // Used to complete an asynchronous resource request in response to resource
32 // load events from the resource dispatcher host. 33 // load events from the resource dispatcher host.
33 class CONTENT_EXPORT AsyncResourceHandler : public ResourceHandler, 34 class CONTENT_EXPORT AsyncResourceHandler : public ResourceHandler,
34 public ResourceMessageDelegate { 35 public ResourceMessageDelegate {
35 public: 36 public:
36 AsyncResourceHandler(net::URLRequest* request, 37 AsyncResourceHandler(net::URLRequest* request,
37 ResourceDispatcherHostImpl* rdh); 38 ResourceDispatcherHostImpl* rdh);
38 ~AsyncResourceHandler() override; 39 ~AsyncResourceHandler() override;
39 40
40 bool OnMessageReceived(const IPC::Message& message) override; 41 bool OnMessageReceived(const IPC::Message& message) override;
41 42
42 // ResourceHandler implementation: 43 // ResourceHandler implementation:
43 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 44 void OnRequestRedirected(
44 ResourceResponse* response, 45 const net::RedirectInfo& redirect_info,
45 bool* defer) override; 46 ResourceResponse* response,
46 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 47 std::unique_ptr<ResourceController> controller) override;
47 bool OnWillStart(const GURL& url, bool* defer) override; 48 void OnResponseStarted(
49 ResourceResponse* response,
50 std::unique_ptr<ResourceController> controller) override;
51 void OnWillStart(const GURL& url,
52 std::unique_ptr<ResourceController> controller) override;
48 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 53 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
49 int* buf_size, 54 int* buf_size,
50 int min_size) override; 55 int min_size) override;
51 bool OnReadCompleted(int bytes_read, bool* defer) override; 56 void OnReadCompleted(int bytes_read,
52 void OnResponseCompleted(const net::URLRequestStatus& status, 57 std::unique_ptr<ResourceController> controller) override;
53 bool* defer) override; 58 void OnResponseCompleted(
59 const net::URLRequestStatus& status,
60 std::unique_ptr<ResourceController> controller) override;
54 void OnDataDownloaded(int bytes_downloaded) override; 61 void OnDataDownloaded(int bytes_downloaded) override;
55 62
56 private: 63 private:
57 class InliningHelper; 64 class InliningHelper;
58 65
59 // IPC message handlers: 66 // IPC message handlers:
60 void OnFollowRedirect(int request_id); 67 void OnFollowRedirect(int request_id);
61 void OnDataReceivedACK(int request_id); 68 void OnDataReceivedACK(int request_id);
62 void OnUploadProgressACK(int request_id); 69 void OnUploadProgressACK(int request_id);
63 70
64 bool EnsureResourceBufferIsInitialized(); 71 bool EnsureResourceBufferIsInitialized();
65 void ResumeIfDeferred(); 72 void ResumeIfDeferred();
66 void OnDefer(); 73 void OnDefer(std::unique_ptr<ResourceController> controller);
67 bool CheckForSufficientResource(); 74 bool CheckForSufficientResource();
68 int CalculateEncodedDataLengthToReport(); 75 int CalculateEncodedDataLengthToReport();
69 int CalculateEncodedBodyLengthToReport(); 76 int CalculateEncodedBodyLengthToReport();
70 void RecordHistogram(); 77 void RecordHistogram();
71 void SendUploadProgress(const net::UploadProgress& progress); 78 void SendUploadProgress(const net::UploadProgress& progress);
72 79
73 scoped_refptr<ResourceBuffer> buffer_; 80 scoped_refptr<ResourceBuffer> buffer_;
74 ResourceDispatcherHostImpl* rdh_; 81 ResourceDispatcherHostImpl* rdh_;
75 82
76 // Number of messages we've sent to the renderer that we haven't gotten an 83 // Number of messages we've sent to the renderer that we haven't gotten an
77 // ACK for. This allows us to avoid having too many messages in flight. 84 // ACK for. This allows us to avoid having too many messages in flight.
78 int pending_data_count_; 85 int pending_data_count_;
79 86
80 int allocation_size_; 87 int allocation_size_;
81 88
82 // Size of received body. Used for comparison with expected content size, 89 // Size of received body. Used for comparison with expected content size,
83 // which is reported to UMA. 90 // which is reported to UMA.
84 int64_t total_read_body_bytes_; 91 int64_t total_read_body_bytes_;
85 92
86 bool first_chunk_read_ = false; 93 bool first_chunk_read_ = false;
87 94
88 bool did_defer_;
89
90 bool has_checked_for_sufficient_resources_; 95 bool has_checked_for_sufficient_resources_;
91 bool sent_received_response_msg_; 96 bool sent_received_response_msg_;
92 bool sent_data_buffer_msg_; 97 bool sent_data_buffer_msg_;
93 98
94 std::unique_ptr<InliningHelper> inlining_helper_; 99 std::unique_ptr<InliningHelper> inlining_helper_;
95 base::TimeTicks response_started_ticks_; 100 base::TimeTicks response_started_ticks_;
96 101
97 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_; 102 std::unique_ptr<UploadProgressTracker> upload_progress_tracker_;
98 103
99 int64_t reported_transfer_size_; 104 int64_t reported_transfer_size_;
100 105
101 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); 106 DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler);
102 }; 107 };
103 108
104 } // namespace content 109 } // namespace content
105 110
106 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_ 111 #endif // CONTENT_BROWSER_LOADER_ASYNC_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/DEPS ('k') | content/browser/loader/async_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698