Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / loader / detachable_resource_handler.h
blob64d23ef2628e2fe27aaacf5275c594586f48514d
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "content/browser/loader/resource_handler.h"
15 #include "content/public/browser/resource_controller.h"
17 namespace net {
18 class IOBuffer;
19 class URLRequest;
20 } // namespace net
22 namespace content {
24 // A ResourceHandler which delegates all calls to the next handler, unless
25 // detached. Once detached, it drives the request to completion itself. This is
26 // used for requests which outlive the owning renderer, such as <link
27 // rel=prefetch> and <a ping>. Requests do not start out detached so, e.g.,
28 // prefetches appear in DevTools and get placed in the renderer's local
29 // cache. If the request does not complete after a timeout on detach, it is
30 // cancelled.
32 // Note that, once detached, the request continues without the original next
33 // handler, so any policy decisions in that handler are skipped.
34 class DetachableResourceHandler : public ResourceHandler,
35 public ResourceController {
36 public:
37 DetachableResourceHandler(net::URLRequest* request,
38 base::TimeDelta cancel_delay,
39 scoped_ptr<ResourceHandler> next_handler);
40 ~DetachableResourceHandler() override;
42 bool is_detached() const { return next_handler_ == NULL; }
43 void Detach();
45 void set_cancel_delay(base::TimeDelta cancel_delay) {
46 cancel_delay_ = cancel_delay;
49 // ResourceHandler implementation:
50 void SetController(ResourceController* controller) override;
51 bool OnUploadProgress(uint64 position, uint64 size) override;
52 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
53 ResourceResponse* response,
54 bool* defer) override;
55 bool OnResponseStarted(ResourceResponse* response, bool* defer) override;
56 bool OnWillStart(const GURL& url, bool* defer) override;
57 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override;
58 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
59 int* buf_size,
60 int min_size) override;
61 bool OnReadCompleted(int bytes_read, bool* defer) override;
62 void OnResponseCompleted(const net::URLRequestStatus& status,
63 const std::string& security_info,
64 bool* defer) override;
65 void OnDataDownloaded(int bytes_downloaded) override;
67 // ResourceController implementation:
68 void Resume() override;
69 void Cancel() override;
70 void CancelAndIgnore() override;
71 void CancelWithError(int error_code) override;
73 private:
74 scoped_ptr<ResourceHandler> next_handler_;
75 scoped_refptr<net::IOBuffer> read_buffer_;
77 scoped_ptr<base::OneShotTimer<DetachableResourceHandler> > detached_timer_;
78 base::TimeDelta cancel_delay_;
80 bool is_deferred_;
81 bool is_finished_;
83 DISALLOW_COPY_AND_ASSIGN(DetachableResourceHandler);
86 } // namespace content
88 #endif // CONTENT_BROWSER_LOADER_DETACHABLE_RESOURCE_HANDLER_H_