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

Side by Side Diff: content/browser/renderer_host/buffered_resource_handler.h

Issue 10578055: Rewrite guts of ResourceLoader and BufferedResourceHandler to suck less. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/renderer_host/layered_resource_handler.h" 13 #include "content/browser/renderer_host/layered_resource_handler.h"
14 #include "content/public/browser/resource_controller.h"
14 15
15 namespace net { 16 namespace net {
16 class URLRequest; 17 class URLRequest;
17 } // namespace net 18 }
18 19
19 namespace webkit { 20 namespace webkit {
20 struct WebPluginInfo; 21 struct WebPluginInfo;
21 } 22 }
22 23
23 namespace content { 24 namespace content {
24 class ResourceDispatcherHostImpl; 25 class ResourceDispatcherHostImpl;
25 26
26 // Used to buffer a request until enough data has been received. 27 // Used to buffer a request until enough data has been received.
27 class BufferedResourceHandler 28 class BufferedResourceHandler
28 : public LayeredResourceHandler, 29 : public LayeredResourceHandler,
30 public ResourceController,
29 public base::SupportsWeakPtr<BufferedResourceHandler> { 31 public base::SupportsWeakPtr<BufferedResourceHandler> {
30 public: 32 public:
31 BufferedResourceHandler(scoped_ptr<ResourceHandler> next_handler, 33 BufferedResourceHandler(scoped_ptr<ResourceHandler> next_handler,
32 ResourceDispatcherHostImpl* host, 34 ResourceDispatcherHostImpl* host,
33 net::URLRequest* request); 35 net::URLRequest* request);
34 virtual ~BufferedResourceHandler(); 36 virtual ~BufferedResourceHandler();
35 37
38 private:
36 // ResourceHandler implementation: 39 // ResourceHandler implementation:
40 virtual void SetController(ResourceController* controller) OVERRIDE;
37 virtual bool OnResponseStarted(int request_id, 41 virtual bool OnResponseStarted(int request_id,
38 ResourceResponse* response, 42 ResourceResponse* response,
39 bool* defer) OVERRIDE; 43 bool* defer) OVERRIDE;
40 virtual bool OnWillRead(int request_id, 44 virtual bool OnWillRead(int request_id,
41 net::IOBuffer** buf, 45 net::IOBuffer** buf,
42 int* buf_size, 46 int* buf_size,
43 int min_size) OVERRIDE; 47 int min_size) OVERRIDE;
44 virtual bool OnReadCompleted(int request_id, int* bytes_read, 48 virtual bool OnReadCompleted(int request_id, int bytes_read,
45 bool* defer) OVERRIDE; 49 bool* defer) OVERRIDE;
50 virtual bool OnResponseCompleted(int request_id,
51 const net::URLRequestStatus& status,
52 const std::string& security_info) OVERRIDE;
46 53
47 private: 54 // ResourceController implementation:
48 // Returns true if we should delay OnResponseStarted forwarding. 55 virtual void Resume() OVERRIDE;
49 bool DelayResponse(); 56 virtual void Cancel() OVERRIDE;
50 57
51 // Returns true if there is enough information to process the DocType. 58 bool ProcessResponse(bool* defer);
52 bool DidBufferEnough(int bytes_read);
53 59
54 // Returns true if we have to keep buffering data. 60 bool ShouldSniffContent();
55 bool KeepBuffering(int bytes_read); 61 bool DetermineMimeType();
62 bool SelectNextHandler(bool* defer);
63 bool UseAlternateNextHandler(scoped_ptr<ResourceHandler> handler);
56 64
57 // Sends a pending OnResponseStarted notification. 65 bool ReplayReadCompleted(bool* defer);
58 bool CompleteResponseStarted(int request_id, bool* defer); 66 void CallReplayReadCompleted();
59 67
60 // Returns true if we have to wait until the plugin list is generated. 68 bool MustDownload();
61 bool ShouldWaitForPlugins(); 69 bool HasSupportingPlugin(bool* is_stale);
62
63 // A test to determining whether the request should be forwarded to the
64 // download thread. If need_plugin_list was passed in and was set to true,
65 // that means that the check couldn't be fully done because the plugins aren't
66 // loaded. The function should be called again after the plugin list is
67 // loaded.
68 bool ShouldDownload(bool* need_plugin_list);
69
70 // Informs the original ResourceHandler |next_handler_| that the response
71 // will be handled entirely by the new ResourceHandler |handler|. A
72 // reference to |handler| is acquired. Returns false to indicate an error,
73 // which will result in the request being cancelled.
74 bool UseAlternateResourceHandler(int request_id,
75 scoped_ptr<ResourceHandler> handler,
76 bool* defer);
77
78 // Forwards any queued events to |next_handler_|. Returns false to indicate
79 // an error, which will result in the request being cancelled.
80 bool ForwardPendingEventsToNextHandler(int request_id, bool* defer);
81 70
82 // Copies data from |read_buffer_| to |next_handler_|. 71 // Copies data from |read_buffer_| to |next_handler_|.
83 void CopyReadBufferToNextHandler(int request_id); 72 bool CopyReadBufferToNextHandler(int request_id);
84 73
85 // Called on the IO thread once the list of plugins has been loaded. 74 // Called on the IO thread once the list of plugins has been loaded.
86 void OnPluginsLoaded(const std::vector<webkit::WebPluginInfo>& plugins); 75 void OnPluginsLoaded(const std::vector<webkit::WebPluginInfo>& plugins);
87 76
77 enum State {
78 STATE_STARTING,
79
80 // In this state, we are filling read_buffer_ with data for the purpose
81 // of sniffing the mime type of the response.
82 STATE_BUFFERING,
83
84 // In this state, we are select an appropriate downstream ResourceHandler
85 // based on the mime type of the response. We are also potentially waiting
86 // for plugins to load so that we can determine if a plugin is available to
87 // handle the mime type.
88 STATE_PROCESSING,
89
90 // In this state, we are replaying buffered events (OnResponseStarted and
91 // OnReadCompleted) to the downstream ResourceHandler.
92 STATE_REPLAYING,
93
94 // In this state, we are just a blind pass-through ResourceHandler.
95 STATE_STREAMING
96 };
97 State state_;
98
88 scoped_refptr<ResourceResponse> response_; 99 scoped_refptr<ResourceResponse> response_;
89 ResourceDispatcherHostImpl* host_; 100 ResourceDispatcherHostImpl* host_;
90 net::URLRequest* request_; 101 net::URLRequest* request_;
91 scoped_refptr<net::IOBuffer> read_buffer_; 102 scoped_refptr<net::IOBuffer> read_buffer_;
92 scoped_refptr<net::IOBuffer> my_buffer_;
93 int read_buffer_size_; 103 int read_buffer_size_;
94 int bytes_read_; 104 int bytes_read_;
95 bool sniff_content_; 105
96 bool wait_for_plugins_; 106 bool must_download_;
97 bool deferred_waiting_for_plugins_; 107 bool must_download_is_set_;
98 bool buffering_;
99 bool next_handler_needs_response_started_;
100 bool next_handler_needs_will_read_;
101 bool finished_;
102 108
103 DISALLOW_COPY_AND_ASSIGN(BufferedResourceHandler); 109 DISALLOW_COPY_AND_ASSIGN(BufferedResourceHandler);
104 }; 110 };
105 111
106 } // namespace content 112 } // namespace content
107 113
108 #endif // CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_ 114 #endif // CONTENT_BROWSER_RENDERER_HOST_BUFFERED_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/async_resource_handler.cc ('k') | content/browser/renderer_host/buffered_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698