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

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

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

Powered by Google App Engine
This is Rietveld 408576698