[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / loader / resource_loader.h
blob41f3d7e38b108899fc0b1287a41398c32593beee
1 // Copyright (c) 2012 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_RESOURCE_LOADER_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/timer/timer.h"
11 #include "content/browser/loader/resource_handler.h"
12 #include "content/browser/ssl/ssl_client_auth_handler.h"
13 #include "content/browser/ssl/ssl_error_handler.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/resource_controller.h"
16 #include "content/public/common/signed_certificate_timestamp_id_and_status.h"
17 #include "net/url_request/url_request.h"
19 namespace net {
20 class X509Certificate;
23 namespace content {
24 class ResourceDispatcherHostLoginDelegate;
25 class ResourceLoaderDelegate;
26 class ResourceRequestInfoImpl;
28 // This class is responsible for driving the URLRequest (i.e., calling Start,
29 // Read, and servicing events). It has a ResourceHandler, which is typically a
30 // chain of ResourceHandlers, and is the ResourceController for its handler.
31 class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate,
32 public SSLErrorHandler::Delegate,
33 public SSLClientAuthHandler::Delegate,
34 public ResourceController {
35 public:
36 ResourceLoader(scoped_ptr<net::URLRequest> request,
37 scoped_ptr<ResourceHandler> handler,
38 ResourceLoaderDelegate* delegate);
39 ~ResourceLoader() override;
41 void StartRequest();
42 void CancelRequest(bool from_renderer);
44 bool is_transferring() const { return is_transferring_; }
45 void MarkAsTransferring();
46 void CompleteTransfer();
48 net::URLRequest* request() { return request_.get(); }
49 ResourceRequestInfoImpl* GetRequestInfo();
51 void ClearLoginDelegate();
53 private:
54 // net::URLRequest::Delegate implementation:
55 void OnReceivedRedirect(net::URLRequest* request,
56 const net::RedirectInfo& redirect_info,
57 bool* defer) override;
58 void OnAuthRequired(net::URLRequest* request,
59 net::AuthChallengeInfo* info) override;
60 void OnCertificateRequested(net::URLRequest* request,
61 net::SSLCertRequestInfo* info) override;
62 void OnSSLCertificateError(net::URLRequest* request,
63 const net::SSLInfo& info,
64 bool fatal) override;
65 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override;
66 void OnResponseStarted(net::URLRequest* request) override;
67 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
69 // SSLErrorHandler::Delegate implementation:
70 void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) override;
71 void ContinueSSLRequest() override;
73 // SSLClientAuthHandler::Delegate implementation.
74 void ContinueWithCertificate(net::X509Certificate* cert) override;
75 void CancelCertificateSelection() override;
77 // ResourceController implementation:
78 void Resume() override;
79 void Cancel() override;
80 void CancelAndIgnore() override;
81 void CancelWithError(int error_code) override;
83 void StartRequestInternal();
84 void CancelRequestInternal(int error, bool from_renderer);
85 // Stores the SignedCertificateTimestamps held in |sct_list| in the
86 // SignedCertificateTimestampStore singleton, associated with |process_id|.
87 // On return, |sct_ids| contains the assigned ID and verification status of
88 // each SignedCertificateTimestamp.
89 void StoreSignedCertificateTimestamps(
90 const net::SignedCertificateTimestampAndStatusList& sct_list,
91 int process_id,
92 SignedCertificateTimestampIDStatusList* sct_ids);
93 void CompleteResponseStarted();
94 void StartReading(bool is_continuation);
95 void ResumeReading();
96 void ReadMore(int* bytes_read);
97 // Passes a read result to the handler.
98 void CompleteRead(int bytes_read);
99 void ResponseCompleted();
100 void CallDidFinishLoading();
101 void RecordHistograms();
103 bool is_deferred() const { return deferred_stage_ != DEFERRED_NONE; }
105 // Used for categorizing loading of prefetches for reporting in histograms.
106 // NOTE: This enumeration is used in histograms, so please do not add entries
107 // in the middle.
108 enum PrefetchStatus {
109 STATUS_UNDEFINED,
110 STATUS_SUCCESS_FROM_CACHE,
111 STATUS_SUCCESS_FROM_NETWORK,
112 STATUS_CANCELED,
113 STATUS_MAX,
116 enum DeferredStage {
117 DEFERRED_NONE,
118 DEFERRED_START,
119 DEFERRED_NETWORK_START,
120 DEFERRED_REDIRECT,
121 DEFERRED_READ,
122 DEFERRED_RESPONSE_COMPLETE,
123 DEFERRED_FINISH
125 DeferredStage deferred_stage_;
127 scoped_ptr<net::URLRequest> request_;
128 scoped_ptr<ResourceHandler> handler_;
129 ResourceLoaderDelegate* delegate_;
131 scoped_refptr<ResourceDispatcherHostLoginDelegate> login_delegate_;
132 scoped_ptr<SSLClientAuthHandler> ssl_client_auth_handler_;
134 base::TimeTicks read_deferral_start_time_;
136 // Indicates that we are in a state of being transferred to a new downstream
137 // consumer. We are waiting for a notification to complete the transfer, at
138 // which point we'll receive a new ResourceHandler.
139 bool is_transferring_;
141 // Instrumentation add to investigate http://crbug.com/503306.
142 // TODO(mmenke): Remove once bug is fixed.
143 int times_cancelled_before_request_start_;
144 bool started_request_;
145 int times_cancelled_after_request_start_;
147 base::WeakPtrFactory<ResourceLoader> weak_ptr_factory_;
149 DISALLOW_COPY_AND_ASSIGN(ResourceLoader);
152 } // namespace content
154 #endif // CONTENT_BROWSER_LOADER_RESOURCE_LOADER_H_