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

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

Issue 2005273002: Move MimeTypeResourceHandler before ThrottlingResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
7
8 #include <string>
9 #include <vector>
mmenke 2016/07/18 18:50:42 Not used.
clamy 2016/07/19 14:24:54 Done.
10
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/loader/layered_resource_handler.h"
14 #include "content/common/content_export.h"
15
16 namespace net {
17 class URLRequest;
18 }
19
20 namespace content {
21
22 // ResourceHandler that initiates special handling of the response if needed,
23 // based on the response's MIME type (starts downloads, sends data to some
24 // plugin types via a special channel).
25 class CONTENT_EXPORT InterceptingResourceHandler
26 : public LayeredResourceHandler {
27 public:
28 // If ENABLE_PLUGINS is defined, |plugin_service| must not be NULL.
29 InterceptingResourceHandler(std::unique_ptr<ResourceHandler> next_handler,
30 net::URLRequest* request);
31 ~InterceptingResourceHandler() override;
32
33 void UseNewHandler(std::unique_ptr<ResourceHandler> new_handler,
34 const std::string& payload_for_old_handler);
35
36 private:
37 enum class State {
38 // In this state, the InterceptingResourceHandler is waiting for the mime
39 // type of the response to be identified, to check if the next handler
40 // should be replaced with an appropriate one.
41 STARTING,
42
43 // In this state, the InterceptingResourceHandler is waiting to copy the
44 // read buffer to the next handler if it was replaced. This is needed
45 // because MimeTypeResourceHandler may call OnWillRead before calling
46 // OnResponseStarted, that is before the InterceptingResourceHandler
47 // replaces the original ResourceHandler of the request. Therefore, the
48 // data read at that time should be copied to the new ResourceHandler.
49 WAITING_FOR_BUFFER_COPY,
50
51 // In this state, the InterceptingResourceHandler has replaced its next
52 // ResourceHandler if needed, and has ensured the buffered read data was
53 // properly transmitted to the new ResourceHandler. The
54 // InterceptingResourceHandler now acts as a pass-through ResourceHandler.
55 DONE,
56 };
57
58 // ResourceHandler implementation:
59 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
60 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
61 int* buf_size,
62 int min_size) override;
63 bool OnReadCompleted(int bytes_read, bool* defer) override;
64
65 void SendPayloadToOldHandler();
66
67 bool CopyReadBufferToNextHandler();
68
69 State state_;
70
71 std::unique_ptr<ResourceHandler> new_handler_;
mmenke 2016/07/18 18:50:42 include <memory>
clamy 2016/07/19 14:24:54 Done.
72 std::string payload_for_old_handler_;
73
74 // Used to copy data to the new next ResourceHandler.
75 scoped_refptr<net::IOBuffer> read_buffer_;
mmenke 2016/07/18 18:50:42 include net/base/io_buffer.h and base/memory/ref_c
clamy 2016/07/19 14:24:54 Done.
76 int bytes_read_;
77
78 DISALLOW_COPY_AND_ASSIGN(InterceptingResourceHandler);
79 };
80
81 } // namespace content
82
83 #endif // CONTENT_BROWSER_LOADER_INTERCEPTING_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698