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

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

Issue 2668603003: Make ResourceHandler::OnWillRead able to complete asynchronously. (Closed)
Patch Set: Fix merge (x2) Created 3 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_DETACHABLE_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
15 #include "content/browser/loader/resource_controller.h" 15 #include "content/browser/loader/resource_controller.h"
16 #include "content/browser/loader/resource_handler.h" 16 #include "content/browser/loader/resource_handler.h"
17 #include "content/common/content_export.h"
17 18
18 namespace net { 19 namespace net {
19 class IOBuffer; 20 class IOBuffer;
20 class URLRequest; 21 class URLRequest;
21 } // namespace net 22 } // namespace net
22 23
23 namespace content { 24 namespace content {
24 25
25 class ResourceController; 26 class ResourceController;
26 27
27 // A ResourceHandler which delegates all calls to the next handler, unless 28 // A ResourceHandler which delegates all calls to the next handler, unless
28 // detached. Once detached, it drives the request to completion itself. This is 29 // detached. Once detached, it drives the request to completion itself. This is
29 // used for requests which outlive the owning renderer, such as <link 30 // used for requests which outlive the owning renderer, such as <link
30 // rel=prefetch> and <a ping>. Requests do not start out detached so, e.g., 31 // rel=prefetch> and <a ping>. Requests do not start out detached so, e.g.,
31 // prefetches appear in DevTools and get placed in the renderer's local 32 // prefetches appear in DevTools and get placed in the renderer's local
32 // cache. If the request does not complete after a timeout on detach, it is 33 // cache. If the request does not complete after a timeout on detach, it is
33 // cancelled. 34 // cancelled.
34 // 35 //
35 // Note that, once detached, the request continues without the original next 36 // Note that, once detached, the request continues without the original next
36 // handler, so any policy decisions in that handler are skipped. 37 // handler, so any policy decisions in that handler are skipped.
37 class DetachableResourceHandler : public ResourceHandler { 38 class CONTENT_EXPORT DetachableResourceHandler : public ResourceHandler {
38 public: 39 public:
39 DetachableResourceHandler(net::URLRequest* request, 40 DetachableResourceHandler(net::URLRequest* request,
40 base::TimeDelta cancel_delay, 41 base::TimeDelta cancel_delay,
41 std::unique_ptr<ResourceHandler> next_handler); 42 std::unique_ptr<ResourceHandler> next_handler);
42 ~DetachableResourceHandler() override; 43 ~DetachableResourceHandler() override;
43 44
44 void SetDelegate(Delegate* delegate) override; 45 void SetDelegate(Delegate* delegate) override;
45 46
46 bool is_detached() const { return next_handler_ == NULL; } 47 bool is_detached() const { return next_handler_ == NULL; }
47 void Detach(); 48 void Detach();
48 49
49 void set_cancel_delay(base::TimeDelta cancel_delay) { 50 void set_cancel_delay(base::TimeDelta cancel_delay) {
50 cancel_delay_ = cancel_delay; 51 cancel_delay_ = cancel_delay;
51 } 52 }
52 53
53 // ResourceHandler implementation: 54 // ResourceHandler implementation:
54 void OnRequestRedirected( 55 void OnRequestRedirected(
55 const net::RedirectInfo& redirect_info, 56 const net::RedirectInfo& redirect_info,
56 ResourceResponse* response, 57 ResourceResponse* response,
57 std::unique_ptr<ResourceController> controller) override; 58 std::unique_ptr<ResourceController> controller) override;
58 void OnResponseStarted( 59 void OnResponseStarted(
59 ResourceResponse* response, 60 ResourceResponse* response,
60 std::unique_ptr<ResourceController> controller) override; 61 std::unique_ptr<ResourceController> controller) override;
61 void OnWillStart(const GURL& url, 62 void OnWillStart(const GURL& url,
62 std::unique_ptr<ResourceController> controller) override; 63 std::unique_ptr<ResourceController> controller) override;
63 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 64 void OnWillRead(scoped_refptr<net::IOBuffer>* buf,
64 int* buf_size) override; 65 int* buf_size,
66 std::unique_ptr<ResourceController> controller) override;
65 void OnReadCompleted(int bytes_read, 67 void OnReadCompleted(int bytes_read,
66 std::unique_ptr<ResourceController> controller) override; 68 std::unique_ptr<ResourceController> controller) override;
67 void OnResponseCompleted( 69 void OnResponseCompleted(
68 const net::URLRequestStatus& status, 70 const net::URLRequestStatus& status,
69 std::unique_ptr<ResourceController> controller) override; 71 std::unique_ptr<ResourceController> controller) override;
70 void OnDataDownloaded(int bytes_downloaded) override; 72 void OnDataDownloaded(int bytes_downloaded) override;
71 73
72 private: 74 private:
73 class Controller; 75 class Controller;
74 76
77 void ResumeInternal();
75 void OnTimedOut(); 78 void OnTimedOut();
76 79
77 std::unique_ptr<ResourceHandler> next_handler_; 80 std::unique_ptr<ResourceHandler> next_handler_;
78 scoped_refptr<net::IOBuffer> read_buffer_; 81 scoped_refptr<net::IOBuffer> read_buffer_;
79 82
80 std::unique_ptr<base::OneShotTimer> detached_timer_; 83 std::unique_ptr<base::OneShotTimer> detached_timer_;
81 base::TimeDelta cancel_delay_; 84 base::TimeDelta cancel_delay_;
82 85
86 // Only non-NULL between a call to |next_handler_|'s OnWillRead and it
87 // resuming the request. Needed so that if detached during that time, can
88 // complete the call.
89 scoped_refptr<net::IOBuffer>* parent_read_buffer_;
90 int* parent_read_buffer_size_;
91
83 bool is_finished_; 92 bool is_finished_;
84 93
85 DISALLOW_COPY_AND_ASSIGN(DetachableResourceHandler); 94 DISALLOW_COPY_AND_ASSIGN(DetachableResourceHandler);
86 }; 95 };
87 96
88 } // namespace content 97 } // namespace content
89 98
90 #endif // CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_ 99 #endif // CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698