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

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

Issue 2005273002: Move MimeTypeResourceHandler before ThrottlingResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed gypi error Created 4 years, 6 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_REPLACING_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_REPLACING_RESOURCE_HANDLER_H_
7
8 #include <string>
9 #include <vector>
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 class PluginService;
22 class ResourceDispatcherHostImpl;
23 struct WebPluginInfo;
24
25 // ResourceHandler that initiates special handling of the response if needed,
26 // based on the response's MIME type (starts downloads, sends data to some
27 // plugin types via a special channel).
28 class CONTENT_EXPORT ReplacingResourceHandler : public LayeredResourceHandler {
mmenke 2016/06/09 18:09:29 I'm not a big fan of this name. ResourceHandlerRe
clamy 2016/06/21 16:14:15 Done.
29 public:
30 // If ENABLE_PLUGINS is defined, |plugin_service| must not be NULL.
31 ReplacingResourceHandler(std::unique_ptr<ResourceHandler> next_handler,
32 ResourceDispatcherHostImpl* host,
33 PluginService* plugin_service,
34 net::URLRequest* request);
35 ~ReplacingResourceHandler() override;
36
37 private:
38 enum class State {
mmenke 2016/06/09 18:09:29 I think these states need some documentation.
clamy 2016/06/21 16:14:15 Done.
39 STARTING,
40 WAITING_FOR_NEW_HANDLER,
mmenke 2016/06/09 18:09:29 We only keep this state when we're waiting to get
clamy 2016/06/21 16:14:15 Done.
41 WAITING_FOR_BUFFER_COPY,
mmenke 2016/06/09 18:09:29 This state is only needed because the MimeTypeReso
clamy 2016/06/21 16:14:15 Done.
42 CHOICE_MADE,
mmenke 2016/06/09 18:09:29 We've also made the choice in WAITING_FOR_BUFFER_C
clamy 2016/06/21 16:14:15 I've called it DONE, since the InterceptingResourc
43 };
mmenke 2016/06/09 18:09:29 nit: Suggest a blank line here.
clamy 2016/06/21 16:14:15 Done.
44 // ResourceHandler implementation:
45 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
46 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
47 int* buf_size,
48 int min_size) override;
49 bool OnReadCompleted(int bytes_read, bool* defer) override;
50
51 bool MakeHandlerChoice(bool* defer);
52
53 // Determines whether a plugin will handle the current request, and if so,
54 // sets up the handler to direct the response to that plugin. Returns false
55 // if there is an error and the request should be cancelled and true
56 // otherwise. |defer| is set to true if plugin data is stale and needs to be
57 // refreshed before the request can be handled (in this case the function
58 // still returns true). If the request is directed to a plugin,
59 // |handled_by_plugin| is set to true.
60 bool SelectPluginHandler(bool* defer, bool* handled_by_plugin);
61 // Returns false if the request should be cancelled.
62 bool SelectNextHandler(bool* defer);
63 bool UseAlternateNextHandler(std::unique_ptr<ResourceHandler> handler,
64 const std::string& payload_for_old_handler);
65
66 bool MustDownload();
67
68 // Called on the IO thread once the list of plugins has been loaded.
69 void OnPluginsLoaded(const std::vector<WebPluginInfo>& plugins);
70
71 bool CopyReadBufferToNextHandler();
72
73 State state_;
74
75 ResourceDispatcherHostImpl* host_;
76 #if defined(ENABLE_PLUGINS)
77 PluginService* plugin_service_;
78 #endif
79
80 bool switched_handler_;
81
82 bool must_download_;
83 bool must_download_is_set_;
84
85 // Used to copy data to the new next ResourceHandler.
86 scoped_refptr<ResourceResponse> response_;
87 scoped_refptr<net::IOBuffer> read_buffer_;
88 int bytes_read_;
89
90 base::WeakPtrFactory<ReplacingResourceHandler> weak_ptr_factory_;
91
92 DISALLOW_COPY_AND_ASSIGN(ReplacingResourceHandler);
93 };
94
95 } // namespace content
96
97 #endif // CONTENT_BROWSER_LOADER_REPLACING_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698