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

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

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Response to comments Created 3 years, 10 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 17
18 namespace net { 18 namespace net {
19 class IOBuffer; 19 class IOBuffer;
20 class URLRequest; 20 class URLRequest;
21 } // namespace net 21 } // namespace net
22 22
23 namespace content { 23 namespace content {
24 24
25 class ResourceController;
26
25 // A ResourceHandler which delegates all calls to the next handler, unless 27 // A ResourceHandler which delegates all calls to the next handler, unless
26 // detached. Once detached, it drives the request to completion itself. This is 28 // detached. Once detached, it drives the request to completion itself. This is
27 // used for requests which outlive the owning renderer, such as <link 29 // used for requests which outlive the owning renderer, such as <link
28 // rel=prefetch> and <a ping>. Requests do not start out detached so, e.g., 30 // rel=prefetch> and <a ping>. Requests do not start out detached so, e.g.,
29 // prefetches appear in DevTools and get placed in the renderer's local 31 // prefetches appear in DevTools and get placed in the renderer's local
30 // cache. If the request does not complete after a timeout on detach, it is 32 // cache. If the request does not complete after a timeout on detach, it is
31 // cancelled. 33 // cancelled.
32 // 34 //
33 // Note that, once detached, the request continues without the original next 35 // Note that, once detached, the request continues without the original next
34 // handler, so any policy decisions in that handler are skipped. 36 // handler, so any policy decisions in that handler are skipped.
35 class DetachableResourceHandler : public ResourceHandler, 37 class DetachableResourceHandler : public ResourceHandler {
36 public ResourceController {
37 public: 38 public:
38 DetachableResourceHandler(net::URLRequest* request, 39 DetachableResourceHandler(net::URLRequest* request,
39 base::TimeDelta cancel_delay, 40 base::TimeDelta cancel_delay,
40 std::unique_ptr<ResourceHandler> next_handler); 41 std::unique_ptr<ResourceHandler> next_handler);
41 ~DetachableResourceHandler() override; 42 ~DetachableResourceHandler() override;
42 43
44 void SetDelegate(Delegate* delegate) override;
45
43 bool is_detached() const { return next_handler_ == NULL; } 46 bool is_detached() const { return next_handler_ == NULL; }
44 void Detach(); 47 void Detach();
45 48
46 void set_cancel_delay(base::TimeDelta cancel_delay) { 49 void set_cancel_delay(base::TimeDelta cancel_delay) {
47 cancel_delay_ = cancel_delay; 50 cancel_delay_ = cancel_delay;
48 } 51 }
49 52
50 // ResourceHandler implementation: 53 // ResourceHandler implementation:
51 void SetController(ResourceController* controller) override; 54 void OnRequestRedirected(
52 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 55 const net::RedirectInfo& redirect_info,
53 ResourceResponse* response, 56 ResourceResponse* response,
54 bool* defer) override; 57 std::unique_ptr<ResourceController> controller) override;
55 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; 58 void OnResponseStarted(
56 bool OnWillStart(const GURL& url, bool* defer) override; 59 ResourceResponse* response,
60 std::unique_ptr<ResourceController> controller) override;
61 void OnWillStart(const GURL& url,
62 std::unique_ptr<ResourceController> controller) override;
57 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 63 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
58 int* buf_size, 64 int* buf_size,
59 int min_size) override; 65 int min_size) override;
60 bool OnReadCompleted(int bytes_read, bool* defer) override; 66 void OnReadCompleted(int bytes_read,
61 void OnResponseCompleted(const net::URLRequestStatus& status, 67 std::unique_ptr<ResourceController> controller) override;
62 bool* defer) override; 68 void OnResponseCompleted(
69 const net::URLRequestStatus& status,
70 std::unique_ptr<ResourceController> controller) override;
63 void OnDataDownloaded(int bytes_downloaded) override; 71 void OnDataDownloaded(int bytes_downloaded) override;
64 72
65 // ResourceController implementation: 73 private:
66 void Resume() override; 74 class Controller;
67 void Cancel() override;
68 void CancelAndIgnore() override;
69 void CancelWithError(int error_code) override;
70 75
71 private: 76 void OnTimedOut();
77
72 std::unique_ptr<ResourceHandler> next_handler_; 78 std::unique_ptr<ResourceHandler> next_handler_;
73 scoped_refptr<net::IOBuffer> read_buffer_; 79 scoped_refptr<net::IOBuffer> read_buffer_;
74 80
75 std::unique_ptr<base::OneShotTimer> detached_timer_; 81 std::unique_ptr<base::OneShotTimer> detached_timer_;
76 base::TimeDelta cancel_delay_; 82 base::TimeDelta cancel_delay_;
77 83
78 bool is_deferred_;
79 bool is_finished_; 84 bool is_finished_;
80 85
81 DISALLOW_COPY_AND_ASSIGN(DetachableResourceHandler); 86 DISALLOW_COPY_AND_ASSIGN(DetachableResourceHandler);
82 }; 87 };
83 88
84 } // namespace content 89 } // namespace content
85 90
86 #endif // CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_ 91 #endif // CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/async_resource_handler.cc ('k') | content/browser/loader/detachable_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698