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

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

Issue 2476163003: Refactor ResourceHandler API. (Closed)
Patch Set: Minor cleanups, one real fix Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_INTERCEPTING_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 24 matching lines...) Expand all
35 class CONTENT_EXPORT InterceptingResourceHandler 35 class CONTENT_EXPORT InterceptingResourceHandler
36 : public LayeredResourceHandler, 36 : public LayeredResourceHandler,
37 public ResourceController { 37 public ResourceController {
38 public: 38 public:
39 InterceptingResourceHandler(std::unique_ptr<ResourceHandler> next_handler, 39 InterceptingResourceHandler(std::unique_ptr<ResourceHandler> next_handler,
40 net::URLRequest* request); 40 net::URLRequest* request);
41 ~InterceptingResourceHandler() override; 41 ~InterceptingResourceHandler() override;
42 42
43 // ResourceHandler implementation: 43 // ResourceHandler implementation:
44 void SetController(ResourceController* controller) override; 44 void SetController(ResourceController* controller) override;
45 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 45 void OnResponseStarted(ResourceResponse* response,
46 bool* defer_or_cancel) override;
46 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 47 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
47 int* buf_size, 48 int* buf_size,
48 int min_size) override; 49 int min_size) override;
49 bool OnReadCompleted(int bytes_read, bool* defer) override; 50 void OnReadCompleted(int bytes_read, bool* defer_or_cancel) override;
50 void OnResponseCompleted(const net::URLRequestStatus& status, 51 void OnResponseCompleted(const net::URLRequestStatus& status,
51 bool* defer) override; 52 bool* defer) override;
52 53
53 // ResourceController implementation: 54 // ResourceController implementation:
54 void Cancel() override; 55 void Cancel() override;
55 void CancelAndIgnore() override; 56 void CancelAndIgnore() override;
56 void CancelWithError(int error_code) override; 57 void CancelWithError(int error_code) override;
57 void Resume() override; 58 void Resume() override;
58 59
59 // Replaces the next handler with |new_handler|, sending 60 // Replaces the next handler with |new_handler|, sending
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // the new handler and waiting for its completion via Resume(). 102 // the new handler and waiting for its completion via Resume().
102 SENDING_BUFFER_TO_NEW_HANDLER, 103 SENDING_BUFFER_TO_NEW_HANDLER,
103 104
104 // The InterceptingResourceHandler has replaced its next ResourceHandler if 105 // The InterceptingResourceHandler has replaced its next ResourceHandler if
105 // needed, and has ensured the buffered read data was properly transmitted 106 // needed, and has ensured the buffered read data was properly transmitted
106 // to the new ResourceHandler. The InterceptingResourceHandler now acts as 107 // to the new ResourceHandler. The InterceptingResourceHandler now acts as
107 // a pass-through ResourceHandler. 108 // a pass-through ResourceHandler.
108 PASS_THROUGH, 109 PASS_THROUGH,
109 }; 110 };
110 111
111 // Runs necessary operations depending on |state_|. Returns false when an 112 // Runs necessary operations depending on |state_|. Set |*defer_or_cancel| to
112 // error happens, and set |*defer| to true if the operation continues upon 113 // true if the operation is not yet complete, and will invoke Resume() or
113 // return. 114 // Cancel() in the future, or if Cancel() was invoked synchronously.
114 bool DoLoop(bool* defer); 115 void DoLoop(bool* defer_or_cancel);
115 116
116 // The return value and |defer| has the same meaning as DoLoop. 117 // |defer_or_cancel| has the same meaning as DoLoop.
117 bool SendPayloadToOldHandler(bool* defer); 118 void SendPayloadToOldHandler(bool* defer_or_cancel);
118 bool SendFirstReadBufferToNewHandler(bool* defer); 119 void SendFirstReadBufferToNewHandler(bool* defer_or_cancel);
119 bool SendOnResponseStartedToNewHandler(bool* defer); 120 void SendOnResponseStartedToNewHandler(bool* defer_or_cancel);
120 121
121 State state_ = State::STARTING; 122 State state_ = State::STARTING;
122 123
123 std::unique_ptr<ResourceHandler> new_handler_; 124 std::unique_ptr<ResourceHandler> new_handler_;
124 std::string payload_for_old_handler_; 125 std::string payload_for_old_handler_;
125 size_t payload_bytes_written_ = 0; 126 size_t payload_bytes_written_ = 0;
126 127
127 // Result of the first read, that may have to be passed to an alternate 128 // Result of the first read, that may have to be passed to an alternate
128 // ResourceHandler instead of the original ResourceHandler. 129 // ResourceHandler instead of the original ResourceHandler.
129 scoped_refptr<net::IOBuffer> first_read_buffer_; 130 scoped_refptr<net::IOBuffer> first_read_buffer_;
130 // Instead of |first_read_buffer_|, this handler creates a new IOBuffer with 131 // Instead of |first_read_buffer_|, this handler creates a new IOBuffer with
131 // the same size and return it to the client. 132 // the same size and return it to the client.
132 scoped_refptr<net::IOBuffer> first_read_buffer_double_; 133 scoped_refptr<net::IOBuffer> first_read_buffer_double_;
133 size_t first_read_buffer_size_ = 0; 134 size_t first_read_buffer_size_ = 0;
134 size_t first_read_buffer_bytes_read_ = 0; 135 size_t first_read_buffer_bytes_read_ = 0;
135 size_t first_read_buffer_bytes_written_ = 0; 136 size_t first_read_buffer_bytes_written_ = 0;
136 137
137 scoped_refptr<ResourceResponse> response_; 138 scoped_refptr<ResourceResponse> response_;
138 139
139 DISALLOW_COPY_AND_ASSIGN(InterceptingResourceHandler); 140 DISALLOW_COPY_AND_ASSIGN(InterceptingResourceHandler);
140 }; 141 };
141 142
142 } // namespace content 143 } // namespace content
143 144
144 #endif // CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_ 145 #endif // CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/detachable_resource_handler.cc ('k') | content/browser/loader/intercepting_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698